Skip to content

Commit 7d166f7

Browse files
authored
ci: reduce number of jobs & improve coverage measurement (#5052)
* ci: run coverage as part of "build" job * merge free-threaded tests into main build jobs * make `test-introspection` jobs only run on PRs if requested * fix 3.7 & 3.8 build error * fix `check-feature-powerset`
1 parent c545b2e commit 7d166f7

File tree

4 files changed

+95
-95
lines changed

4 files changed

+95
-95
lines changed

.github/workflows/build.yml

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ jobs:
2727
if: ${{ !(startsWith(inputs.python-version, 'graalpy') && startsWith(inputs.os, 'windows')) }}
2828
steps:
2929
- uses: actions/checkout@v4
30+
with:
31+
# For PRs, we need to run on the real PR head, not the resultant merge of the PR into the target branch.
32+
#
33+
# This is necessary for coverage reporting to make sense; we then get exactly the coverage change
34+
# between the base branch and the real PR head.
35+
#
36+
# If it were run on the merge commit the problem is that the coverage potentially does not align
37+
# with the commit diff, because the merge may affect line numbers.
38+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
3039

3140
- name: Set up Python ${{ inputs.python-version }}
3241
uses: actions/setup-python@v5
@@ -40,7 +49,7 @@ jobs:
4049
- name: Install nox
4150
run: python -m pip install --upgrade pip && pip install nox
4251

43-
- if: inputs.python-version == 'graalpy24.1'
52+
- if: ${{ startsWith(inputs.python-version, 'graalpy24.1') }}
4453
name: Install GraalPy virtualenv (only GraalPy 24.1)
4554
run: python -m pip install 'git+https://github.com/oracle/graalpython#egg=graalpy_virtualenv_seeder&subdirectory=graalpy_virtualenv_seeder'
4655

@@ -49,8 +58,17 @@ jobs:
4958
with:
5059
toolchain: ${{ inputs.rust }}
5160
targets: ${{ inputs.rust-target }}
52-
# needed to correctly format errors, see #1865
53-
components: rust-src
61+
# rust-src needed to correctly format errors, see #1865
62+
components: rust-src,llvm-tools-preview
63+
64+
# On windows 32 bit, we are running on an x64 host, so we need to specifically set the target
65+
# NB we don't do this for *all* jobs because it breaks coverage of proc macros to have an
66+
# explicit target set.
67+
- name: Set Rust target for Windows 32-bit
68+
if: inputs.os == 'windows-latest' && inputs.python-architecture == 'x86'
69+
shell: bash
70+
run: |
71+
echo "CARGO_BUILD_TARGET=i686-pc-windows-msvc" >> $GITHUB_ENV
5472
5573
- uses: Swatinem/rust-cache@v2
5674
with:
@@ -72,6 +90,16 @@ jobs:
7290
name: Prepare to test on nightly rust
7391
run: echo "MAYBE_NIGHTLY=nightly" >> "$GITHUB_ENV"
7492

93+
- if: ${{ github.event_name != 'merge_group' }}
94+
name: Install cargo-llvm-cov
95+
uses: taiki-e/install-action@cargo-llvm-cov
96+
97+
- if: ${{ github.event_name != 'merge_group' }}
98+
name: Prepare coverage environment
99+
run: |
100+
cargo llvm-cov clean --workspace --profraw-only
101+
nox -s set-coverage-env
102+
75103
- name: Build docs
76104
run: nox -s docs
77105

@@ -154,9 +182,26 @@ jobs:
154182
if: ${{ endsWith(inputs.python-version, '-dev') || (steps.ffi-changes.outputs.changed == 'true' && inputs.rust == 'stable' && !startsWith(inputs.python-version, 'graalpy') && !(inputs.python-version == 'pypy3.9' && contains(inputs.os, 'windows'))) }}
155183
run: nox -s ffi-check
156184

185+
- if: ${{ github.event_name != 'merge_group' }}
186+
name: Generate coverage report
187+
run: cargo llvm-cov
188+
--package=pyo3
189+
--package=pyo3-build-config
190+
--package=pyo3-macros-backend
191+
--package=pyo3-macros
192+
--package=pyo3-ffi
193+
report --codecov --output-path coverage.json
194+
195+
- if: ${{ github.event_name != 'merge_group' }}
196+
name: Upload coverage report
197+
uses: codecov/codecov-action@v4
198+
with:
199+
file: coverage.json
200+
name: ${{ inputs.os }}/${{ inputs.python-version }}/${{ inputs.rust }}
201+
token: ${{ secrets.CODECOV_TOKEN }}
202+
157203
env:
158204
CARGO_TERM_VERBOSE: true
159-
CARGO_BUILD_TARGET: ${{ inputs.rust-target }}
160205
RUST_BACKTRACE: 1
161206
RUSTFLAGS: "-D warnings"
162207
RUSTDOCFLAGS: "-D warnings"

.github/workflows/ci.yml

Lines changed: 36 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,17 @@ jobs:
225225
python-architecture: "x64",
226226
rust-target: "x86_64-unknown-linux-gnu",
227227
}
228+
# Also test free-threaded Python just for latest Python version, on ubuntu
229+
# (run for all OSes on build-full)
230+
- rust: stable
231+
python-version: "3.13t"
232+
platform:
233+
{
234+
os: "ubuntu-latest",
235+
python-architecture: "x64",
236+
rust-target: "x86_64-unknown-linux-gnu",
237+
}
238+
228239
build-full:
229240
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }}
230241
name: python${{ matrix.python-version }}-${{ matrix.platform.python-architecture }} ${{ matrix.platform.os }} rust-${{ matrix.rust }}
@@ -252,6 +263,7 @@ jobs:
252263
"3.11",
253264
"3.12",
254265
"3.13",
266+
"3.13t",
255267
"pypy3.9",
256268
"pypy3.10",
257269
"pypy3.11",
@@ -460,35 +472,6 @@ jobs:
460472
components: rust-src
461473
- run: cargo rustdoc --lib --no-default-features --features full,jiff-02 -Zunstable-options --config "build.rustdocflags=[\"--cfg\", \"docsrs\"]"
462474

