Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions hashin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import pip_api
from packaging.requirements import Requirement
from packaging.specifiers import SpecifierSet
from packaging.version import parse
from packaging.version import parse, InvalidVersion

from urllib.request import urlopen
from urllib.error import HTTPError
Expand Down Expand Up @@ -436,7 +436,15 @@ def get_latest_version(data, include_prereleases):
all_versions = []
count_prereleases = 0
for version in data["releases"]:
v = parse(version)
# NOTE: We ignore invalid version strings here so that pre-PEP-440
# versions like "0.3.2d" from that past (say 2009) cannot break
# the present
try:
v = parse(version)
except InvalidVersion:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a code-comment to explain why it's doing this.
I think you can take the title of this PR.

By the way, should it print a warning when it happens?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a code-comment to explain why it's doing this. I think you can take the title of this PR.

@peterbe I can sure add an in-code comment: done.

By the way, should it print a warning when it happens?

I'm producing some output now. How do you feel about the new approach?

print(f"Invalid version skipped (PEP 440): {version!r}", file=sys.stderr)
continue

if not v.is_prerelease or include_prereleases:
all_versions.append((v, version))
else:
Expand Down