Skip to content

Commit dc26dc8

Browse files
authored
Merge pull request #234 from tobiasdiez/wheel
Use `uv` and simplify wheel building
2 parents 896256e + 050dddc commit dc26dc8

File tree

10 files changed

+597
-119
lines changed

10 files changed

+597
-119
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,21 @@ jobs:
2929
with:
3030
submodules: recursive
3131
fetch-depth: 0
32-
- name: Set up Python ${{ matrix.python-version }}
32+
- name: Setup Python ${{ matrix.python-version }}
3333
uses: actions/setup-python@v5
3434
with:
3535
python-version: ${{ matrix.python-version }}
36-
- name: Install dependencies
37-
run: |
38-
pip install --upgrade pip
39-
pip install --upgrade -r requirements.txt
40-
pip install --upgrade ninja
36+
- name: Setup uv
37+
uses: astral-sh/setup-uv@v6
4138
- name: Build
42-
run: pip install -v --no-build-isolation --config-settings=builddir=builddir .
39+
run: |
40+
uv sync --frozen --inexact -v --no-install-project
41+
uv sync --frozen --inexact -v --no-build-isolation --no-editable --config-settings=builddir=builddir
4342
- name: Install cypari2
4443
run: |
4544
sudo apt-get update
4645
sudo apt-get install pari-gp libpari-dev
4746
pip install --upgrade cypari2
4847
if: matrix.os == 'ubuntu-latest'
4948
- name: Test
50-
run: meson test --print-errorlogs -C builddir
49+
run: uv run --no-editable meson test --print-errorlogs -C builddir

.github/workflows/dist.yml

Lines changed: 36 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -11,128 +11,75 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
jobs:
14-
15-
sdists_for_pypi:
16-
name: Build sdist (and upload to PyPI on release tags)
14+
make_sdist:
15+
name: Build sdist
1716
runs-on: ubuntu-latest
18-
env:
19-
CAN_DEPLOY: ${{ secrets.SAGEMATH_PYPI_API_TOKEN != '' }}
2017
steps:
2118
- uses: actions/checkout@v4
22-
- uses: actions/setup-python@v4
23-
- name: Install dependencies
24-
run: |
25-
pip install --upgrade pip
26-
pip install --upgrade -r requirements.txt
19+
- uses: astral-sh/setup-uv@v6
2720
- name: Build sdist
28-
run: python -m build --sdist .
21+
run: uv build --sdist
2922
- uses: actions/upload-artifact@v4
3023
with:
3124
path: "dist/*.tar.*"
32-
name: dist
33-
- uses: pypa/gh-action-pypi-publish@release/v1
34-
with:
35-
user: __token__
36-
password: ${{ secrets.SAGEMATH_PYPI_API_TOKEN }}
37-
skip_existing: true
38-
verbose: true
39-
if: env.CAN_DEPLOY == 'true' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
25+
name: release-sdist
4026

