Skip to content

Commit 539f9cc

Browse files
Merge pull request #5 from feltor-dev/pypi
Build and submit binary wheel to pypi The wheel is built for linux, windows and macos
2 parents cd546d4 + 20af6fb commit 539f9cc

File tree

3 files changed

+115
-41
lines changed

3 files changed

+115
-41
lines changed
Lines changed: 94 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,103 @@
11
name: Build/publish Python Package
22

3-
on: push
3+
# Adopted from gh:pybind/scikit_build_example
4+
# Read more on https://cibuildwheel.pypa.io/en/stable
5+
6+
on:
7+
workflow_dispatch:
8+
pull_request:
9+
push:
10+
branches:
11+
- main
12+
release:
13+
types:
14+
- published
15+
16+
env:
17+
FORCE_COLOR: 3
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
422

523
jobs:
6-
build:
24+
build_sdist:
25+
name: Build SDist
726
runs-on: ubuntu-latest
827
steps:
9-
- uses: actions/checkout@v4
10-
with:
11-
fetch-depth: 0
12-
- name: Set up Python
13-
uses: actions/setup-python@v5
14-
with:
15-
python-version: '3.x'
16-
- name: Install dependencies
17-
run: |
18-
python -m pip install --upgrade pip
19-
python -m pip install build twine
20-
- name: Build package
21-
run: |
22-
python -m build --sdist --wheel
23-
- name: Check package
24-
run: |
25-
python -m twine check dist/*
26-
- name: Store the distribution packages
27-
uses: actions/upload-artifact@v4
28-
with:
29-
name: python-package-distributions
30-
path: dist/
31-
32-
publish-to-pypi:
33-
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
34-
needs:
35-
- build
28+
- uses: actions/checkout@v4
29+
30+
- name: Build SDist
31+
run: pipx run build --sdist
32+
33+
- name: Check metadata
34+
run: pipx run twine check dist/*
35+
36+
- uses: actions/upload-artifact@v4
37+
with:
38+
name: cibw-sdist
39+
path: dist/*.tar.gz
40+
41+
42+
build_wheels:
43+
name: Build wheels on ${{ matrix.os }}
44+
runs-on: ${{ matrix.os }}
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
os: [windows-latest, macos-latest, ubuntu-latest]
49+
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- uses: astral-sh/setup-uv@v4
54+
55+
- name: Build wheels
56+
uses: pypa/cibuildwheel@v3.0.0
57+
env:
58+
CIBW_ARCHS_WINDOWS: auto64
59+
CIBW_ENVIRONMENT_MACOS: CXX="g++-13" MACOSX_DEPLOYMENT_TARGET="14.0"
60+
with:
61+
package-dir: .
62+
output-dir: wheelhouse
63+
config-file: "{package}/pyproject.toml"
64+
65+
- name: Verify clean directory
66+
run: git diff --exit-code
67+
shell: bash
68+
69+
- uses: actions/upload-artifact@v4
70+
with:
71+
name: cibw-wheels-${{ matrix.os }}
72+
path: wheelhouse/*.whl
73+
74+
75+
upload_all:
76+
name: Upload if release
77+
needs: [build_wheels, build_sdist]
3678
runs-on: ubuntu-latest
37-
environment:
38-
name: pypi
79+
if: github.event_name == 'release' && github.event.action == 'published'
80+
environment: pypi
3981
permissions:
40-
id-token: write # IMPORTANT: mandatory for trusted publishing
82+
id-token: write
83+
attestations: write
84+
4185
steps:
42-
- name: Download distribution packages
43-
uses: actions/download-artifact@v4
44-
with:
45-
name: python-package-distributions
46-
path: dist/
47-
- name: Publish to PyPI
48-
uses: pypa/gh-action-pypi-publish@release/v1
86+
- uses: actions/setup-python@v5
87+
with:
88+
python-version: "3.x"
89+
90+
- uses: actions/download-artifact@v4
91+
with:
92+
pattern: cibw-*
93+
merge-multiple: true
94+
path: dist
95+
96+
- name: Generate artifact attestation for sdist and wheels
97+
uses: actions/attest-build-provenance@v1
98+
with:
99+
subject-path: "dist/*"
100+
101+
- uses: pypa/gh-action-pypi-publish@release/v1
102+
with:
103+
attestations: true

.github/workflows/test.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ on: [push, pull_request]
44

55
jobs:
66
pytest:
7-
runs-on: ubuntu-latest
7+
runs-on: ${{ matrix.os }}
88
strategy:
99
fail-fast: false
1010
matrix:
11+
os: [windows-latest, macos-latest, ubuntu-latest]
1112
python-version: ["3.12", "3.13"]
1213

1314
steps:
@@ -17,7 +18,12 @@ jobs:
1718
with:
1819
python-version: ${{ matrix.python-version }}
1920
- name: Install dependencies
21+
shell: bash
2022
run: |
23+
if [[ ${{ matrix.os }} = "macos-latest" ]]; then
24+
export CXX=g++-13
25+
g++-13 --version
26+
fi
2127
python -m pip install --upgrade pip
2228
python -m pip install .[test]
2329
- name: Test with pytest

pyproject.toml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ classifiers = [
1919
"Operating System :: POSIX :: Linux",
2020
"Programming Language :: Python :: 3",
2121
]
22-
version = "0.1.0" # TODO How to get automatic versioning in scikit?
22+
version = "0.1.1" # TODO How to get automatic versioning in scikit?
2323
[project.urls]
2424
Source = "https://github.com/feltor-dev/pyfeltor"
2525
Tracker = "https://github.com/feltor-dev/pyfeltor/issues"
@@ -35,6 +35,19 @@ build-backend = "scikit_build_core.build"
3535
build.verbose = true # cmake --build . -v ## only visible if pip install . -v is used
3636
cmake.args = ["-DCMAKE_POLICY_VERSION_MINIMUM=3.5"] # Necessary for nlohmann_json with cmake>4.0
3737

38+
# Since we distribute binary wheels we need to build for multiple os using
39+
# gh:pypa/cibuildwheel
40+
# You can local test using (requires docker)
41+
# uvx cibuildwheel
42+
[tool.cibuildwheel]
43+
build-frontend = "build[uv]"
44+
test-command = "pytest {project}/tests"
45+
test-extras = ["test"]
46+
skip = "*-musllinux*" # Skip musllinux (conflicts with libcudacxx)
47+
48+
[tool.cibuildwheel.pyodide]
49+
build-frontend = {name = "build", args = ["--exports", "whole_archive"]}
50+
3851

3952
[project.optional-dependencies]
4053
test = [

0 commit comments

Comments
 (0)