Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use setuptools instead of distutils #100

Merged
merged 13 commits into from
Oct 21, 2023
Merged
41 changes: 18 additions & 23 deletions .github/workflows/buildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-*
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 numpy cython==3.0.0b2 delvewheel
CIBW_BEFORE_BUILD: pip install numpy setuptools cython delvewheel
CIBW_ENVIRONMENT: >
C_INCLUDE_PATH=$(pwd)/.local/include/
LIBRARY_PATH=$(pwd)/.local/lib/
Expand All @@ -66,10 +65,10 @@ 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
- run: pip install cython setuptools
- run: python setup.py sdist

- uses: actions/upload-artifact@v3
Expand All @@ -84,7 +83,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
Expand All @@ -94,27 +93,23 @@ 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:
name: Install from git checkout 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 . # Install from checkout
- run: python -m flint.test --verbose

test_pip_linux_pypi:
name: Install from PyPI sdist on Ubuntu
test_pip_vcs_sdist:
name: pip install ${{ matrix.target }} on ${{ matrix.python-version }}
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.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
2 changes: 1 addition & 1 deletion bin/cibw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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_*'

Expand Down
8 changes: 4 additions & 4 deletions bin/pip_install_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ 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 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
36 changes: 20 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@
import os
from subprocess import check_call

from distutils.core import setup
from distutils.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

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"]


if sys.platform == 'win32':
#
# 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')
Expand All @@ -26,24 +36,20 @@
# 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"]
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')


default_include_dirs += [
os.path.join(d, "flint") for d in default_include_dirs
]


define_macros = []
compiler_directives = {
'language_level': 3,
Expand All @@ -69,9 +75,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"]),
Expand Down Expand Up @@ -119,11 +123,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',
Expand Down
6 changes: 5 additions & 1 deletion src/flint/types/fmpq.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
Loading