Skip to content

Commit

Permalink
pre-commit autoupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskuehl committed May 16, 2024
1 parent 5329c91 commit 4dbf23e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ repos:
rev: v3.12.0
hooks:
- id: reorder-python-imports
args: ['--py38-plus']
args: ['--py39-plus']
- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
- id: add-trailing-comma
args: ['--py36-plus']
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args: ['--py38-plus']
args: ['--py310-plus']
- repo: https://github.com/hhatto/autopep8
rev: v2.1.0
hooks:
Expand Down
18 changes: 10 additions & 8 deletions pypi_browser/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@


# Copied from distlib/wheel.py
WHEEL_FILENAME_RE = re.compile(r'''
WHEEL_FILENAME_RE = re.compile(
r'''
(?P<nm>[^-]+)
-(?P<vn>\d+[^-]*)
(-(?P<bn>\d+[^-]*))?
-(?P<py>\w+\d+(\.\w+\d+)*)
-(?P<bi>\w+)
-(?P<ar>\w+(\.\w+)*)
\.whl$
''', re.IGNORECASE | re.VERBOSE)
''', re.IGNORECASE | re.VERBOSE,
)


def pep426_normalize(package_name: str) -> str:
Expand Down Expand Up @@ -92,7 +94,7 @@ class PackageEntry:
size: int


def _package_entries_from_zipfile(path: str) -> typing.Set[PackageEntry]:
def _package_entries_from_zipfile(path: str) -> set[PackageEntry]:
with zipfile.ZipFile(path) as zf:
return {
PackageEntry(
Expand All @@ -105,7 +107,7 @@ def _package_entries_from_zipfile(path: str) -> typing.Set[PackageEntry]:
}


def _package_entries_from_tarball(path: str) -> typing.Set[PackageEntry]:
def _package_entries_from_tarball(path: str) -> set[PackageEntry]:
with tarfile.open(path) as tf:
return {
PackageEntry(
Expand All @@ -130,9 +132,9 @@ async def __aenter__(self) -> 'AsyncArchiveFile':

async def __aexit__(
self,
exc_t: typing.Optional[typing.Type[BaseException]],
exc_v: typing.Optional[BaseException],
exc_tb: typing.Optional[TracebackType],
exc_t: type[BaseException] | None,
exc_v: BaseException | None,
exc_tb: TracebackType | None,
) -> None:
await asyncio.to_thread(self.file_.close)

Expand Down Expand Up @@ -171,7 +173,7 @@ def from_path(cls, path: str) -> 'Package':
path=path,
)

async def entries(self) -> typing.Set[PackageEntry]:
async def entries(self) -> set[PackageEntry]:
if self.package_format is PackageFormat.ZIPFILE:
return await asyncio.to_thread(_package_entries_from_zipfile, self.path)
elif self.package_format is PackageFormat.TARBALL:
Expand Down
10 changes: 5 additions & 5 deletions pypi_browser/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class PythonRepository(abc.ABC):

@abc.abstractmethod
async def files_for_package(self, package_name: str) -> typing.Dict[str, str]:
async def files_for_package(self, package_name: str) -> dict[str, str]:
"""Return mapping from filename to file URL for files in a package."""


Expand All @@ -41,7 +41,7 @@ class SimpleRepository(PythonRepository):
# TODO: Also handle PEP691 JSON simple repositories.
pypi_url: str

async def files_for_package(self, package_name: str) -> typing.Dict[str, str]:
async def files_for_package(self, package_name: str) -> dict[str, str]:
async with httpx.AsyncClient() as client:
resp = await client.get(
f'{self.pypi_url}/{package_name}',
Expand All @@ -67,7 +67,7 @@ class LegacyJsonRepository(PythonRepository):
"""Non-standardized JSON API compatible with pypi.org's /pypi/*/json endpoints."""
pypi_url: str

async def files_for_package(self, package_name: str) -> typing.Dict[str, str]:
async def files_for_package(self, package_name: str) -> dict[str, str]:
async with httpx.AsyncClient() as client:
resp = await client.get(
f'{self.pypi_url}/pypi/{package_name}/json',
Expand All @@ -92,9 +92,9 @@ class PackageDoesNotExist(Exception):
pass


async def files_by_version(config: PyPIConfig, package: str) -> typing.Dict[str | None, typing.Set[str]]:
async def files_by_version(config: PyPIConfig, package: str) -> dict[str | None, set[str]]:
ret = collections.defaultdict(set)
for filename in await config.repo.files_for_package(package):
for filename in await config.repo.files_for_package(package):
try:
version = packaging.guess_version_from_filename(filename)
except ValueError:
Expand Down

0 comments on commit 4dbf23e

Please sign in to comment.