-
Notifications
You must be signed in to change notification settings - Fork 2
Build the Python binding with nanobind + scikit-build-core and ship bundled wheels #136
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
Open
grzanka
wants to merge
5
commits into
main
Choose a base branch
from
claude/issue-131-C9Tuo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3a48bc7
Replace ctypes binding with nanobind + scikit-build-core, ship wheels
claude 064f5c6
ci(wheels): fix sdist verification and add least-privilege permissions
claude 2d6f06c
Address review: harden Config element-array setters; explicit install…
claude 1ca7204
ci(wheels): build both macOS arches on arm64; drop scarce Intel runner
claude 8094912
docs: document the Python binding for consistency with the new package
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| name: Wheels | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| tags: ["v*"] | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: wheels-${{ github.ref }} | ||
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | ||
|
|
||
| # Least-privilege default for every job; publish jobs opt into id-token below. | ||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build_wheels: | ||
| name: Wheels on ${{ matrix.os }} | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| # macOS arm64 + x86_64 are both built on the arm64 runner (see the | ||
| # [tool.cibuildwheel.macos] archs in pyproject.toml), so the scarce | ||
| # Intel macos-13 runner is not needed. | ||
| os: [ubuntu-latest, windows-latest, macos-14] | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 # needed for setuptools_scm to resolve the version | ||
|
|
||
| - name: Build wheels | ||
| uses: pypa/cibuildwheel@v3.2.0 | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: cibw-wheels-${{ matrix.os }} | ||
| path: ./wheelhouse/*.whl | ||
|
|
||
| build_sdist: | ||
| name: Build sdist | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| # `build` with no target builds the sdist and then a wheel *from that | ||
| # sdist*, which proves the sdist is self-contained. Only the sdist is | ||
| # published; the locally-built (unrepaired) wheel is discarded. | ||
| - name: Build sdist and verify it builds a wheel | ||
| run: pipx run build | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: cibw-sdist | ||
| path: dist/*.tar.gz | ||
|
|
||
| # Dry-run publish to TestPyPI on every tag before the real PyPI release. | ||
| publish_testpypi: | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| name: Publish to TestPyPI | ||
| needs: [build_wheels, build_sdist] | ||
| runs-on: ubuntu-latest | ||
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | ||
| environment: | ||
| name: testpypi | ||
| url: https://test.pypi.org/p/libdedx | ||
| permissions: | ||
| id-token: write # OIDC trusted publishing | ||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| pattern: cibw-* | ||
| path: dist | ||
| merge-multiple: true | ||
|
|
||
| - uses: pypa/gh-action-pypi-publish@release/v1 | ||
| with: | ||
| repository-url: https://test.pypi.org/legacy/ | ||
| skip-existing: true | ||
|
|
||
| publish_pypi: | ||
| name: Publish to PyPI | ||
| needs: [publish_testpypi] | ||
| runs-on: ubuntu-latest | ||
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | ||
| environment: | ||
| name: pypi | ||
| url: https://pypi.org/p/libdedx | ||
| permissions: | ||
| id-token: write # OIDC trusted publishing | ||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| pattern: cibw-* | ||
| path: dist | ||
| merge-multiple: true | ||
|
|
||
| - uses: pypa/gh-action-pypi-publish@release/v1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| [build-system] | ||
| requires = [ | ||
| "scikit-build-core>0.10", | ||
| "nanobind>=2", | ||
| "setuptools-scm>=8", | ||
| ] | ||
| build-backend = "scikit_build_core.build" | ||
|
|
||
| [project] | ||
| name = "libdedx" | ||
| description = "Python binding for the libdedx charged-particle stopping-power library" | ||
| readme = "python/README.md" | ||
| requires-python = ">=3.9" | ||
| license = "GPL-3.0-or-later" | ||
| license-files = ["COPYING"] | ||
| authors = [ | ||
| { name = "Jakob Toftegaard" }, | ||
| { name = "Niels Bassler" }, | ||
| { name = "Leszek Grzanka" }, | ||
| ] | ||
| dependencies = ["numpy"] | ||
| dynamic = ["version"] | ||
|
|
||
| [project.urls] | ||
| Homepage = "https://github.com/APTG/libdedx" | ||
| Issues = "https://github.com/APTG/libdedx/issues" | ||
|
|
||
| [project.optional-dependencies] | ||
| test = ["pytest>=8", "numpy"] | ||
| dev = ["ruff>=0.5.0", "pytest>=8", "numpy"] | ||
|
|
||
| [tool.scikit-build] | ||
| minimum-version = "build-system.requires" | ||
| build-dir = "build/{wheel_tag}" | ||
| # The repo root is the CMake source tree; the extension is added when SKBUILD | ||
| # turns on DEDX_BUILD_PYTHON. Only the pure-Python package lives under python/. | ||
| wheel.packages = ["python/libdedx"] | ||
|
|
||
| [tool.scikit-build.cmake] | ||
| version = ">=3.21" | ||
|
|
||
| [tool.scikit-build.metadata.version] | ||
| provider = "scikit_build_core.metadata.setuptools_scm" | ||
|
|
||
| [tool.scikit-build.sdist] | ||
| # Ship the C sources/headers needed to build the extension from an sdist. The | ||
| # stopping-power tables are already embedded in src/, so the raw data/ tree is | ||
| # not required to build a wheel. | ||
| include = [ | ||
| "CMakeLists.txt", | ||
| "include/**", | ||
| "src/**", | ||
| "python/**", | ||
| ] | ||
|
|
||
| [tool.setuptools_scm] | ||
| version_scheme = "post-release" | ||
| local_scheme = "node-and-date" | ||
|
|
||
| [tool.pytest.ini_options] | ||
| testpaths = ["python/tests"] | ||
|
|
||
| [tool.ruff] | ||
| line-length = 120 | ||
| target-version = "py39" | ||
| extend-exclude = ["build"] | ||
|
|
||
| [tool.ruff.lint] | ||
| select = ["E", "F", "W"] | ||
|
|
||
| [tool.cibuildwheel] | ||
| # CPython 3.9–3.14 on 64-bit platforms; PyPy and musllinux are skipped for now. | ||
| build = "cp39-* cp310-* cp311-* cp312-* cp313-* cp314-*" | ||
| skip = "pp* *-musllinux*" | ||
| build-frontend = "build" | ||
| # Install-and-import smoke test plus the full test suite for every wheel. | ||
| test-requires = "pytest numpy" | ||
| test-command = "pytest {project}/python/tests" | ||
|
|
||
| [tool.cibuildwheel.macos] | ||
| # Build both architectures on a single (arm64) runner: arm64 natively and | ||
| # x86_64 by cross-compiling. This avoids GitHub's scarce Intel `macos-13` | ||
| # runners, which queue for a very long time. | ||
| archs = ["arm64", "x86_64"] | ||
|
|
||
| [tool.cibuildwheel.macos.environment] | ||
| MACOSX_DEPLOYMENT_TARGET = "11.0" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.