463-
coverage:
464-
if: ${{ github.event_name != 'merge_group' }}
465-
needs: [fmt]
466-
name: coverage ${{ matrix.os }}
467-
strategy:
468-
matrix:
469-
os: ["windows-latest", "macos-latest", "ubuntu-latest"]
470-
runs-on: ${{ matrix.os }}
471-
steps:
472-
- uses: actions/checkout@v4
473-
- uses: actions/setup-python@v5
474-
with:
475-
python-version: "3.13"
476-
- uses: Swatinem/rust-cache@v2
477-
with:
478-
save-if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'CI-save-pr-cache') }}
479-
- uses: dtolnay/rust-toolchain@stable
480-
with:
481-
components: llvm-tools-preview,rust-src
482-
- name: Install cargo-llvm-cov
483-
uses: taiki-e/install-action@cargo-llvm-cov
484-
- run: python -m pip install --upgrade pip && pip install nox
485-
- run: nox -s coverage
486-
- uses: codecov/codecov-action@v5
487-
with:
488-
files: coverage.json
489-
name: ${{ matrix.os }}
490-
token: ${{ secrets.CODECOV_TOKEN }}
491-
492475
emscripten:
493476
name: emscripten
494477
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }}
@@ -575,43 +558,6 @@ jobs:
575558
echo PYO3_CONFIG_FILE=$PYO3_CONFIG_FILE >> $GITHUB_ENV
576559
- run: python3 -m nox -s test
577560

578-
test-free-threaded:
579-
needs: [fmt]
580-
name: Free threaded tests - ${{ matrix.os }}
581-
runs-on: ${{ matrix.os }}
582-
strategy:
583-
matrix:
584-
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
585-
steps:
586-
- uses: actions/checkout@v4
587-
- uses: Swatinem/rust-cache@v2
588-
with:
589-
save-if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'CI-save-pr-cache') }}
590-
- uses: dtolnay/rust-toolchain@stable
591-
with:
592-
components: rust-src
593-
- uses: actions/[email protected]
594-
with:
595-
python-version: "3.13t"
596-
- name: Install cargo-llvm-cov
597-
uses: taiki-e/install-action@cargo-llvm-cov
598-
- run: python3 -m sysconfig
599-
- run: python3 -m pip install --upgrade pip && pip install nox
600-
- name: Prepare coverage environment
601-
run: |
602-
cargo llvm-cov clean --workspace --profraw-only
603-
nox -s set-coverage-env
604-
- run: nox -s ffi-check
605-
- run: nox
606-
- name: Generate coverage report
607-
run: nox -s generate-coverage-report
608-
- name: Upload coverage report
609-
uses: codecov/codecov-action@v5
610-
with:
611-
files: coverage.json
612-
name: ${{ matrix.os }}-test-free-threaded
613-
token: ${{ secrets.CODECOV_TOKEN }}
614-
615561
test-version-limits:
616562
needs: [fmt]
617563
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }}
@@ -758,30 +704,32 @@ jobs:
758704

