diff options
author | makaimann <makaim@stanford.edu> | 2021-05-21 00:20:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-21 04:20:30 +0000 |
commit | 84fdf87a74a7104a0eccaf7a817597b086c3afa9 (patch) | |
tree | bf082fc1d5636bff214ab47eb8d5b3fb1d082720 /src | |
parent | 4268c75087e2bb68dbb2257d99e062a8cc897f8c (diff) |
Use scikit-build CMake files for pycvc5 (#6543)
This PR removes copied CMake files for the pycvc5 Cython target, and instead adds a dependency on scikit-build (where those CMake files originated anyway). This keeps us up to date with fixes. Furthermore, the PR switches from distutils to the more modern setuptools. This does add another dependency but it's a fairly reasonable one. setuptools is not part of the base Python distribution, but my understanding is that it is now the de facto standard, and most package managers install it automatically with Python. The main motivation for switching is in preparation for building wheels.
This PR is a piece of this old one (#5657) which I am closing and splitting up.
Diffstat (limited to 'src')
-rw-r--r-- | src/api/python/CMakeLists.txt | 38 | ||||
-rw-r--r-- | src/api/python/setup.py.in | 26 |
2 files changed, 46 insertions, 18 deletions
diff --git a/src/api/python/CMakeLists.txt b/src/api/python/CMakeLists.txt index c6686e32b..27e36f538 100644 --- a/src/api/python/CMakeLists.txt +++ b/src/api/python/CMakeLists.txt @@ -19,6 +19,36 @@ if(POLICY CMP0057) cmake_policy(SET CMP0057 NEW) endif() +# Check that scikit-build is installed +# Provides CMake files for Python bindings +check_python_module("skbuild" "scikit-build") + +# setuptools for installing the module +check_python_module("setuptools") + +# Find cmake modules distributed with scikit-build +# They are distributed under <scikit-build directory>/resources/cmake +execute_process( + COMMAND + ${PYTHON_EXECUTABLE} -c "from __future__ import print_function; \ + import os; import skbuild; \ + cmake_module_path=os.path.join(os.path.dirname(skbuild.__file__), \ + 'resources', 'cmake'); print(cmake_module_path, end='')" + OUTPUT_VARIABLE + SKBUILD_CMAKE_MODULE_PATH + RESULT_VARIABLE + RET_SKBUILD_CMAKE_MODULE_PATH +) + +if (NOT EXISTS ${SKBUILD_CMAKE_MODULE_PATH}) + message(FATAL_ERROR "Expected CMake module path from + scikit-build at ${SKBUILD_CMAKE_MODULE_PATH}") +endif() + +# Add scikit-build cmake files to cmake module path +# Required for Cython target below +list(APPEND CMAKE_MODULE_PATH ${SKBUILD_CMAKE_MODULE_PATH}) + find_package(PythonExtensions REQUIRED) find_package(Cython 0.29 REQUIRED) @@ -98,8 +128,14 @@ print('YES' if 'VIRTUAL_ENV' in os.environ else 'NO', end='')") set(INSTALL_CMD "${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install") # if we're in a virtualenv, we install it in the virtualenv lib location +# otherwise install in site-packages +# option --single-version-externally-managed prevents it from being +# an .egg distribution and --record records the list of installed files if ("${IN_VIRTUALENV}" STREQUAL "NO") - set(INSTALL_CMD "${INSTALL_CMD} --prefix=${CMAKE_INSTALL_PREFIX}") + set(INSTALL_CMD "${INSTALL_CMD} + --prefix=${CMAKE_INSTALL_PREFIX} + --single-version-externally-managed + --record=pycvc5-installed-files.txt") endif() message("Python bindings install command: ${INSTALL_CMD}") diff --git a/src/api/python/setup.py.in b/src/api/python/setup.py.in index 231f27c2a..7f8783a28 100644 --- a/src/api/python/setup.py.in +++ b/src/api/python/setup.py.in @@ -20,24 +20,16 @@ # configured install prefix using the setup.py --prefix option ## -from distutils.core import setup -from distutils.command.clean import clean -from distutils.command.install import install +from setuptools import setup -class PyCVC5Install(install): - - # Calls the default run command, then deletes the build area - # (equivalent to "setup clean --all"). - def run(self): - install.run(self) - c = clean(self.distribution) - c.all = True - c.finalize_options() - c.run() +CVC5_VERSION='${CVC5_MAJOR}.${CVC5_MINOR}.${CVC5_RELEASE}' setup(name='pycvc5', - version='${CVC5_MAJOR}.${CVC5_MINOR}.${CVC5_RELEASE}', + version=CVC5_VERSION, + long_description='Python bindings for cvc5 ' + CVC5_VERSION, + url='https://github.com/cvc5/cvc5', + zip_safe=False, packages=['pycvc5'], - package_dir={'pycvc5': '${CMAKE_CURRENT_BINARY_DIR}/pycvc5'}, - package_data={'pycvc5': ['pycvc5.so']}, - cmdclass={'install': PyCVC5Install}) + package_dir={'':'${CMAKE_CURRENT_BINARY_DIR}'}, + package_data={'': ['pycvc5*.so']}, + extras_require={'test': ['pytest']}) |