Skip to content

Commit 39a9df9

Browse files
Merge pull request #100 from oscarbenjamin/pr_setuptools
Use setuptools instead of distutils
2 parents 2fd4fd6 + 159426b commit 39a9df9

File tree

5 files changed

+48
-45
lines changed

5 files changed

+48
-45
lines changed

.github/workflows/buildwheel.yml

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,17 @@ jobs:
3232
if: ${{ matrix.os == 'windows-2019' }}
3333

3434
- name: Build wheels
35-
uses: pypa/cibuildwheel@v2.11.2
35+
uses: pypa/cibuildwheel@v2.16.2
3636
env:
37-
CIBW_BUILD: cp39-* cp310-* cp311-*
37+
CIBW_BUILD: cp39-* cp310-* cp311-* cp312-*
3838
CIBW_SKIP: "*-win32 *-manylinux_i686 *-musllinux_*"
39-
#CIBW_SKIP: "*-win32 *-musllinux_*"
4039
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
4140
CIBW_MANYLINUX_I686_IMAGE: manylinux2014
4241
CIBW_BEFORE_ALL_LINUX: bin/cibw_before_all_linux.sh
4342
CIBW_BEFORE_ALL_MACOS: bin/cibw_before_all_macosx_x86_64.sh
4443
CIBW_BEFORE_ALL_WINDOWS: msys2 -c bin/cibw_before_all_windows.sh
4544
CIBW_BEFORE_BUILD_WINDOWS: msys2 -c bin/cibw_before_build_windows.sh
46-
CIBW_BEFORE_BUILD: pip install numpy cython==3.0.0b2 delvewheel
45+
CIBW_BEFORE_BUILD: pip install numpy setuptools cython delvewheel
4746
CIBW_ENVIRONMENT: >
4847
C_INCLUDE_PATH=$(pwd)/.local/include/
4948
LIBRARY_PATH=$(pwd)/.local/lib/
@@ -66,10 +65,10 @@ jobs:
6665

6766
- uses: actions/setup-python@v4
6867
with:
69-
python-version: '3.11'
68+
python-version: '3.12'
7069

7170
- run: pip install --upgrade pip
72-
- run: pip install cython numpy
71+
- run: pip install cython setuptools
7372
- run: python setup.py sdist
7473

7574
- uses: actions/upload-artifact@v3
@@ -84,7 +83,7 @@ jobs:
8483
fail-fast: false
8584
matrix:
8685
os: [ubuntu-20.04, windows-2019, macos-12]
87-
python-version: ['3.9', '3.10', '3.11']
86+
python-version: ['3.9', '3.10', '3.11', '3.12']
8887

8988
steps:
9089
- uses: actions/setup-python@v4
@@ -94,27 +93,23 @@ jobs:
9493
with:
9594
name: artifact
9695
path: wheelhouse
97-
- run: pip install --find-links wheelhouse python_flint
96+
- run: pip install --no-index --find-links wheelhouse python_flint
9897
- run: python -m flint.test --verbose
9998

100-
test_pip_linux_vcs:
101-
name: Install from git checkout on Ubuntu
102-
runs-on: ubuntu-22.04
103-
steps:
104-
- uses: actions/checkout@v3
105-
- uses: actions/setup-python@v4
106-
with:
107-
python-version: 3.11
108-
- run: bin/pip_install_ubuntu.sh . # Install from checkout
109-
- run: python -m flint.test --verbose
110-
111-
test_pip_linux_pypi:
112-
name: Install from PyPI sdist on Ubuntu
99+
test_pip_vcs_sdist:
100+
name: pip install ${{ matrix.target }} on ${{ matrix.python-version }}
113101
runs-on: ubuntu-22.04
102+
strategy:
103+
fail-fast: false
104+
matrix:
105+
python-version: ['3.11', '3.12']
106+
# '.' means install from git checkout
107+
# 'python-flint' means install from PyPI sdist
108+
target: ['.', 'python-flint']
114109
steps:
115110
- uses: actions/checkout@v3
116111
- uses: actions/setup-python@v4
117112
with:
118-
python-version: 3.11
119-
- run: bin/pip_install_ubuntu.sh python-flint # Install from PyPI sdist
113+
python-version: ${{ matrix.python-version }}
114+
- run: bin/pip_install_ubuntu.sh ${{ matrix.target }}
120115
- run: python -m flint.test --verbose

