Skip to content

Commit

Permalink
Simplify version parsing.
Browse files Browse the repository at this point in the history
Calling Version directly has given the strict parsing we require
since the Version class was created and the class predates the
parse(...) function itself. This simpler code should give the
correct behaviour on all versions of packaging since 2014.
  • Loading branch information
hodgestar committed Dec 10, 2022
1 parent 52b222e commit 5a53092
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,7 @@ def _determine_version(options):
version_filename = os.path.join(options['rootdir'], 'VERSION')
with open(version_filename, "r") as version_file:
version_string = version_file.read().strip()
version = packaging.version.parse(version_string)
# LegacyVersion was removed in packaging 22, but is still returned by
# packing <= 21
LegacyVersion = getattr(packaging.version, "LegacyVersion", type(None))
if isinstance(version, LegacyVersion):
raise ValueError("invalid version: " + version_string)
version = packaging.version.Version(version_string)
options['short_version'] = str(version.public)
options['release'] = not version.is_devrelease
if not options['release']:
Expand Down

0 comments on commit 5a53092

Please sign in to comment.