Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Sanitize Python version to be PEP 440 compliant #1605

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ jobs:
. /opt/rh/devtoolset-7/enable
cp packaging/wheel/* .
./publish.sh
python3 -m pip --verbose install dist/xrootd-*.tar.gz
cd .. # Move xrootd.egg-info off PYTHONPATH
python3 -m pip --verbose install xrootd/dist/xrootd-*.tar.gz
python3 -m pip list

- name: Verify Python bindings
Expand Down Expand Up @@ -383,7 +384,8 @@ jobs:
. /opt/rh/devtoolset-7/enable
cp packaging/wheel/* .
./publish.sh
python3 -m pip --verbose install dist/xrootd-*.tar.gz
cd .. # Move xrootd.egg-info off PYTHONPATH
python3 -m pip --verbose install xrootd/dist/xrootd-*.tar.gz
python3 -m pip list

- name: Verify Python bindings
Expand Down
31 changes: 27 additions & 4 deletions bindings/python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,36 @@ if version.startswith('unknown'):
import os
version_file_path = os.path.join('${CMAKE_CURRENT_SOURCE_DIR}', 'VERSION')
print('Version file path: {}'.format(version_file_path))
f = open(version_file_path, 'r')
version = f.read().split('/n')[0]
print('Version from file: {}'.format(version))
f.close()
with open(version_file_path, 'r') as f:
version = f.read().split('/n')[0]
print('Version from file: {}'.format(version))
except Exception as e:
print('{} \nCannot open VERSION_INFO file. {} will be used'.format(e, version))

# Sanitize in keeping with PEP 440
# c.f. https://www.python.org/dev/peps/pep-0440/
# c.f. https://github.com/pypa/pip/issues/8368
# version needs to pass pip._vendor.packaging.version.Version()
version = version.replace("-", ".")

if version.startswith("v"):
version = version[1:]

version_parts = version.split(".")
if len(version_parts[0]) == 8:
# CalVer
date = version_parts[0]
year = date[:4]
incremental = date[4:]
if incremental.startswith("0"):
incremental = incremental[1:]

version = year + "." + incremental

if len(version_parts) > 1:
# https://github.com/pypa/pip/issues/9188#issuecomment-736025963
hash = version_parts[1]
version = version + "+" + hash

print('XRootD library dir: ', xrdlibdir)
print('XRootD src include dir:', xrdsrcincdir)
Expand Down
32 changes: 25 additions & 7 deletions packaging/wheel/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,36 @@
import sys

def get_version():
version = subprocess.check_output(['./genversion.sh', '--print-only'])
version = version.decode()
if version.startswith('v'):
version = subprocess.check_output(['./genversion.sh', '--print-only']).decode()

# Sanitize in keeping with PEP 440
# c.f. https://www.python.org/dev/peps/pep-0440/
# c.f. https://github.com/pypa/pip/issues/8368
# version needs to pass pip._vendor.packaging.version.Version()
version = version.replace("-", ".")

if version.startswith("v"):
version = version[1:]
version = version.split('-')[0]

version_parts = version.split(".")

# Assume SemVer as default case
if len(version_parts[0]) == 8:
# CalVer
date = version_parts[0]
year = date[:4]
incremental = date[4:]
if incremental.startswith("0"):
incremental = incremental[1:]

version = year + "." + incremental

return version

def get_version_from_file():
try:
f = open('./bindings/python/VERSION')
version = f.read().split('/n')[0]
f.close()
with open('./bindings/python/VERSION') as f:
version = f.read().split('/n')[0]
return version
except:
print('Failed to get version from file. Using unknown')
Expand Down