Skip to content

Commit

Permalink
Check whether version number complies with PEP 440
Browse files Browse the repository at this point in the history
a24b7f9 exposed a problem where if the
version number does not comply with PEP 440, it may be normalized by
setuptools, but the build scripts are still looking for a wheel
containing the un-normalized version. This causes the build scripts to
fail to find the wheels that are created. To avoid this situation, we
now check the version number for PEP 440 compliance when building the
Python interface. This will allow non-compliant version number issues to
be caught locally.
  • Loading branch information
isc-adang committed Jun 25, 2021
1 parent b30aa5f commit 9e8df77
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/iknowpy/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import itertools
import os
import platform
import re
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -601,6 +602,14 @@ def find_wheel():
return wheel_pattern_matches[0]


def is_canonical_version(version):
"""Return True if version is canonical according to PEP 440, False
otherwise."""
return re.match(
r'^([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev(0|[1-9][0-9]*))?$',
version) is not None


# set constants
CACHE_DIR = 'dist/cache'

Expand All @@ -609,6 +618,8 @@ def find_wheel():
with open('iknowpy/version.py') as version_file:
exec(version_file.read(), version)
version = version['__version__']
if not is_canonical_version(version):
raise BuildError(f'Version {version!r} is not in PEP 440 canonical form')

if 'ICUDIR' in os.environ:
icudir = os.environ['ICUDIR']
Expand Down

0 comments on commit 9e8df77

Please sign in to comment.