From 060530aaa6c07b034080a5c265ca418c2874b3b8 Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Tue, 17 Dec 2024 15:34:47 +0100 Subject: [PATCH 01/12] Fix job skip condition by interpreting Python version as int Currently, it's a string comparison, which means ">=" is checked by character. Hence, we invoke abi3audit even for Python 3.8 and 3.9, which is useless. This might break if free-threading gets thrown into the mix, which carries a "t" suffix in its version, preventing integer casting. --- .github/workflows/lint-and-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-test.yaml b/.github/workflows/lint-and-test.yaml index 850de12..17c3da7 100644 --- a/.github/workflows/lint-and-test.yaml +++ b/.github/workflows/lint-and-test.yaml @@ -62,7 +62,7 @@ jobs: python -c "import nanobind_example; assert nanobind_example.add(1, 2) == 3" working-directory: ${{ github.workspace }}/nanobind_example - name: Check ${{ matrix.os }} CPython>=3.12 wheels for stable ABI violations - if: matrix.py >= 3.12 + if: fromJSON(matrix.py) >= 3.12 run: | python -m pip install --upgrade abi3audit python -m abi3audit dist/*.whl --verbose From 487051424cf7300911972630a56ccde04abd0cd0 Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Wed, 18 Dec 2024 17:01:33 +0100 Subject: [PATCH 02/12] Temporarily apply stubgen patch to unbreak CI --- .github/workflows/lint-and-test.yaml | 2 ++ stubgen.patch | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 stubgen.patch diff --git a/.github/workflows/lint-and-test.yaml b/.github/workflows/lint-and-test.yaml index 17c3da7..26e00fd 100644 --- a/.github/workflows/lint-and-test.yaml +++ b/.github/workflows/lint-and-test.yaml @@ -52,6 +52,8 @@ jobs: repository: wjakob/nanobind_example path: nanobind_example ref: bazel + - run: git apply ${{github.workspace }}/stubgen.patch + working-directory: ${{ github.workspace }}/nanobind_example - name: Override nanobind_bazel pin in MODULE.bazel run: python fixup_module_bazel.py ${{ github.workspace}}/nanobind_example diff --git a/stubgen.patch b/stubgen.patch new file mode 100644 index 0000000..727a451 --- /dev/null +++ b/stubgen.patch @@ -0,0 +1,13 @@ +diff --git a/src/BUILD b/src/BUILD +index 5562dca..95e210e 100644 +--- a/src/BUILD ++++ b/src/BUILD +@@ -20,6 +20,6 @@ nanobind_stubgen( + name = "nanobind_example_ext_stubgen", + module = ":nanobind_example_ext", + marker_file = "src/py.typed", +- output_directory = "src", +- recursive = True, ++# output_directory = "src", ++# recursive = True, + ) From 043bb11858f8d0d1d8355d4d353d18f9826d3e4f Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Wed, 18 Dec 2024 17:08:47 +0100 Subject: [PATCH 03/12] Try with explicit brackets --- .github/workflows/lint-and-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-test.yaml b/.github/workflows/lint-and-test.yaml index 26e00fd..999d565 100644 --- a/.github/workflows/lint-and-test.yaml +++ b/.github/workflows/lint-and-test.yaml @@ -64,7 +64,7 @@ jobs: python -c "import nanobind_example; assert nanobind_example.add(1, 2) == 3" working-directory: ${{ github.workspace }}/nanobind_example - name: Check ${{ matrix.os }} CPython>=3.12 wheels for stable ABI violations - if: fromJSON(matrix.py) >= 3.12 + if: ${{ fromJSON(matrix.py) >= 3.12 }} run: | python -m pip install --upgrade abi3audit python -m abi3audit dist/*.whl --verbose From 6767c2991e6fb52386ea9d2ee57a07c666961d11 Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Wed, 18 Dec 2024 20:19:12 +0100 Subject: [PATCH 04/12] Switch CI to uv, use floats as Python versions This should make things somewhat faster, and finally fix the comparison. --- .github/workflows/lint-and-test.yaml | 41 ++++++++++------------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/.github/workflows/lint-and-test.yaml b/.github/workflows/lint-and-test.yaml index 999d565..59ad70b 100644 --- a/.github/workflows/lint-and-test.yaml +++ b/.github/workflows/lint-and-test.yaml @@ -12,40 +12,28 @@ jobs: buildifier: name: Lint Bazel files with buildifier runs-on: ubuntu-latest - env: - PRE_COMMIT_HOME: "${{ github.workspace }}/.cache/pre-commit" steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Set up Python and dependencies - uses: actions/setup-python@v5 - with: - python-version: 3.12 - - name: Install pre-commit - run: pip install --upgrade pre-commit - - name: Cache pre-commit tools - uses: actions/cache@v4 - with: - path: ${{ env.PRE_COMMIT_HOME }} - key: ${{ hashFiles('.pre-commit-config.yaml') }}-linter-cache + - name: Install uv + uses: astral-sh/setup-uv@v3 - name: Run pre-commit checks - run: pre-commit run --all-files --verbose --show-diff-on-failure + run: uvx pre-commit run --all-files --verbose --show-diff-on-failure test: - name: Test nanobind_example on ${{ matrix.os }} w/ Python ${{ matrix.py }} + name: Test nanobind_example on ${{ matrix.os }} w/ Python ${{ matrix.python-version }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - py: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] + python-version: [3.8, 3.9, 3.10, 3.11, 3.12, 3.13] steps: - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.py }} on ${{ matrix.os }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.py }} - - run: python -m pip install build + - name: Install uv + uses: astral-sh/setup-uv@v3 + - name: Install Python ${{ matrix.python-version }} + run: uv python install ${{ matrix.python-version }} - name: Check out nanobind example repo uses: actions/checkout@v4 with: @@ -59,14 +47,15 @@ jobs: run: python fixup_module_bazel.py ${{ github.workspace}}/nanobind_example - name: Build and test nanobind_example on ${{ matrix.os }} run: | - python -m build . -w - python -m pip install --find-links=dist/ nanobind_example + uv pip install build + uv run -m build . -w + uv pip install --find-links=dist/ nanobind_example python -c "import nanobind_example; assert nanobind_example.add(1, 2) == 3" working-directory: ${{ github.workspace }}/nanobind_example - name: Check ${{ matrix.os }} CPython>=3.12 wheels for stable ABI violations - if: ${{ fromJSON(matrix.py) >= 3.12 }} + if: matrix.python-version >= 3.12 run: | - python -m pip install --upgrade abi3audit - python -m abi3audit dist/*.whl --verbose + uv pip install abi3audit + uv run -m abi3audit dist/*.whl --verbose --summary shell: bash working-directory: ${{ github.workspace }}/nanobind_example From 15c4caa5dfdc5a15130d733433b4d8643ee86e59 Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Wed, 18 Dec 2024 20:33:00 +0100 Subject: [PATCH 05/12] Add venv construction to build pipeline --- .github/workflows/lint-and-test.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/lint-and-test.yaml b/.github/workflows/lint-and-test.yaml index 59ad70b..ef77da1 100644 --- a/.github/workflows/lint-and-test.yaml +++ b/.github/workflows/lint-and-test.yaml @@ -47,10 +47,13 @@ jobs: run: python fixup_module_bazel.py ${{ github.workspace}}/nanobind_example - name: Build and test nanobind_example on ${{ matrix.os }} run: | + uv venv --seed -p ${{ matrix.python-version }} + source .venv/bin/activate uv pip install build uv run -m build . -w uv pip install --find-links=dist/ nanobind_example python -c "import nanobind_example; assert nanobind_example.add(1, 2) == 3" + shell: bash working-directory: ${{ github.workspace }}/nanobind_example - name: Check ${{ matrix.os }} CPython>=3.12 wheels for stable ABI violations if: matrix.python-version >= 3.12 From 9d2179349463372e369fe9bf170b440c679f59e8 Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Wed, 18 Dec 2024 20:41:34 +0100 Subject: [PATCH 06/12] Give proper name to stubgen patch job --- .github/workflows/lint-and-test.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-test.yaml b/.github/workflows/lint-and-test.yaml index ef77da1..8f1ae87 100644 --- a/.github/workflows/lint-and-test.yaml +++ b/.github/workflows/lint-and-test.yaml @@ -40,7 +40,8 @@ jobs: repository: wjakob/nanobind_example path: nanobind_example ref: bazel - - run: git apply ${{github.workspace }}/stubgen.patch + - name: Patch nanobind_example stubgen target + run: git apply ${{github.workspace }}/stubgen.patch working-directory: ${{ github.workspace }}/nanobind_example - name: Override nanobind_bazel pin in MODULE.bazel From dbc232100ab9bdf66664d9db4da264fb74fb842f Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Wed, 18 Dec 2024 21:06:37 +0100 Subject: [PATCH 07/12] Use no-editable install for uv run --- .github/workflows/lint-and-test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-and-test.yaml b/.github/workflows/lint-and-test.yaml index 8f1ae87..1832196 100644 --- a/.github/workflows/lint-and-test.yaml +++ b/.github/workflows/lint-and-test.yaml @@ -27,7 +27,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: [3.8, 3.9, 3.10, 3.11, 3.12, 3.13] + python-version: [3.8, 3.9, "3.10", 3.11, 3.12, 3.13] steps: - uses: actions/checkout@v4 - name: Install uv @@ -51,7 +51,7 @@ jobs: uv venv --seed -p ${{ matrix.python-version }} source .venv/bin/activate uv pip install build - uv run -m build . -w + uv run --no-editable -m build . -w uv pip install --find-links=dist/ nanobind_example python -c "import nanobind_example; assert nanobind_example.add(1, 2) == 3" shell: bash From 85335a4dc1e8f74c9bd3d3f003e0075b626bc875 Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Wed, 18 Dec 2024 21:26:18 +0100 Subject: [PATCH 08/12] Rework pipeline with uv sync to not have to activate venv --- .github/workflows/lint-and-test.yaml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint-and-test.yaml b/.github/workflows/lint-and-test.yaml index 1832196..6f88dcc 100644 --- a/.github/workflows/lint-and-test.yaml +++ b/.github/workflows/lint-and-test.yaml @@ -48,11 +48,9 @@ jobs: run: python fixup_module_bazel.py ${{ github.workspace}}/nanobind_example - name: Build and test nanobind_example on ${{ matrix.os }} run: | - uv venv --seed -p ${{ matrix.python-version }} - source .venv/bin/activate - uv pip install build - uv run --no-editable -m build . -w - uv pip install --find-links=dist/ nanobind_example + uv sync --no-install-project + uv build --wheel -o dist + uv pip install --no-index --find-links=dist/ nanobind_example python -c "import nanobind_example; assert nanobind_example.add(1, 2) == 3" shell: bash working-directory: ${{ github.workspace }}/nanobind_example From cd57ed2e3fad45720de630d52bf8637fa642c5b8 Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Wed, 18 Dec 2024 21:42:53 +0100 Subject: [PATCH 09/12] Move wheel build to abi3audit job portion --- .github/workflows/lint-and-test.yaml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/lint-and-test.yaml b/.github/workflows/lint-and-test.yaml index 6f88dcc..213e75e 100644 --- a/.github/workflows/lint-and-test.yaml +++ b/.github/workflows/lint-and-test.yaml @@ -17,7 +17,7 @@ jobs: with: fetch-depth: 0 - name: Install uv - uses: astral-sh/setup-uv@v3 + uses: astral-sh/setup-uv@v4 - name: Run pre-commit checks run: uvx pre-commit run --all-files --verbose --show-diff-on-failure test: @@ -31,9 +31,10 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install uv - uses: astral-sh/setup-uv@v3 - - name: Install Python ${{ matrix.python-version }} - run: uv python install ${{ matrix.python-version }} + uses: astral-sh/setup-uv@v4 + with: + python-version: ${{ matrix.python-version }} + enable-cache: true - name: Check out nanobind example repo uses: actions/checkout@v4 with: @@ -48,16 +49,14 @@ jobs: run: python fixup_module_bazel.py ${{ github.workspace}}/nanobind_example - name: Build and test nanobind_example on ${{ matrix.os }} run: | - uv sync --no-install-project - uv build --wheel -o dist - uv pip install --no-index --find-links=dist/ nanobind_example - python -c "import nanobind_example; assert nanobind_example.add(1, 2) == 3" - shell: bash + uv sync --no-editable + uv run python -c "import nanobind_example; assert nanobind_example.add(1, 2) == 3" working-directory: ${{ github.workspace }}/nanobind_example - name: Check ${{ matrix.os }} CPython>=3.12 wheels for stable ABI violations if: matrix.python-version >= 3.12 run: | uv pip install abi3audit + uv build --wheel -o dist uv run -m abi3audit dist/*.whl --verbose --summary shell: bash working-directory: ${{ github.workspace }}/nanobind_example From f3ba870373aad15e4414474d61e8032cc0b1a21c Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Wed, 18 Dec 2024 21:46:32 +0100 Subject: [PATCH 10/12] Remove cache again --- .github/workflows/lint-and-test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/lint-and-test.yaml b/.github/workflows/lint-and-test.yaml index 213e75e..887001f 100644 --- a/.github/workflows/lint-and-test.yaml +++ b/.github/workflows/lint-and-test.yaml @@ -34,7 +34,6 @@ jobs: uses: astral-sh/setup-uv@v4 with: python-version: ${{ matrix.python-version }} - enable-cache: true - name: Check out nanobind example repo uses: actions/checkout@v4 with: From 4472da5971f7f2e82c20d4c7e24b0ed92df32b9c Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Wed, 18 Dec 2024 21:59:58 +0100 Subject: [PATCH 11/12] Add --no-sync to run commands, make note --- .github/workflows/lint-and-test.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint-and-test.yaml b/.github/workflows/lint-and-test.yaml index 887001f..234bebf 100644 --- a/.github/workflows/lint-and-test.yaml +++ b/.github/workflows/lint-and-test.yaml @@ -47,15 +47,16 @@ jobs: - name: Override nanobind_bazel pin in MODULE.bazel run: python fixup_module_bazel.py ${{ github.workspace}}/nanobind_example - name: Build and test nanobind_example on ${{ matrix.os }} + # --no-sync is required so that uv does not remove the .so file again. run: | uv sync --no-editable - uv run python -c "import nanobind_example; assert nanobind_example.add(1, 2) == 3" + uv run --no-sync -- python -c "import nanobind_example; assert nanobind_example.add(1, 2) == 3" working-directory: ${{ github.workspace }}/nanobind_example - name: Check ${{ matrix.os }} CPython>=3.12 wheels for stable ABI violations if: matrix.python-version >= 3.12 run: | uv pip install abi3audit - uv build --wheel -o dist - uv run -m abi3audit dist/*.whl --verbose --summary + uv build --wheel + uv run --no-sync abi3audit dist/*.whl --verbose --summary shell: bash working-directory: ${{ github.workspace }}/nanobind_example From 03f09ae5dc38547405e69a3e83dd7c0c6b1eabed Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Wed, 18 Dec 2024 22:18:18 +0100 Subject: [PATCH 12/12] Just give up and do an array membership check --- .github/workflows/lint-and-test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-and-test.yaml b/.github/workflows/lint-and-test.yaml index 234bebf..36ec512 100644 --- a/.github/workflows/lint-and-test.yaml +++ b/.github/workflows/lint-and-test.yaml @@ -27,7 +27,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: [3.8, 3.9, "3.10", 3.11, 3.12, 3.13] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 - name: Install uv @@ -53,7 +53,7 @@ jobs: uv run --no-sync -- python -c "import nanobind_example; assert nanobind_example.add(1, 2) == 3" working-directory: ${{ github.workspace }}/nanobind_example - name: Check ${{ matrix.os }} CPython>=3.12 wheels for stable ABI violations - if: matrix.python-version >= 3.12 + if: ${{ contains(fromJSON('["3.12", "3.13"]'), matrix.python-version) }} run: | uv pip install abi3audit uv build --wheel