Skip to content

Commit

Permalink
Merge pull request #129 from oscarbenjamin/pr_meson_python
Browse files Browse the repository at this point in the history
Use meson-python instead of setuptools for wheels
  • Loading branch information
oscarbenjamin committed Apr 25, 2024
2 parents 1ce152d + cfe2fea commit a65c88c
Show file tree
Hide file tree
Showing 16 changed files with 260 additions and 42 deletions.
12 changes: 5 additions & 7 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"
21 changes: 18 additions & 3 deletions .github/workflows/buildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ MANIFEST
.python-version
*.DS_Store
.venv
.hypothesis
1 change: 0 additions & 1 deletion bin/activate
Original file line number Diff line number Diff line change
@@ -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
18 changes: 0 additions & 18 deletions bin/cibw.sh

This file was deleted.

2 changes: 1 addition & 1 deletion bin/pip_install_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -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')
45 changes: 34 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -21,18 +19,46 @@ 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_*"
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"
Expand All @@ -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"
26 changes: 26 additions & 0 deletions src/flint/flint_base/meson.build
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions src/flint/functions/meson.build
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions src/flint/meson.build
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/flint/test/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions src/flint/test/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
thisdir = 'flint/test'

pyfiles = [
'__init__.py',
'__main__.py',
'test_all.py',
]

py.install_sources(
pyfiles,
pure: false,
subdir: thisdir,
)
File renamed without changes.
58 changes: 58 additions & 0 deletions src/flint/types/meson.build
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions src/flint/utils/meson.build
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a65c88c

Please sign in to comment.