Skip to content

Commit 285c3aa

Browse files
committed
ENH: Add explicit PEP 404 version conformance check
Fail early if the version is incompatible with PEP 440.
1 parent 9ecf24a commit 285c3aa

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

itkVersion.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
VERSION = "6.0b1"
1+
from packaging.version import Version
22

3+
# Version needs to be python PEP 440 compliant (no leading v)
4+
VERSION = '6.0b1'.removeprefix("v")
35

46
def get_versions():
57
"""Returns versions for the ITK Python package.
@@ -20,7 +22,10 @@ def get_versions():
2022
# '4.11.0.dev20170208+139.g922f2d9'
2123
get_versions()['package-version']
2224
"""
25+
26+
Version(VERSION) # Raise InvalidVersion exception if not PEP 440 compliant
27+
2328
versions = {}
24-
versions["version"] = VERSION
25-
versions["package-version"] = VERSION.split("+")[0]
29+
versions['version'] = VERSION
30+
versions['package-version'] = VERSION.split('+')[0]
2631
return versions

scripts/update_python_version.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import subprocess
1010
from datetime import datetime
11+
from packaging.version import Version
1112

1213
argparser = argparse.ArgumentParser(description=__doc__)
1314
argparser.add_argument("itkSourceDir")
@@ -61,6 +62,9 @@
6162

6263
os.chdir(itkPythonPackageDir)
6364
itkVersionPath = os.path.join(itkPythonPackageDir, "itkVersion.py")
65+
66+
Version(VERSION) # Raise InvalidVersion exception if not PEP 440 compliant
67+
6468
if not os.path.exists(itkVersionPath):
6569
print("Expected file " + itkVersionPath + " not found!")
6670
sys.exit(1)

0 commit comments

Comments
 (0)