bin/cibw.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ rm -f wheelhouse/*
1111
# bin/build_dependencies_unix.sh places headers and shared libraries under .local
1212
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'
1313

14-
export CIBW_BUILD='cp39-* cp310-* cp311-*'
14+
export CIBW_BUILD='cp39-* cp310-* cp311-* cp312-*'
1515
# export CIBW_BUILD='cp311-*'
1616
export CIBW_SKIP='*-win32 *-manylinux_i686 *-musllinux_*'
1717

bin/pip_install_ubuntu.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ cd ..
4141
ls -l /usr/local/lib
4242
sudo ldconfig /usr/local/lib
4343

44-
# Python build requirements. Ideally these would be in pyprojec.toml, but
44+
# Python build requirements. Ideally these would be in pyproject.toml, but
4545
# first need to migrate from setup.py to pyproject.toml.
46-
pip install 'cython>=3' numpy wheel
46+
pip install numpy cython setuptools wheel
4747

4848
# Install from checkout (or sdist).
4949
echo -----------------------------------------------------------
5050
echo
5151
echo Running:
52-
echo $ pip install --no-build-isolation $1
52+
echo $ pip install --no-binary :all: --no-build-isolation $1
5353
echo
5454
echo -----------------------------------------------------------
5555

56-
pip install --no-build-isolation $1
56+
pip install --no-binary :all: --no-build-isolation $1

setup.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,31 @@
22
import os
33
from subprocess import check_call
44

5-
from distutils.core import setup
6-
from distutils.extension import Extension
75
from Cython.Distutils import build_ext
86
from Cython.Build import cythonize
9-
from numpy.distutils.system_info import default_include_dirs, default_lib_dirs
107

11-
from distutils.sysconfig import get_config_vars
8+
9+
if sys.version_info < (3, 12):
10+
from distutils.core import setup
11+
from distutils.extension import Extension
12+
from numpy.distutils.system_info import default_include_dirs, default_lib_dirs
13+
from distutils.sysconfig import get_config_vars
14+
else:
15+
from setuptools import setup
16+
from setuptools.extension import Extension
17+
from sysconfig import get_config_vars
18+
default_include_dirs = []
19+
default_lib_dirs = []
20+
21+
22+
libraries = ["flint"]
1223

1324

1425
if sys.platform == 'win32':
1526
#
1627
# This is used in CI to build wheels with mingw64
1728
#
1829
if os.getenv('PYTHON_FLINT_MINGW64'):
19-
libraries = ["flint", "mpfr", "gmp"]
2030
includedir = os.path.join(os.path.dirname(__file__), '.local', 'include')
2131
librarydir1 = os.path.join(os.path.dirname(__file__), '.local', 'bin')
2232
librarydir2 = os.path.join(os.path.dirname(__file__), '.local', 'lib')
@@ -26,24 +36,20 @@
2636
# Add gcc to the PATH in GitHub Actions when this setup.py is called by
2737
# cibuildwheel.
2838
os.environ['PATH'] += r';C:\msys64\mingw64\bin'
39+
libraries += ["mpfr", "gmp"]
2940
elif os.getenv('PYTHON_FLINT_MINGW64_TMP'):
3041
# This would be used to build under Windows against these libraries if
3142
# they have been installed somewhere other than .local
32-
libraries = ["flint", "mpfr", "gmp"]
43+
libraries += ["mpfr", "gmp"]
3344
else:
3445
# For the MSVC toolchain link with mpir instead of gmp
35-
libraries = ["flint", "mpir", "mpfr", "pthreads"]
46+
libraries += ["mpir", "mpfr", "pthreads"]
3647
else:
3748
libraries = ["flint"]
3849
(opt,) = get_config_vars('OPT')
3950
os.environ['OPT'] = " ".join(flag for flag in opt.split() if flag != '-Wstrict-prototypes')
4051

4152

42-
default_include_dirs += [
43-
os.path.join(d, "flint") for d in default_include_dirs
44-
]
45-
46-
4753
define_macros = []
4854
compiler_directives = {
4955
'language_level': 3,
@@ -69,9 +75,7 @@
6975

7076

7177
ext_files = [
72-
# ("flint._flint", ["src/flint/_flint.pxd"]), # Main Module
73-
("flint.pyflint", ["src/flint/pyflint.pyx"]), # Main Module
74-
# Submodules
78+
("flint.pyflint", ["src/flint/pyflint.pyx"]),
7579
("flint.types.fmpz", ["src/flint/types/fmpz.pyx"]),
7680
("flint.types.fmpz_poly", ["src/flint/types/fmpz_poly.pyx"]),
7781
("flint.types.fmpz_mat", ["src/flint/types/fmpz_mat.pyx"]),
@@ -119,11 +123,11 @@
119123
for e in ext_modules:
120124
e.cython_directives = {"embedsignature": True}
121125

126+
122127
setup(
123128
name='python-flint',
124129
cmdclass={'build_ext': build_ext},
125130
ext_modules=cythonize(ext_modules, compiler_directives=compiler_directives),
126-
#ext_modules=cythonize(ext_modules, compiler_directives=compiler_directives, annotate=True),
127131
packages=packages,
128132
package_dir={'': 'src'},
129133
description='Bindings for FLINT and Arb',

src/flint/types/fmpq.pyx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,12 @@ cdef class fmpq(flint_scalar):
440440
return fmpz(fround)
441441

442442
def __hash__(self):
443+
import sys
443444
from fractions import Fraction
444-
return hash(Fraction(int(self.p), int(self.q), _normalize=False))
445+
if sys.version_info < (3, 12):
446+
return hash(Fraction(int(self.p), int(self.q), _normalize=False))
447+
else:
448+
return hash(Fraction._from_coprime_ints(int(self.p), int(self.q)))
445449

446450
def height_bits(self, bint signed=False):
447451
"""

0 commit comments

Comments
 (0)