diff --git a/.cirrus.yml b/.cirrus.yml index 189079bc..3970103e 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -9,14 +9,12 @@ cirrus_wheels_macos_arm64_task: env: PATH: /opt/homebrew/opt/python@3.10/bin:$PATH CIBW_ARCHS_MACOS: arm64 + CIBW_TEST_COMMAND: "python -m flint.test" install_pre_requirements_script: - - brew install python@3.10 - - ln -s python3 /opt/homebrew/opt/python@3.10/bin/python - - which python - - python --version - install_cibuildwheel_script: - - python -m pip install cibuildwheel==2.16.2 + - python3 -m venv venv + - venv/bin/pip install --upgrade pip + - venv/bin/pip install cibuildwheel==2.16.2 run_cibuildwheel_script: - - bin/cibw.sh + - venv/bin/cibuildwheel --platform macos wheels_artifacts: path: "wheelhouse/*" diff --git a/.github/workflows/buildwheel.yml b/.github/workflows/buildwheel.yml index 88f79c62..536d00c9 100644 --- a/.github/workflows/buildwheel.yml +++ b/.github/workflows/buildwheel.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-20.04, windows-2019, macos-12] + os: [ubuntu-20.04, windows-2019, macos-13] steps: - uses: actions/checkout@v4 @@ -31,6 +31,16 @@ jobs: path-type: inherit if: ${{ matrix.os == 'windows-2019' }} + # Install pkgconfig on Windows from choco rather than from msys and + # avoid using the Strawberry one. + - run: choco install -y --stoponfirstfailure --checksum 6004DF17818F5A6DBF19CB335CC92702 pkgconfiglite + if: ${{ matrix.os == 'windows-2019' }} + + # We have to set this here rather than in the cibuildwheel config + # This is probably something to do with \ vs / in paths... + - run: echo "PKG_CONFIG_PATH=${{ github.workspace }}/.local/lib/pkgconfig" >> $env:GITHUB_ENV + if: ${{ matrix.os == 'windows-2019' }} + - name: Build wheels uses: pypa/cibuildwheel@v2.16.5 env: @@ -45,7 +55,7 @@ jobs: build_sdist: name: Build sdist - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 @@ -54,6 +64,11 @@ jobs: with: python-version: '3.12' + - run: sudo apt-get update + - run: sudo apt-get install libgmp-dev libmpfr-dev xz-utils ninja-build + - run: curl -O -L https://www.flintlib.org/flint-3.1.0.tar.gz + - run: tar -xzf flint-3.1.0.tar.gz + - run: cd flint-3.1.0 && ./configure --disable-static && make -j4 && sudo make install - run: pip install build - run: python -m build --sdist @@ -91,7 +106,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-20.04, windows-2019, macos-12] + os: [ubuntu-20.04, windows-2019, macos-13] python-version: ['3.9', '3.10', '3.11', '3.12'] steps: diff --git a/.gitignore b/.gitignore index 213e156f..0f4570f3 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ MANIFEST .python-version *.DS_Store .venv +.hypothesis diff --git a/bin/activate b/bin/activate index 83f5d452..81e1eead 100644 --- a/bin/activate +++ b/bin/activate @@ -1,4 +1,3 @@ export C_INCLUDE_PATH=$(pwd)/.local/include export LIBRARY_PATH=$(pwd)/.local/lib export LD_LIBRARY_PATH=$(pwd)/.local/lib -export PYTHONPATH=$(pwd)/src diff --git a/bin/cibw.sh b/bin/cibw.sh deleted file mode 100755 index 23a70498..00000000 --- a/bin/cibw.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -# -# This script can be used to test cibuildwheel locally on OSX/Linux -# -# It is also worth commenting out the BEFORE_ALL line to build GMP etc after you have -# built those once because that is by far the slowest step. -# - -rm -f wheelhouse/* - -# export CIBW_ARCHS_MACOS="x86_64" -export CIBW_ARCHS_MACOS="arm64" - -export CIBW_TEST_COMMAND="python -m flint.test" # override setting in pyproject.toml - -# cibuildwheel --platform linux -# cibuildwheel --platform windows -cibuildwheel --platform macos diff --git a/bin/pip_install_ubuntu.sh b/bin/pip_install_ubuntu.sh index dce9b9d0..b28e31e7 100755 --- a/bin/pip_install_ubuntu.sh +++ b/bin/pip_install_ubuntu.sh @@ -35,7 +35,7 @@ PYTHON_FLINT=$1 # First install their dependencies and build dependencies sudo apt-get update -sudo apt-get install libgmp-dev libmpfr-dev xz-utils +sudo apt-get install libgmp-dev libmpfr-dev xz-utils ninja-build if [ -z "$FLINT_GIT" ]; then # Install from release tarball diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..b4fe7f83 --- /dev/null +++ b/meson.build @@ -0,0 +1,19 @@ +project('python-flint', 'cython', 'c') + +py = import('python').find_installation(pure: false) +dep_py = py.dependency() + +cc = meson.get_compiler('c') + +gmp_dep = dependency('gmp') +mpfr_dep = dependency('mpfr') +flint_dep = dependency('flint') + +# flint.pc was missing -lflint until Flint 3.1.0 +if flint_dep.version().version_compare('<3.1') + flint_dep = cc.find_library('flint') +endif + +pyflint_deps = [dep_py, gmp_dep, mpfr_dep, flint_dep] + +subdir('src/flint') diff --git a/pyproject.toml b/pyproject.toml index 19d18a8a..e29f7ccf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,6 @@ [build-system] -requires = ["setuptools", - "numpy; sys_platform == 'win32' and python_version < '3.12'", - "Cython>=3"] -build-backend = "setuptools.build_meta" +requires = ["meson-python", "cython"] +build-backend = "mesonpy" [project] name = "python-flint" @@ -21,6 +19,27 @@ classifiers = [ file = "README.md" content-type = "text/markdown" +[tool.spin] +package = "flint" + +[tool.spin.commands] + +"Build" = [ + "spin.cmds.meson.build", + "spin.cmds.meson.test", + "spin.cmds.build.sdist", + "spin.cmds.pip.install", +] +"Documentation" = [ + "spin.cmds.meson.docs", +] +"Environments" = [ + "spin.cmds.meson.shell", + "spin.cmds.meson.ipython", + "spin.cmds.meson.python", + "spin.cmds.meson.run", +] + [tool.cibuildwheel] build = "cp39-* cp310-* cp311-* cp312-*" skip = "*-win32 *-manylinux_i686 *-musllinux_*" @@ -28,11 +47,18 @@ manylinux-x86_64-image = "manylinux2014" manylinux-i686-image = "manylinux2014" test-command = "python -c \"import flint; print(str(flint.fmpz(2)))\"" -[tool.cibuildwheel.environment] -# bin/build_dependencies_unix.sh places headers and shared libraries under .local -C_INCLUDE_PATH = "$(pwd)/.local/include/" -LIBRARY_PATH = "$(pwd)/.local/lib/" +[tool.cibuildwheel.linux.environment] +# LD_LIBRARY_PATH is needed by auditwheel LD_LIBRARY_PATH = "$(pwd)/.local/lib:$LD_LIBRARY_PATH" +PKG_CONFIG_PATH = "$(pwd)/.local/lib/pkgconfig" + +[tool.cibuildwheel.macos.environment] +PKG_CONFIG_PATH = "$(pwd)/.local/lib/pkgconfig" + +[tool.cibuildwheel.windows.environment] +# Setting PKG_CONFIG_PATH here breaks pkgconfig for some reason... +# We set it in the CI workflow instead. +# PKG_CONFIG_PATH = "$(pwd)/.local/lib/pkgconfig:$PKG_CONFIG_PATH" [tool.cibuildwheel.linux] before-all = "bin/cibw_before_all_linux.sh" @@ -44,6 +70,3 @@ before-all = "bin/cibw_before_all_macosx_$(uname -m).sh" before-all = "C:\\msys64\\usr\\bin\\bash bin/cibw_before_all_windows.sh" before-build = "pip install delvewheel && C:\\msys64\\usr\\bin\\bash bin/cibw_before_build_windows.sh" repair-wheel-command = "bin\\cibw_repair_wheel_command_windows.bat {dest_dir} {wheel}" - -[tool.cibuildwheel.windows.environment] -PYTHON_FLINT_MINGW64 = "true" diff --git a/src/flint/flint_base/meson.build b/src/flint/flint_base/meson.build new file mode 100644 index 00000000..6c6943d7 --- /dev/null +++ b/src/flint/flint_base/meson.build @@ -0,0 +1,26 @@ +pkgdir = 'flint/flint_base' + +pyfiles = [ + '__init__.py', +] + +exts = [ + 'flint_base', + 'flint_context', +] + +py.install_sources( + pyfiles, + pure: false, + subdir: pkgdir, +) + +foreach ext : exts + py.extension_module( + ext, + ext + '.pyx', + dependencies: pyflint_deps, + install: true, + subdir: pkgdir, + ) +endforeach diff --git a/src/flint/functions/meson.build b/src/flint/functions/meson.build new file mode 100644 index 00000000..80f1f869 --- /dev/null +++ b/src/flint/functions/meson.build @@ -0,0 +1,23 @@ +pyfiles = [ + '__init__.py', +] + +exts = [ + 'showgood', +] + +py.install_sources( + pyfiles, + pure: false, + subdir: 'flint/functions', +) + +foreach ext : exts + py.extension_module( + ext, + ext + '.pyx', + dependencies: pyflint_deps, + install: true, + subdir: 'flint/functions', + ) +endforeach diff --git a/src/flint/meson.build b/src/flint/meson.build new file mode 100644 index 00000000..4ed3dc99 --- /dev/null +++ b/src/flint/meson.build @@ -0,0 +1,37 @@ +thisdir = 'flint' + +pyfiles = [ + '__init__.py', +] + +exts = [ + 'pyflint', +] + +pkgs = [ + 'flint_base', + 'types', + 'functions', + 'utils', + 'test', +] + +py.install_sources( + pyfiles, + pure: false, + subdir: thisdir, +) + +foreach ext : exts + py.extension_module( + ext, + ext + '.pyx', + dependencies: pyflint_deps, + install: true, + subdir: thisdir, + ) +endforeach + +foreach pkg : pkgs + subdir(pkg) +endforeach diff --git a/src/flint/test/__main__.py b/src/flint/test/__main__.py index 637fdb46..d16b0aa5 100644 --- a/src/flint/test/__main__.py +++ b/src/flint/test/__main__.py @@ -10,7 +10,7 @@ import argparse import flint -from flint.test.test import all_tests +from flint.test.test_all import all_tests def run_tests(verbose=None): diff --git a/src/flint/test/meson.build b/src/flint/test/meson.build new file mode 100644 index 00000000..4aa245a1 --- /dev/null +++ b/src/flint/test/meson.build @@ -0,0 +1,13 @@ +thisdir = 'flint/test' + +pyfiles = [ + '__init__.py', + '__main__.py', + 'test_all.py', +] + +py.install_sources( + pyfiles, + pure: false, + subdir: thisdir, +) diff --git a/src/flint/test/test.py b/src/flint/test/test_all.py similarity index 100% rename from src/flint/test/test.py rename to src/flint/test/test_all.py diff --git a/src/flint/types/meson.build b/src/flint/types/meson.build new file mode 100644 index 00000000..bf8caec5 --- /dev/null +++ b/src/flint/types/meson.build @@ -0,0 +1,58 @@ +thisdir = 'flint/types' + +pyfiles = [ + '__init__.py', +] + +exts = [ + 'fmpz', + 'fmpz_poly', + 'fmpz_mat', + 'fmpz_series', + + 'fmpq', + 'fmpq_poly', + 'fmpq_mat', + 'fmpq_series', + + 'nmod', + 'nmod_poly', + 'nmod_mat', + 'nmod_series', + + 'fmpz_mod', + 'fmpz_mod_poly', + 'fmpz_mod_mat', + + 'arf', + + 'arb', + 'arb_poly', + 'arb_mat', + 'arb_series', + + 'acb', + 'acb_poly', + 'acb_mat', + 'acb_series', + + 'dirichlet', + + 'fmpz_mpoly', +] + +py.install_sources( + pyfiles, + pure: false, + subdir: thisdir, +) + +foreach ext : exts + py.extension_module( + ext, + ext + '.pyx', + dependencies: pyflint_deps, + install: true, + subdir: thisdir, + ) +endforeach diff --git a/src/flint/utils/meson.build b/src/flint/utils/meson.build new file mode 100644 index 00000000..d05a2dd9 --- /dev/null +++ b/src/flint/utils/meson.build @@ -0,0 +1,24 @@ +thisdir = 'flint/utils' + +pyfiles = [ + '__init__.py', + 'flint_exceptions.py', +] + +exts = [] + +py.install_sources( + pyfiles, + pure: false, + subdir: thisdir, +) + +foreach ext : exts + py.extension_module( + ext, + ext + '.pyx', + dependencies: pyflint_deps, + install: true, + subdir: thisdir, + ) +endforeach