From ac7d735939618be0f9082622258379994fb2f7e7 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 21 Oct 2023 18:19:17 +0100 Subject: [PATCH 01/13] Use setuptools instead of distutils --- setup.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/setup.py b/setup.py index 13ce2c28..2bb874a7 100644 --- a/setup.py +++ b/setup.py @@ -2,13 +2,16 @@ import os from subprocess import check_call -from distutils.core import setup -from distutils.extension import Extension +from setuptools import setup +from setuptools.extension import Extension from Cython.Distutils import build_ext from Cython.Build import cythonize -from numpy.distutils.system_info import default_include_dirs, default_lib_dirs -from distutils.sysconfig import get_config_vars + +default_include_dirs = [] +default_lib_dirs = [] + +libraries = ["flint"] if sys.platform == 'win32': @@ -16,7 +19,6 @@ # This is used in CI to build wheels with mingw64 # if os.getenv('PYTHON_FLINT_MINGW64'): - libraries = ["flint", "mpfr", "gmp"] includedir = os.path.join(os.path.dirname(__file__), '.local', 'include') librarydir1 = os.path.join(os.path.dirname(__file__), '.local', 'bin') librarydir2 = os.path.join(os.path.dirname(__file__), '.local', 'lib') @@ -26,22 +28,14 @@ # Add gcc to the PATH in GitHub Actions when this setup.py is called by # cibuildwheel. os.environ['PATH'] += r';C:\msys64\mingw64\bin' + libraries += ["mpfr", "gmp"] elif os.getenv('PYTHON_FLINT_MINGW64_TMP'): # This would be used to build under Windows against these libraries if # they have been installed somewhere other than .local - libraries = ["flint", "mpfr", "gmp"] + libraries += ["mpfr", "gmp"] else: # For the MSVC toolchain link with mpir instead of gmp - libraries = ["flint", "mpir", "mpfr", "pthreads"] -else: - libraries = ["flint"] - (opt,) = get_config_vars('OPT') - os.environ['OPT'] = " ".join(flag for flag in opt.split() if flag != '-Wstrict-prototypes') - - -default_include_dirs += [ - os.path.join(d, "flint") for d in default_include_dirs -] + libraries += ["mpir", "mpfr", "pthreads"] define_macros = [] @@ -69,9 +63,7 @@ ext_files = [ - # ("flint._flint", ["src/flint/_flint.pxd"]), # Main Module - ("flint.pyflint", ["src/flint/pyflint.pyx"]), # Main Module - # Submodules + ("flint.pyflint", ["src/flint/pyflint.pyx"]), ("flint.types.fmpz", ["src/flint/types/fmpz.pyx"]), ("flint.types.fmpz_poly", ["src/flint/types/fmpz_poly.pyx"]), ("flint.types.fmpz_mat", ["src/flint/types/fmpz_mat.pyx"]), @@ -119,11 +111,11 @@ for e in ext_modules: e.cython_directives = {"embedsignature": True} + setup( name='python-flint', cmdclass={'build_ext': build_ext}, ext_modules=cythonize(ext_modules, compiler_directives=compiler_directives), - #ext_modules=cythonize(ext_modules, compiler_directives=compiler_directives, annotate=True), packages=packages, package_dir={'': 'src'}, description='Bindings for FLINT and Arb', From 9958bfeedf207df7f59f24e7e41c012b8b972119 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 21 Oct 2023 18:34:45 +0100 Subject: [PATCH 02/13] Add Python 3.12 to the wheel build matrix --- .github/workflows/buildwheel.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/buildwheel.yml b/.github/workflows/buildwheel.yml index 17eb5296..6b5f9d9e 100644 --- a/.github/workflows/buildwheel.yml +++ b/.github/workflows/buildwheel.yml @@ -34,7 +34,7 @@ jobs: - name: Build wheels uses: pypa/cibuildwheel@v2.11.2 env: - CIBW_BUILD: cp39-* cp310-* cp311-* + CIBW_BUILD: cp39-* cp310-* cp311-* cp312-* CIBW_SKIP: "*-win32 *-manylinux_i686 *-musllinux_*" #CIBW_SKIP: "*-win32 *-musllinux_*" CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014 @@ -66,7 +66,7 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: '3.12' - run: pip install --upgrade pip - run: pip install cython numpy @@ -84,7 +84,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-20.04, windows-2019, macos-12] - python-version: ['3.9', '3.10', '3.11'] + python-version: ['3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/setup-python@v4 @@ -104,7 +104,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: 3.11 + python-version: 3.12 - run: bin/pip_install_ubuntu.sh . # Install from checkout - run: python -m flint.test --verbose From 7b8dba9c5406a9772f82c64f883fe545905c4228 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 21 Oct 2023 18:38:11 +0100 Subject: [PATCH 03/13] Install setuptools in CI --- .github/workflows/buildwheel.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/buildwheel.yml b/.github/workflows/buildwheel.yml index 6b5f9d9e..7b7d647f 100644 --- a/.github/workflows/buildwheel.yml +++ b/.github/workflows/buildwheel.yml @@ -43,7 +43,7 @@ jobs: CIBW_BEFORE_ALL_MACOS: bin/cibw_before_all_macosx_x86_64.sh CIBW_BEFORE_ALL_WINDOWS: msys2 -c bin/cibw_before_all_windows.sh CIBW_BEFORE_BUILD_WINDOWS: msys2 -c bin/cibw_before_build_windows.sh - CIBW_BEFORE_BUILD: pip install numpy cython==3.0.0b2 delvewheel + CIBW_BEFORE_BUILD: pip install cython==3.0.0b2 delvewheel CIBW_ENVIRONMENT: > C_INCLUDE_PATH=$(pwd)/.local/include/ LIBRARY_PATH=$(pwd)/.local/lib/ @@ -69,7 +69,7 @@ jobs: python-version: '3.12' - run: pip install --upgrade pip - - run: pip install cython numpy + - run: pip install cython setuptools - run: python setup.py sdist - uses: actions/upload-artifact@v3 From 621531e185af6963b70783d8524088384d4ab4a9 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 21 Oct 2023 18:47:58 +0100 Subject: [PATCH 04/13] Install setuptools in CI --- bin/pip_install_ubuntu.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/pip_install_ubuntu.sh b/bin/pip_install_ubuntu.sh index 49930ade..b6ded337 100755 --- a/bin/pip_install_ubuntu.sh +++ b/bin/pip_install_ubuntu.sh @@ -41,9 +41,9 @@ cd .. ls -l /usr/local/lib sudo ldconfig /usr/local/lib -# Python build requirements. Ideally these would be in pyprojec.toml, but +# Python build requirements. Ideally these would be in pyproject.toml, but # first need to migrate from setup.py to pyproject.toml. -pip install 'cython>=3' numpy wheel +pip install 'cython>=3' setuptools wheel # Install from checkout (or sdist). echo ----------------------------------------------------------- From 17852e7da5ae0d53aefb03c5daa7429fc1824782 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 21 Oct 2023 18:56:03 +0100 Subject: [PATCH 05/13] Don't unstall from PyPI when testing in CI --- .github/workflows/buildwheel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/buildwheel.yml b/.github/workflows/buildwheel.yml index 7b7d647f..c0ae5911 100644 --- a/.github/workflows/buildwheel.yml +++ b/.github/workflows/buildwheel.yml @@ -94,7 +94,7 @@ jobs: with: name: artifact path: wheelhouse - - run: pip install --find-links wheelhouse python_flint + - run: pip install --no-index --find-links wheelhouse python_flint - run: python -m flint.test --verbose test_pip_linux_vcs: From 3b6b11eb6bcca5a5f113f03e0ae54d9d66b258b1 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 21 Oct 2023 19:14:26 +0100 Subject: [PATCH 06/13] Add 3.12 to the Cirrus build matrix --- bin/cibw.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cibw.sh b/bin/cibw.sh index 2f84d5f6..a62de6f3 100755 --- a/bin/cibw.sh +++ b/bin/cibw.sh @@ -11,7 +11,7 @@ rm -f wheelhouse/* # bin/build_dependencies_unix.sh places headers and shared libraries under .local export CIBW_ENVIRONMENT='C_INCLUDE_PATH=$(pwd)/.local/include/ LIBRARY_PATH=$(pwd)/.local/lib/ LD_LIBRARY_PATH=$(pwd)/.local/lib:$LD_LIBRARY_PATH PYTHON_FLINT_MINGW64=true' -export CIBW_BUILD='cp39-* cp310-* cp311-*' +export CIBW_BUILD='cp39-* cp310-* cp311-* cp312-*' # export CIBW_BUILD='cp311-*' export CIBW_SKIP='*-win32 *-manylinux_i686 *-musllinux_*' From bc63dfd221352feaeea670ee1bc5ab30b104d086 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 21 Oct 2023 19:30:52 +0100 Subject: [PATCH 07/13] Update cibuildwheel version --- .github/workflows/buildwheel.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/buildwheel.yml b/.github/workflows/buildwheel.yml index c0ae5911..cef6d7e6 100644 --- a/.github/workflows/buildwheel.yml +++ b/.github/workflows/buildwheel.yml @@ -32,18 +32,17 @@ jobs: if: ${{ matrix.os == 'windows-2019' }} - name: Build wheels - uses: pypa/cibuildwheel@v2.11.2 + uses: pypa/cibuildwheel@v2.16.2 env: CIBW_BUILD: cp39-* cp310-* cp311-* cp312-* CIBW_SKIP: "*-win32 *-manylinux_i686 *-musllinux_*" - #CIBW_SKIP: "*-win32 *-musllinux_*" CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014 CIBW_MANYLINUX_I686_IMAGE: manylinux2014 CIBW_BEFORE_ALL_LINUX: bin/cibw_before_all_linux.sh CIBW_BEFORE_ALL_MACOS: bin/cibw_before_all_macosx_x86_64.sh CIBW_BEFORE_ALL_WINDOWS: msys2 -c bin/cibw_before_all_windows.sh CIBW_BEFORE_BUILD_WINDOWS: msys2 -c bin/cibw_before_build_windows.sh - CIBW_BEFORE_BUILD: pip install cython==3.0.0b2 delvewheel + CIBW_BEFORE_BUILD: pip install cython delvewheel CIBW_ENVIRONMENT: > C_INCLUDE_PATH=$(pwd)/.local/include/ LIBRARY_PATH=$(pwd)/.local/lib/ From 211aba0bbc690cc723f6687c28b26c7e63484a61 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 21 Oct 2023 19:56:26 +0100 Subject: [PATCH 08/13] Fix use of private Fraction methods for 3.12 --- src/flint/types/fmpq.pyx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/flint/types/fmpq.pyx b/src/flint/types/fmpq.pyx index cc25fc7b..fa3cde8c 100644 --- a/src/flint/types/fmpq.pyx +++ b/src/flint/types/fmpq.pyx @@ -440,8 +440,12 @@ cdef class fmpq(flint_scalar): return fmpz(fround) def __hash__(self): + import sys from fractions import Fraction - return hash(Fraction(int(self.p), int(self.q), _normalize=False)) + if sys.version_info < (3, 12): + return hash(Fraction(int(self.p), int(self.q), _normalize=False)) + else: + return hash(Fraction._from_coprime_ints(int(self.p), int(self.q))) def height_bits(self, bint signed=False): """ From 3d162df5e64c317d4f0c58a233718731b0ef71c0 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 21 Oct 2023 21:51:01 +0100 Subject: [PATCH 09/13] Only build wheels for 3.12 --- .github/workflows/buildwheel.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/buildwheel.yml b/.github/workflows/buildwheel.yml index cef6d7e6..5e7fd571 100644 --- a/.github/workflows/buildwheel.yml +++ b/.github/workflows/buildwheel.yml @@ -34,7 +34,8 @@ jobs: - name: Build wheels uses: pypa/cibuildwheel@v2.16.2 env: - CIBW_BUILD: cp39-* cp310-* cp311-* cp312-* + CIBW_BUILD: cp312-* + #CIBW_BUILD: cp39-* cp310-* cp311-* cp312-* CIBW_SKIP: "*-win32 *-manylinux_i686 *-musllinux_*" CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014 CIBW_MANYLINUX_I686_IMAGE: manylinux2014 From 1e77473c2d1ba3256f177da1c2fe86370a601d3e Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 21 Oct 2023 22:37:05 +0100 Subject: [PATCH 10/13] Build for all Python versions in CI --- .github/workflows/buildwheel.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/buildwheel.yml b/.github/workflows/buildwheel.yml index 5e7fd571..cef6d7e6 100644 --- a/.github/workflows/buildwheel.yml +++ b/.github/workflows/buildwheel.yml @@ -34,8 +34,7 @@ jobs: - name: Build wheels uses: pypa/cibuildwheel@v2.16.2 env: - CIBW_BUILD: cp312-* - #CIBW_BUILD: cp39-* cp310-* cp311-* cp312-* + CIBW_BUILD: cp39-* cp310-* cp311-* cp312-* CIBW_SKIP: "*-win32 *-manylinux_i686 *-musllinux_*" CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014 CIBW_MANYLINUX_I686_IMAGE: manylinux2014 From c343f39f79cf269f0b153c90a82e394b7f0aa198 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 21 Oct 2023 22:43:12 +0100 Subject: [PATCH 11/13] Use version checks for setuptools in setup.py --- setup.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 2bb874a7..84746161 100644 --- a/setup.py +++ b/setup.py @@ -2,14 +2,22 @@ import os from subprocess import check_call -from setuptools import setup -from setuptools.extension import Extension from Cython.Distutils import build_ext from Cython.Build import cythonize -default_include_dirs = [] -default_lib_dirs = [] +if sys.version_info < (3, 12): + from distutils.core import setup + from distutils.extension import Extension + from numpy.distutils.system_info import default_include_dirs, default_lib_dirs + from distutils.sysconfig import get_config_vars +else: + from setuptools import setup + from setuptools.extension import Extension + from sysconfig import get_config_vars + default_include_dirs = [] + default_lib_dirs = [] + libraries = ["flint"] @@ -36,6 +44,10 @@ else: # For the MSVC toolchain link with mpir instead of gmp libraries += ["mpir", "mpfr", "pthreads"] +else: + libraries = ["flint"] + (opt,) = get_config_vars('OPT') + os.environ['OPT'] = " ".join(flag for flag in opt.split() if flag != '-Wstrict-prototypes') define_macros = [] From 27d4b543405204df21af5954ea390471230c656b Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 21 Oct 2023 22:52:36 +0100 Subject: [PATCH 12/13] Install numpy and fix up CI testing for source builds --- .github/workflows/buildwheel.yml | 24 ++++++++++-------------- bin/pip_install_ubuntu.sh | 6 +++--- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/.github/workflows/buildwheel.yml b/.github/workflows/buildwheel.yml index cef6d7e6..06944e7d 100644 --- a/.github/workflows/buildwheel.yml +++ b/.github/workflows/buildwheel.yml @@ -42,7 +42,7 @@ jobs: CIBW_BEFORE_ALL_MACOS: bin/cibw_before_all_macosx_x86_64.sh CIBW_BEFORE_ALL_WINDOWS: msys2 -c bin/cibw_before_all_windows.sh CIBW_BEFORE_BUILD_WINDOWS: msys2 -c bin/cibw_before_build_windows.sh - CIBW_BEFORE_BUILD: pip install cython delvewheel + CIBW_BEFORE_BUILD: pip install numpy setuptools cython delvewheel CIBW_ENVIRONMENT: > C_INCLUDE_PATH=$(pwd)/.local/include/ LIBRARY_PATH=$(pwd)/.local/lib/ @@ -99,21 +99,17 @@ jobs: test_pip_linux_vcs: name: Install from git checkout on Ubuntu runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + python-version: ['3.11', '3.12'] + # '.' means install from git checkout + # 'python-flint' means install from PyPI sdist + target: ['.', 'python-flint'] steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: 3.12 - - run: bin/pip_install_ubuntu.sh . # Install from checkout - - run: python -m flint.test --verbose - - test_pip_linux_pypi: - name: Install from PyPI sdist on Ubuntu - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: 3.11 - - run: bin/pip_install_ubuntu.sh python-flint # Install from PyPI sdist + python-version: ${{ matrix.python-version }} + - run: bin/pip_install_ubuntu.sh ${{ matrix.target }} - run: python -m flint.test --verbose diff --git a/bin/pip_install_ubuntu.sh b/bin/pip_install_ubuntu.sh index b6ded337..070e4261 100755 --- a/bin/pip_install_ubuntu.sh +++ b/bin/pip_install_ubuntu.sh @@ -43,14 +43,14 @@ sudo ldconfig /usr/local/lib # Python build requirements. Ideally these would be in pyproject.toml, but # first need to migrate from setup.py to pyproject.toml. -pip install 'cython>=3' setuptools wheel +pip install numpy cython setuptools wheel # Install from checkout (or sdist). echo ----------------------------------------------------------- echo echo Running: -echo $ pip install --no-build-isolation $1 +echo $ pip install --no-binary :all: --no-build-isolation $1 echo echo ----------------------------------------------------------- -pip install --no-build-isolation $1 +pip install --no-binary :all: --no-build-isolation $1 From 159426b3a24b84e8721919c92f6d09f4731baa39 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 21 Oct 2023 23:03:21 +0100 Subject: [PATCH 13/13] Change name of pip CI job --- .github/workflows/buildwheel.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/buildwheel.yml b/.github/workflows/buildwheel.yml index 06944e7d..35f41f9d 100644 --- a/.github/workflows/buildwheel.yml +++ b/.github/workflows/buildwheel.yml @@ -96,8 +96,8 @@ jobs: - run: pip install --no-index --find-links wheelhouse python_flint - run: python -m flint.test --verbose - test_pip_linux_vcs: - name: Install from git checkout on Ubuntu + test_pip_vcs_sdist: + name: pip install ${{ matrix.target }} on ${{ matrix.python-version }} runs-on: ubuntu-22.04 strategy: fail-fast: false