From: Alex Ozdemir Date: Wed, 17 Nov 2021 02:19:05 +0000 (-0800) Subject: Update Python packaging infrastructure (#7654) X-Git-Tag: cvc5-1.0.0~808 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d4183fd0318585e089e805e97f8123cd8f84ace5;p=cvc5.git Update Python packaging infrastructure (#7654) - Stop passing --lib-only (it no longer exists) - Fix the regex search for the cvc5 version - Take a version suffix as an (optional) environmental variable --- diff --git a/src/api/python/wheels/build_wheel.py b/src/api/python/wheels/build_wheel.py index f35dd5662..2f0ff99da 100644 --- a/src/api/python/wheels/build_wheel.py +++ b/src/api/python/wheels/build_wheel.py @@ -17,12 +17,20 @@ # Configures and builds in directory ./build # Creates wheel in ./dist # +# Note: takes an *optional* environment variable VERSION_SUFFIX. If set, this +# suffix will be appended to the pypi package version. +# Example: +# VERSION_SUFFIX=rc1 python3 ./src/api/python/wheels/build_wheel.py bdist_wheel +# would create versions X.Y.Zrc1 +# +# The suffix should start with a letter, and end with a number ## import os import re import sys import platform +import string import subprocess import multiprocessing import shutil @@ -32,7 +40,8 @@ from setuptools.command.build_ext import build_ext from skbuild.cmaker import CMaker from distutils.version import LooseVersion -WORKING_DIR="build" +WORKING_DIR = "build" + def get_project_src_path(): # expecting this script to be in src/api/python/wheels @@ -48,21 +57,16 @@ def get_cvc5_version(): project_src_path = get_project_src_path() # read CMakeLists.txt to get version number - version = dict() - str_pattern = 'set\(CVC5_(?PMAJOR|MINOR|RELEASE)\s*(?P\d+)\)' + version = '' + str_pattern = 'set\(CVC5_LAST_RELEASE\s*"([^"]+)"\)' pattern = re.compile(str_pattern) - with open(os.path.join(project_src_path, 'CMakeLists.txt'), 'r') as f: - for line in f: - line = line.strip() - m = pattern.search(line) - if m: - gd = m.groupdict() - version[gd['component']] = gd['version'] - if len(version) == 3: - break - - assert len(version) == 3, 'Expecting MAJOR, MINOR and RELEASE' - return version['MAJOR'], version['MINOR'], version['RELEASE'] + with open(os.path.join(project_src_path, 'cmake', 'version-base.cmake'), 'r') as f: + m = pattern.search(f.read()) + if m: + version = m.group(1) + return version + else: + raise Exception('Could not find version') class CMakeExtension(Extension): @@ -110,17 +114,16 @@ class CMakeBuild(build_ext): # configure with the working directory python-build-wheel args = ['--python-bindings', '--auto-download', - '--lib-only', '--name='+WORKING_DIR] # find correct Python include directory and library # works even for nonstandard Python installations # (e.g., on pypa/manylinux) - args.append('-DPYTHON_VERSION_STRING:STRING=' + \ + args.append('-DPYTHON_VERSION_STRING:STRING=' + sys.version.split(' ')[0]) python_version = CMaker.get_python_version() - args.append('-DPYTHON_INCLUDE_DIR:PATH=' + \ + args.append('-DPYTHON_INCLUDE_DIR:PATH=' + CMaker.get_python_include_dir(python_version)) - args.append('-DPYTHON_LIBRARY:FILEPATH=' + \ + args.append('-DPYTHON_LIBRARY:FILEPATH=' + CMaker.get_python_library(python_version)) config_filename = os.path.join(project_src_path, "configure.sh") @@ -149,9 +152,17 @@ class CMakeBuild(build_ext): shutil.copytree(pycvc5_module, dst_name) +version_suffix = os.getenv('VERSION_SUFFIX', '') +if len(version_suffix) > 0: + assert all(c in string.ascii_letters + string.digits for c in version_suffix) + assert version_suffix[0] in string.ascii_letters + assert version_suffix[-1] in string.ascii_digits + print("Setting version suffix to", version_suffix) + + setup( name='pycvc5', - version='.'.join(get_cvc5_version()), + version=get_cvc5_version() + version_suffix, long_description='Python bindings for cvc5', url='https://github.com/cvc5/cvc5', license='BSD-3-Clause', @@ -160,4 +171,3 @@ setup( cmdclass=dict(build_ext=CMakeBuild), tests_require=['pytest'] ) -