Skip to content

Commit

Permalink
Merge pull request #20 from letsbuilda/gh18
Browse files Browse the repository at this point in the history
Use a single function to get versioned package metadata
  • Loading branch information
shenanigansd authored Apr 26, 2023
2 parents 4566644 + 19fec3f commit d2da300
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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" },
Expand Down
15 changes: 7 additions & 8 deletions src/letsbuilda/pypi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit d2da300

Please sign in to comment.