From bdd96bb9c214956ad468a2bf4670d2cde99e7d5a Mon Sep 17 00:00:00 2001 From: Alex Seaton Date: Wed, 28 Aug 2024 19:54:19 -0600 Subject: [PATCH 01/12] Added pyproject.toml using scikit-build-core as build backend --- CMakeLists.txt | 11 ++++++++++- pyproject.toml | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 pyproject.toml diff --git a/CMakeLists.txt b/CMakeLists.txt index 32203ad3..aedc1ca9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,7 +155,16 @@ endif() string(REGEX MATCH "([0-9]+)\.([0-9]+)" _HEYOKA_PY_NPY_MAJOR_MINOR ${Python3_NumPy_VERSION}) message(STATUS "NumPy major.minor version: ${_HEYOKA_PY_NPY_MAJOR_MINOR}") -set(HEYOKA_PY_INSTALL_PATH "" CACHE STRING "heyoka module installation path") +if (DEFINED SKBUILD) + # If we're using scikit-build-core, set install path to the current + # directory since skbuild will be handling the installation. + set(HEYOKA_PY_INSTALL_PATH "." CACHE STRING "heyoka module installation path") + + # Also ensure shared libraries can be found in RPATH. + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) +else() + set(HEYOKA_PY_INSTALL_PATH "" CACHE STRING "heyoka module installation path") +endif() mark_as_advanced(HEYOKA_PY_INSTALL_PATH) unset(_HEYOKA_PY_PYTHON3_COMPONENTS) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..65fe9497 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,38 @@ +[build-system] +build-backend = 'scikit_build_core.build' +requires = ['scikit-build-core', 'pybind11', 'numpy < 2'] + +[project] +name = 'heyoka.py' +version = '5.1.0' +description = "Python library for ODE integration via Taylor's method and LLVM" +readme = 'README.md' +requires-python = '>=3.5' +dependencies = [ + 'cloudpickle', + 'numpy < 2', +] +authors = [ + {name = 'Francesco Biscarni', email = 'bluescarni@gmail.com'}, + {name = 'Dario Izzo'}, +] +license = {text = 'MPL-2.0'} +classifiers = [ + # How mature is this project? Common values are + # 3 - Alpha + # 4 - Beta + # 5 - Production/Stable + "Development Status :: 5 - Production/Stable", + "Operating System :: OS Independent", + "Intended Audience :: Science/Research", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Mathematics", + "Topic :: Scientific/Engineering :: Physics", + "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", + "Programming Language :: Python :: 3", +] +keywords = ['science', 'math', 'physics', 'ode'] + +[project.urls] +Documentation = "https://bluescarni.github.io/heyoka.py/index.html" +Repository = "https://github.com/bluescarni/heyoka.py" From eb511dc224840db5fc079d4a9edada28004bc5c4 Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Tue, 24 Sep 2024 08:14:43 +0200 Subject: [PATCH 02/12] Formatting, bump version to 6.0.0, add optional dependencies section. --- pyproject.toml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 65fe9497..fdf2bc78 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,20 +3,17 @@ build-backend = 'scikit_build_core.build' requires = ['scikit-build-core', 'pybind11', 'numpy < 2'] [project] -name = 'heyoka.py' -version = '5.1.0' +name = 'heyoka' +version = '6.0.0' description = "Python library for ODE integration via Taylor's method and LLVM" readme = 'README.md' requires-python = '>=3.5' -dependencies = [ - 'cloudpickle', - 'numpy < 2', -] +dependencies = ['cloudpickle', 'numpy < 2'] authors = [ - {name = 'Francesco Biscarni', email = 'bluescarni@gmail.com'}, - {name = 'Dario Izzo'}, + { name = 'Francesco Biscarni', email = 'bluescarni@gmail.com' }, + { name = 'Dario Izzo' }, ] -license = {text = 'MPL-2.0'} +license = { text = 'MPL-2.0' } classifiers = [ # How mature is this project? Common values are # 3 - Alpha @@ -34,5 +31,9 @@ classifiers = [ keywords = ['science', 'math', 'physics', 'ode'] [project.urls] -Documentation = "https://bluescarni.github.io/heyoka.py/index.html" -Repository = "https://github.com/bluescarni/heyoka.py" +Documentation = "https://bluescarni.github.io/heyoka.py/index.html" +Repository = "https://github.com/bluescarni/heyoka.py" + +[project.optional-dependencies] +sympy = ["sympy", "mpmath"] +sgp4 = ["skyfield"] From ef8d983637c9cca4fa481296399989564033fa62 Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Tue, 24 Sep 2024 08:38:47 +0200 Subject: [PATCH 03/12] Add a numpy < 2 check in the CMakeLists.txt. --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 611434d9..cc54ba7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,6 +151,11 @@ endif() if(heyoka_WITH_REAL AND ${Python3_NumPy_VERSION} LESS 1.22) message(FATAL_ERROR "The minimum version of NumPy required for supporting arbitrary-precision computations is 1.22, but version ${Python3_NumPy_VERSION} was found instead") endif() +# NOTE: NumPy 2 not supported yet if we are building with support +# for mppp::real or mppp::real128. +if((heyoka_WITH_REAL OR heyoka_WITH_REAL128) AND ${Python3_NumPy_VERSION} VERSION_GREATER_EQUAL 2) + message(FATAL_ERROR "NumPy 2 is not supported when building with support for quadruple-precision or arbitrary-precision computations") +endif() # Extract the major.minor version of NumPy for use in the wheel configuration. string(REGEX MATCH "([0-9]+)\.([0-9]+)" _HEYOKA_PY_NPY_MAJOR_MINOR ${Python3_NumPy_VERSION}) message(STATUS "NumPy major.minor version: ${_HEYOKA_PY_NPY_MAJOR_MINOR}") From fd0917cf8ba8417f65de4a1147b4544009d4bb17 Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Tue, 24 Sep 2024 08:39:09 +0200 Subject: [PATCH 04/12] Be more specific about package versions in pyproject.toml. --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fdf2bc78..269eefd7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] build-backend = 'scikit_build_core.build' -requires = ['scikit-build-core', 'pybind11', 'numpy < 2'] +requires = ['scikit-build-core', 'pybind11 >= 2.10', 'numpy >= 1.22, < 2'] [project] name = 'heyoka' @@ -8,7 +8,7 @@ version = '6.0.0' description = "Python library for ODE integration via Taylor's method and LLVM" readme = 'README.md' requires-python = '>=3.5' -dependencies = ['cloudpickle', 'numpy < 2'] +dependencies = ['cloudpickle', 'numpy >= 1.22, < 2'] authors = [ { name = 'Francesco Biscarni', email = 'bluescarni@gmail.com' }, { name = 'Dario Izzo' }, From ef8dab94f2b7f03b10a5069daedb4905e09c43f8 Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Tue, 24 Sep 2024 08:39:35 +0200 Subject: [PATCH 05/12] Tentatively avoid copying the C++ source files when building binary wheels. --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 269eefd7..8d0ecc26 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,3 +37,8 @@ Repository = "https://github.com/bluescarni/heyoka.py" [project.optional-dependencies] sympy = ["sympy", "mpmath"] sgp4 = ["skyfield"] + +[tool.scikit-build] +# Avoid copying the C++ source files when building +# binary wheels. +wheel.packages = [] From 4bf12d8ab5e67c68245d2e98303ed46e7877ddce Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Tue, 24 Sep 2024 09:01:35 +0200 Subject: [PATCH 06/12] Enable IPO in pyproject.toml. --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 8d0ecc26..25842a9d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,3 +42,5 @@ sgp4 = ["skyfield"] # Avoid copying the C++ source files when building # binary wheels. wheel.packages = [] +# Enable IPO. +cmake.args = ["-DHEYOKA_PY_ENABLE_IPO=ON"] From caeb5f32aeb3b0c53272b996052f5c229cb269e4 Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Tue, 24 Sep 2024 09:06:03 +0200 Subject: [PATCH 07/12] Remove old code for wheel production, first try with new system. --- CMakeLists.txt | 9 ++----- heyoka/CMakeLists.txt | 7 ------ tools/gha_manylinux.sh | 42 ++++++-------------------------- tools/wheel_setup.cfg | 2 -- tools/wheel_setup.py | 55 ------------------------------------------ 5 files changed, 10 insertions(+), 105 deletions(-) delete mode 100644 tools/wheel_setup.cfg delete mode 100644 tools/wheel_setup.py diff --git a/CMakeLists.txt b/CMakeLists.txt index cc54ba7e..49f3ce72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,9 +156,8 @@ endif() if((heyoka_WITH_REAL OR heyoka_WITH_REAL128) AND ${Python3_NumPy_VERSION} VERSION_GREATER_EQUAL 2) message(FATAL_ERROR "NumPy 2 is not supported when building with support for quadruple-precision or arbitrary-precision computations") endif() -# Extract the major.minor version of NumPy for use in the wheel configuration. -string(REGEX MATCH "([0-9]+)\.([0-9]+)" _HEYOKA_PY_NPY_MAJOR_MINOR ${Python3_NumPy_VERSION}) -message(STATUS "NumPy major.minor version: ${_HEYOKA_PY_NPY_MAJOR_MINOR}") +message(STATUS "NumPy version: ${Python3_NumPy_VERSION}") +unset(_HEYOKA_PY_PYTHON3_COMPONENTS) if (DEFINED SKBUILD) # If we're using scikit-build-core, set install path to the current @@ -171,7 +170,6 @@ else() set(HEYOKA_PY_INSTALL_PATH "" CACHE STRING "heyoka module installation path") endif() mark_as_advanced(HEYOKA_PY_INSTALL_PATH) -unset(_HEYOKA_PY_PYTHON3_COMPONENTS) # pybind11. find_package(pybind11 REQUIRED CONFIG) @@ -208,6 +206,3 @@ endif() # Add the module directory. add_subdirectory(heyoka) - -# Cleanup. -unset(_HEYOKA_PY_NPY_MAJOR_MINOR) diff --git a/heyoka/CMakeLists.txt b/heyoka/CMakeLists.txt index 997e787c..4fb3d530 100644 --- a/heyoka/CMakeLists.txt +++ b/heyoka/CMakeLists.txt @@ -1,13 +1,6 @@ # Configure the version file. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/_version.py.in" "${CMAKE_CURRENT_BINARY_DIR}/_version.py" @ONLY) -# Configure the files needed to make the python wheels (for PyPI packages). -if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - message(STATUS "Creating the files for the generation of a binary wheel.") - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/../tools/wheel_setup.py" "${CMAKE_CURRENT_BINARY_DIR}/../wheel/setup.py" @ONLY) - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/../tools/wheel_setup.cfg" "${CMAKE_CURRENT_BINARY_DIR}/../wheel/setup.cfg" @ONLY) -endif() - # The list of heyoka.py's Python files. set(HEYOKA_PY_PYTHON_FILES __init__.py diff --git a/tools/gha_manylinux.sh b/tools/gha_manylinux.sh index 1b720fb6..08c374fa 100644 --- a/tools/gha_manylinux.sh +++ b/tools/gha_manylinux.sh @@ -15,7 +15,7 @@ git config --global --add safe.directory ${GITHUB_WORKSPACE} BRANCH_NAME=`git rev-parse --abbrev-ref HEAD` echo "BRANCH_NAME: ${BRANCH_NAME}" -# Read for what python wheels have to be built. +# Detect the Python version. if [[ ${HEYOKA_PY_BUILD_TYPE} == *38* ]]; then PYTHON_DIR="cp38-cp38" elif [[ ${HEYOKA_PY_BUILD_TYPE} == *39* ]]; then @@ -33,16 +33,9 @@ else exit 1 fi -# Report the inferred directory whwere python is found. +# Report the inferred directory where python is found. echo "PYTHON_DIR: ${PYTHON_DIR}" -# The numpy version heyoka.py will be built against. -if [[ ${HEYOKA_PY_BUILD_TYPE} == *312* || ${HEYOKA_PY_BUILD_TYPE} == *313* ]]; then - export NUMPY_VERSION="1.26.*" -else - export NUMPY_VERSION="1.24.*" -fi - # The heyoka version to be used for releases. export HEYOKA_VERSION_RELEASE="6.0.0" @@ -54,15 +47,7 @@ else echo "Non-tag build detected" fi -# Python mandatory deps. -# NOTE: explicit installation of setuptools is apparently -# needed in Python 3.13. -/opt/python/${PYTHON_DIR}/bin/pip install numpy==${NUMPY_VERSION} cloudpickle setuptools -# Python optional deps. -/opt/python/${PYTHON_DIR}/bin/pip install sympy mpmath skyfield - -# In the pagmo2/manylinux2014_x86_64_with_deps:latest image in dockerhub -# the working directory is /root/install, we will install heyoka there. +# In the manylinux image in dockerhub the working directory is /root/install, we will install heyoka there. cd /root/install # Install heyoka. @@ -85,30 +70,19 @@ cmake -DHEYOKA_WITH_MPPP=yes \ -DCMAKE_BUILD_TYPE=Release ../; make -j4 install -# Install heyoka.py. +# Build the heyoka.py wheel. cd ${GITHUB_WORKSPACE} -mkdir build -cd build -cmake -DCMAKE_BUILD_TYPE=Release \ - -DHEYOKA_PY_ENABLE_IPO=ON \ - -DPython3_EXECUTABLE=/opt/python/${PYTHON_DIR}/bin/python ../; -make -j4 install - -# Making the wheel and installing it -cd wheel -# Move the installed heyoka.py files into the current dir. -mv `/opt/python/${PYTHON_DIR}/bin/python -c 'import site; print(site.getsitepackages()[0])'`/heyoka ./ -# Create the wheel and repair it. +pip wheel . -v +# Repair it. # NOTE: this is temporary because some libraries in the docker # image are installed in lib64 rather than lib and they are # not picked up properly by the linker. export LD_LIBRARY_PATH="/usr/local/lib64:/usr/local/lib" -/opt/python/${PYTHON_DIR}/bin/python setup.py bdist_wheel -auditwheel repair dist/heyoka* -w ./dist2 +auditwheel repair ./heyoka*.whl -w ./repaired_wheel # Try to install it and run the tests. unset LD_LIBRARY_PATH cd / -/opt/python/${PYTHON_DIR}/bin/pip install ${GITHUB_WORKSPACE}/build/wheel/dist2/heyoka* +/opt/python/${PYTHON_DIR}/bin/pip install ${GITHUB_WORKSPACE}/repaired_wheel/heyoka* cd ${GITHUB_WORKSPACE}/tools /opt/python/${PYTHON_DIR}/bin/python ci_test_runner.py cd / diff --git a/tools/wheel_setup.cfg b/tools/wheel_setup.cfg deleted file mode 100644 index 9b3e1739..00000000 --- a/tools/wheel_setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[install] -install_lib= diff --git a/tools/wheel_setup.py b/tools/wheel_setup.py deleted file mode 100644 index a9e35366..00000000 --- a/tools/wheel_setup.py +++ /dev/null @@ -1,55 +0,0 @@ -import os -from setuptools import setup -from setuptools.dist import Distribution -import sys - -NAME = "heyoka" -VERSION = "@heyoka.py_VERSION@" -DESCRIPTION = "Python library for ODE integration via Taylor's method and LLVM" -LONG_DESCRIPTION = "heyoka is a Python library for the integration of ordinary differential equations (ODEs) via Taylor's method, based on automatic differentiation techniques and aggressive just-in-time compilation via LLVM." -URL = "https://github.com/bluescarni/heyoka.py" -AUTHOR = "Francesco Biscani, Dario Izzo" -AUTHOR_EMAIL = "bluescarni@gmail.com" -LICENSE = "MPL-2.0" -CLASSIFIERS = [ - # How mature is this project? Common values are - # 3 - Alpha - # 4 - Beta - # 5 - Production/Stable - "Development Status :: 5 - Production/Stable", - "Operating System :: OS Independent", - "Intended Audience :: Science/Research", - "Topic :: Scientific/Engineering", - "Topic :: Scientific/Engineering :: Mathematics", - "Topic :: Scientific/Engineering :: Physics", - "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", - "Programming Language :: Python :: 3", -] -KEYWORDS = "science math physics ode" -INSTALL_REQUIRES = ["numpy==@_HEYOKA_PY_NPY_MAJOR_MINOR@.*", "cloudpickle"] -PLATFORMS = ["Unix"] - - -class BinaryDistribution(Distribution): - def has_ext_modules(foo): - return True - - -setup( - name=NAME, - version=VERSION, - description=DESCRIPTION, - long_description=LONG_DESCRIPTION, - url=URL, - author=AUTHOR, - author_email=AUTHOR_EMAIL, - license=LICENSE, - classifiers=CLASSIFIERS, - keywords=KEYWORDS, - platforms=PLATFORMS, - install_requires=INSTALL_REQUIRES, - packages=["heyoka", "heyoka.model", "heyoka.callback"], - # Include pre-compiled extension - package_data={"heyoka": [f for f in os.listdir("heyoka/") if f.endswith(".so")]}, - distclass=BinaryDistribution, -) From 237e0119e69aa49c6d3f5310d469b915e0c0e762 Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Tue, 24 Sep 2024 09:15:42 +0200 Subject: [PATCH 08/12] Fix pip invocation. --- tools/gha_manylinux.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/gha_manylinux.sh b/tools/gha_manylinux.sh index 08c374fa..617e10e5 100644 --- a/tools/gha_manylinux.sh +++ b/tools/gha_manylinux.sh @@ -72,7 +72,7 @@ make -j4 install # Build the heyoka.py wheel. cd ${GITHUB_WORKSPACE} -pip wheel . -v +/opt/python/${PYTHON_DIR}/bin/pip wheel . -v # Repair it. # NOTE: this is temporary because some libraries in the docker # image are installed in lib64 rather than lib and they are From a6be7537bf6c2737a4788f9da032a093ba520cca Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Tue, 24 Sep 2024 09:31:27 +0200 Subject: [PATCH 09/12] Remove pybind11 from the Python deps. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 25842a9d..22d70e92 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] build-backend = 'scikit_build_core.build' -requires = ['scikit-build-core', 'pybind11 >= 2.10', 'numpy >= 1.22, < 2'] +requires = ['scikit-build-core', 'numpy >= 1.22, < 2'] [project] name = 'heyoka' From aab45de979e03d368c781514cd4a5f5ef74a5666 Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Tue, 24 Sep 2024 14:35:55 +0200 Subject: [PATCH 10/12] Use cmake.define instead of cmake.args. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 22d70e92..342c4f54 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,4 +43,4 @@ sgp4 = ["skyfield"] # binary wheels. wheel.packages = [] # Enable IPO. -cmake.args = ["-DHEYOKA_PY_ENABLE_IPO=ON"] +cmake.define.HEYOKA_PY_ENABLE_IPO = "ON" From 3fcc27c7973c2fa4ef977ab28f1aaff2f5829e0a Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Thu, 10 Oct 2024 09:30:37 +0200 Subject: [PATCH 11/12] Update pyproject.toml. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 342c4f54..8a4c096a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = ['scikit-build-core', 'numpy >= 1.22, < 2'] [project] name = 'heyoka' -version = '6.0.0' +version = '6.1.0' description = "Python library for ODE integration via Taylor's method and LLVM" readme = 'README.md' requires-python = '>=3.5' From cb37eb7e11936891ade627676a8d288a4c8f1592 Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Thu, 10 Oct 2024 10:29:18 +0200 Subject: [PATCH 12/12] Update changelog. --- doc/changelog.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/changelog.rst b/doc/changelog.rst index 6ec87c48..7ecd3ae9 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -6,9 +6,18 @@ Changelog 6.1.0 (unreleased) ------------------ +New +~~~ + +- Add a proper ``pyproject.toml`` file and use it to produce + the binary wheels + (`#195 `__). + Fix ~~~ +- Do not open the heyoka.py compiled module with ``RTLD_GLOBAL`` + (`#197 `__). - Workaround for a clang 17 issue that would result in runtime exceptions during (de)serialisation (`#196 `__).