4127
build_wheels:
42-
name: Build wheels on ${{ matrix.os }}, arch ${{ matrix.arch }}
28+
name: Build wheels on ${{ matrix.os }}
4329
runs-on: ${{ matrix.os }}
44-
needs: sdists_for_pypi
4530
strategy:
4631
fail-fast: false
4732
matrix:
48-
include:
49-
- os: ubuntu-latest
50-
arch: x86_64
51-
- os: ubuntu-latest
52-
arch: i686
53-
- os: macos-13
54-
arch: x86_64
55-
- os: macos-14
56-
arch: arm64
57-
env:
58-
# SPKGs to install as system packages
59-
SPKGS: _bootstrap _prereq
60-
# Non-Python packages to install as spkgs
61-
TARGETS_PRE:
62-
# on pp310: build/src/cysignals/implementation.c:231:9: error: implicit declaration of function 'PyPyErr_SetInterrupt' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
63-
CIBW_SKIP: "pp31*"
64-
#
65-
CIBW_ARCHS: ${{ matrix.arch }}
66-
# https://cibuildwheel.readthedocs.io/en/stable/options/#requires-python
67-
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.9"
68-
# Environment during wheel build
69-
CIBW_ENVIRONMENT: "PATH=$(pwd)/local/bin:$PATH CPATH=$(pwd)/local/include:$CPATH LIBRARY_PATH=$(pwd)/local/lib:$LIBRARY_PATH LD_LIBRARY_PATH=$(pwd)/local/lib:$LD_LIBRARY_PATH PKG_CONFIG_PATH=$(pwd)/local/share/pkgconfig:$PKG_CONFIG_PATH ACLOCAL_PATH=/usr/share/aclocal"
70-
# Use 'build', not 'pip wheel'
71-
CIBW_BUILD_FRONTEND: build
33+
os:
34+
- ubuntu-latest
35+
- ubuntu-24.04-arm
36+
- windows-latest
37+
- windows-11-arm
38+
- macos-13
39+
- macos-latest
7240
steps:
7341
- uses: actions/checkout@v4
74-
with:
75-
repository: sagemath/sage
76-
ref: develop
77-
78-
- uses: actions/download-artifact@v4
79-
with:
80-
name: dist
81-
path: dist
82-
83-
- uses: actions/setup-python@v5
84-
# As of 2024-02-03, the macOS M1 runners do not have preinstalled python or pipx.
85-
# Installing pipx follows the approach of https://github.com/pypa/cibuildwheel/pull/1743
86-
id: python
87-
with:
88-
python-version: "3.9 - 3.12"
89-
update-environment: false
90-
91-
- name: Build platform wheels
92-
# We build the wheel from the sdist.
93-
# But we must run cibuildwheel with the unpacked source directory, not a tarball,
94-
# so that SAGE_ROOT is copied into the build containers.
95-
#
96-
# In the CIBW_BEFORE_ALL phase, we install libraries using the Sage distribution.
97-
# https://cibuildwheel.readthedocs.io/en/stable/options/#before-all
98-
run: |
99-
"${{ steps.python.outputs.python-path }}" -m pip install pipx
100-
export PATH=build/bin:$PATH
101-
export CIBW_BEFORE_ALL="( $(sage-print-system-package-command debian --yes --no-install-recommends install $(sage-get-system-packages debian $SPKGS)) || $(sage-print-system-package-command fedora --yes --no-install-recommends install $(sage-get-system-packages fedora $SPKGS | sed s/pkg-config/pkgconfig/)) || ( $(sage-print-system-package-command homebrew --yes --no-install-recommends install $(sage-get-system-packages homebrew $SPKGS)) || $(sage-print-system-package-command alpine --yes --no-install-recommends install $(sage-get-system-packages alpine $SPKGS)) || echo error ignored) )"
102-
mkdir -p unpacked
103-
for pkg in cysignals; do
104-
(cd unpacked && tar xfz - ) < dist/$pkg*.tar.gz
105-
"${{ steps.python.outputs.python-path }}" -m pipx run cibuildwheel==2.18.0 unpacked/$pkg*
106-
done
107-
42+
- uses: astral-sh/setup-uv@v6
43+
- name: Build wheels
44+
uses: pypa/cibuildwheel@v3.1
10845
- uses: actions/upload-artifact@v4
10946
with:
110-
name: ${{ matrix.os }}-${{ matrix.arch }}-wheels
111-
path: ./wheelhouse/*.whl
47+
name: release-wheels-${{ matrix.os }}
48+
path: wheelhouse/*.whl
11249

11350
pypi-publish:
11451
# This needs to be a separate job because pypa/gh-action-pypi-publish cannot run on macOS
11552
# https://github.com/pypa/gh-action-pypi-publish
11653
name: Upload wheels to PyPI
117-
needs: build_wheels
118-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
54+
needs: [build_wheels, make_sdist]
55+
if:
11956
runs-on: ubuntu-latest
12057
env:
12158
CAN_DEPLOY: ${{ secrets.SAGEMATH_PYPI_API_TOKEN != '' }}
59+
permissions:
60+
id-token: write
61+
attestations: write
62+
contents: read
12263
steps:
123-
12464
- uses: actions/download-artifact@v4
12565
with:
126-
pattern: "*-*-wheels"
127-
path: wheelhouse
66+
pattern: release-*
67+
path: dist
12868
merge-multiple: true
69+
70+
- name: List files
71+
run: ls -l -R dist
72+
73+
- name: Generate artifact attestations
74+
uses: actions/attest-build-provenance@v2
75+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
76+
with:
77+
subject-path: "dist/*"
12978

13079
- name: Publish package distributions to PyPI
13180
uses: pypa/gh-action-pypi-publish@release/v1
13281
with:
13382
user: __token__
13483
password: ${{ secrets.SAGEMATH_PYPI_API_TOKEN }}
135-
packages_dir: wheelhouse/
136-
skip_existing: true
13784
verbose: true
138-
if: env.CAN_DEPLOY == 'true'
85+
if: env.CAN_DEPLOY == 'true' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

example/README

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
This is a minimal working example package using cysignals.
22

33
Building this package is also part of the cysignals testsuite.
4+
5+
On a clear repo, and no cysignals installed anywhere, the following
6+
works:
7+
8+
uv venv
9+
source .venv/bin/activate
10+
uv sync --frozen --inexact -v --no-install-project
11+
uv sync --frozen --inexact -v --no-build-isolation --no-editable --config-settings=builddir=builddir
12+
uv run --no-editable meson test --print-errorlogs -C builddir

example/meson.build

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,7 @@ project('cysignals_example', 'cython', 'cpp')
22

33
py = import('python').find_installation()
44

5-
inc_cysignals = run_command(
6-
py,
7-
[
8-
'-c',
9-
'''
10-
import cysignals
11-
print(cysignals.__file__.replace('__init__.py', ''))
12-
'''.strip(),
13-
],
14-
check: true,
15-
).stdout().strip()
16-
cysignals = declare_dependency(include_directories: inc_cysignals)
5+
cysignals = dependency('cysignals')
176

187
py.extension_module('cysignals_example',
198
sources: ['cysignals_example.pyx'],

example/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["meson-python", "cython>=0.28"]
2+
requires = ["meson-python", "cython>=0.28", "pkgconf"]
33
build-backend = "mesonpy"
44

55
[project]

pyproject.toml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,34 @@ classifiers = [
3030
"Topic :: Software Development :: Debuggers",
3131
]
3232
urls = { Homepage = "https://github.com/sagemath/cysignals" }
33-
requires-python = ">=3.9"
33+
requires-python = ">=3.9,<3.14"
34+
35+
[project.entry-points.pkg_config]
36+
cysignals = 'cysignals'
3437

3538
[tool.pytest.ini_options]
3639
addopts = "--doctest-modules --import-mode importlib"
3740
testpaths = "src tests"
41+
42+
[dependency-groups]
43+
dev = [
44+
"build>=1.3.0",
45+
"cibuildwheel>=2.23.3",
46+
"cython>=3.1.4",
47+
"meson>=1.9.0",
48+
"meson-python>=0.18.0",
49+
"ninja>=1.13.0",
50+
"pkgconf>=2.4.3.post2",
51+
"pytest>=8.4.2",
52+
]
53+
54+
[tool.cibuildwheel]
55+
skip = ["*-win32"]
56+
test-groups = ["dev"]
57+
test-sources = ["tests", "pyproject.toml"]
58+
test-command = "python -m pytest"
59+
build-frontend = "build[uv]"
60+
build-verbosity = 1
61+
62+
[tool.cibuildwheel.windows]
63+
config-settings = { setup-args = ["--vsenv"] }

requirements.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/cysignals/cysignals.pc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
includedir=${pcfiledir}
2+
3+
Name: cysignals
4+
Description: cysignals library
5+
Version: 1.0.0
6+
Cflags: -I${includedir}

src/cysignals/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ configure_file(output: 'cysignals_config.h', configuration: config, install_dir:
22

33
py.install_sources(
44
'__init__.py',
5+
'cysignals.pc',
56
'cysignals-CSI-helper.py',
67
'memory.pxd',
78
'pysignals.pxd',

0 commit comments

Comments
 (0)