759705
test-introspection:
760706
needs: [fmt]
707+
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-test-introspection') || contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }}
761708
strategy:
762709
matrix:
763-
platform: [
764-
{
765-
os: "macos-latest",
766-
python-architecture: "arm64",
767-
rust-target: "aarch64-apple-darwin",
768-
},
769-
{
770-
os: "ubuntu-latest",
771-
python-architecture: "x64",
772-
rust-target: "x86_64-unknown-linux-gnu",
773-
},
774-
{
775-
os: "windows-latest",
776-
python-architecture: "x64",
777-
rust-target: "x86_64-pc-windows-msvc",
778-
},
779-
{
780-
os: "windows-latest",
781-
python-architecture: "x86",
782-
rust-target: "i686-pc-windows-msvc",
783-
},
784-
]
710+
platform:
711+
[
712+
{
713+
os: "macos-latest",
714+
python-architecture: "arm64",
715+
rust-target: "aarch64-apple-darwin",
716+
},
717+
{
718+
os: "ubuntu-latest",
719+
python-architecture: "x64",
720+
rust-target: "x86_64-unknown-linux-gnu",
721+
},
722+
{
723+
os: "windows-latest",
724+
python-architecture: "x64",
725+
rust-target: "x86_64-pc-windows-msvc",
726+
},
727+
{
728+
os: "windows-latest",
729+
python-architecture: "x86",
730+
rust-target: "i686-pc-windows-msvc",
731+
},
732+
]
785733
runs-on: ${{ matrix.platform.os }}
786734
steps:
787735
- uses: actions/checkout@v4
@@ -811,10 +759,8 @@ jobs:
811759
- valgrind
812760
- careful
813761
- docsrs
814-
- coverage
815762
- emscripten
816763
- test-debug
817-
- test-free-threaded
818764
- test-version-limits
819765
- check-feature-powerset
820766
- test-cross-compilation
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import nox
2+
import sys
23

34

45
@nox.session
56
def python(session: nox.Session):
7+
if sys.version_info < (3, 9):
8+
session.skip("Python 3.9 or later is required for setuptools-rust 1.11")
69
session.env["SETUPTOOLS_RUST_CARGO_PROFILE"] = "dev"
710
session.install(".[dev]")
811
session.run("pytest")

noxfile.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ def _supported_interpreter_versions(
7272
min_minor = int(min_version.split(".")[1])
7373
max_minor = int(max_version.split(".")[1])
7474
versions = [f"{major}.{minor}" for minor in range(min_minor, max_minor + 1)]
75+
# Add free-threaded builds for 3.13+
76+
if python_impl == "cpython":
77+
versions += [f"{major}.{minor}t" for minor in range(13, max_minor + 1)]
7578
return versions
7679

7780

@@ -725,7 +728,10 @@ def check_feature_powerset(session: nox.Session):
725728

726729
cargo_toml = toml.loads((PYO3_DIR / "Cargo.toml").read_text())
727730

728-
EXPECTED_ABI3_FEATURES = {f"abi3-py3{ver.split('.')[1]}" for ver in PY_VERSIONS}
731+
# free-threaded builds do not support ABI3 (yet)
732+
EXPECTED_ABI3_FEATURES = {
733+
f"abi3-py3{ver.split('.')[1]}" for ver in PY_VERSIONS if not ver.endswith("t")
734+
}
729735

730736
EXCLUDED_FROM_FULL = {
731737
"nightly",

0 commit comments

Comments
 (0)