Skip to content

Commit

Permalink
pypi: fix handling of invalid versions
Browse files Browse the repository at this point in the history
fixes #273.
  • Loading branch information
lilydjwg committed Jun 1, 2024
1 parent 1d55664 commit 61ca3c9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nvchecker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MIT licensed
# Copyright (c) 2013-2024 lilydjwg <[email protected]>, et al.

__version__ = '2.15'
__version__ = '2.15.1'
16 changes: 13 additions & 3 deletions nvchecker_source/pypi.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# MIT licensed
# Copyright (c) 2013-2021 lilydjwg <[email protected]>, et al.
# Copyright (c) 2013-2021,2023-2024 lilydjwg <[email protected]>, et al.

from packaging.version import Version
import structlog
from packaging.version import Version, InvalidVersion

from nvchecker.api import RichResult

logger = structlog.get_logger(logger_name=__name__)

async def get_version(name, conf, *, cache, **kwargs):
ret = []

Expand All @@ -16,7 +19,14 @@ async def get_version(name, conf, *, cache, **kwargs):
data = await cache.get_json(url)

for version in data['releases'].keys():
parsed_version = Version(version)
try:
parsed_version = Version(version)
except InvalidVersion:
if data['releases'][version]:
# emit a warning if there is something under the invalid version
# sympy has an empty "0.5.13-hg" version
logger.warning('ignoring invalid version', version=version)
continue

if not use_pre_release and parsed_version.is_prerelease:
continue
Expand Down
6 changes: 6 additions & 0 deletions tests/test_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ async def test_pypi_list(get_version):
"source": "pypi",
"include_regex": "^1\\..*",
}) == "1.26.18"

async def test_pypi_invalid_version(get_version):
await get_version("sympy", {
"source": "pypi",
})

0 comments on commit 61ca3c9

Please sign in to comment.