From 19fec3f4dbdce667a7deeccde981f918600b8cd8 Mon Sep 17 00:00:00 2001 From: Bradley Reynolds Date: Tue, 25 Apr 2023 21:28:38 -0500 Subject: [PATCH] Use a single function to get versioned package metadata Signed-off-by: Bradley Reynolds --- docs/source/changelog.rst | 3 +++ pyproject.toml | 2 +- src/letsbuilda/pypi/client.py | 15 +++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 3db3759..282edcf 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -4,6 +4,9 @@ Changelog ========= +- :release:`4.0.0 <25th April 2023>` +- :feature:`18` Use a single function to get versioned package metadata + - :release:`3.2.0 <25th April 2023>` - :feature:`17` Add version to RSS feed when available diff --git a/pyproject.toml b/pyproject.toml index b81f14b..60a7464 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "letsbuilda-pypi" -version = "3.2.0" +version = "4.0.0" description = "A wrapper for PyPI's API and RSS feed" authors = [ { name = "Bradley Reynolds", email = "bradley.reynolds@darbia.dev" }, diff --git a/src/letsbuilda/pypi/client.py b/src/letsbuilda/pypi/client.py index e8821a2..2fe2f3b 100644 --- a/src/letsbuilda/pypi/client.py +++ b/src/letsbuilda/pypi/client.py @@ -24,12 +24,11 @@ async def get_rss_feed(self, feed_url: str) -> list[RSSPackageMetadata]: rss_data = xmltodict.parse(response_text)["rss"]["channel"]["item"] return [RSSPackageMetadata.build_from(package_data) for package_data in rss_data] - async def get_package_metadata(self, package_name: str) -> PackageMetadata: - """Get the new packages RSS feed""" - async with self.http_session.get(f"https://pypi.org/pypi/{package_name}/json") as response: - return PackageMetadata.from_dict(await response.json()) - - async def get_package_metadata_for_release(self, package_name: str, package_version: str) -> PackageMetadata: - """Get the new packages RSS feed""" - async with self.http_session.get(f"https://pypi.org/pypi/{package_name}/{package_version}/json") as response: + async def get_package_metadata(self, package_name: str, package_version: str | None = None) -> PackageMetadata: + """Get metadata for a package""" + if package_version is not None: + url = f"https://pypi.org/pypi/{package_name}/{package_version}/json" + else: + url = f"https://pypi.org/pypi/{package_name}/json" + async with self.http_session.get(url) as response: return PackageMetadata.from_dict(await response.json())