Skip to content

Commit a55ff1f

Browse files
committed
build: Support testing multiple Python versions in CI and locally
.github/workflows/ci.yml: .gitignore: Justfile: crates/codetracer-python-recorder/test/smoke.py: crates/codetracer-python-recorder/test/test_smoke.py: crates/codetracer-python-recorder/uv.lock: flake.lock: flake.nix: uv.lock: Signed-off-by: Tzanko Matev <[email protected]>
1 parent 5ced5c3 commit a55ff1f

File tree

9 files changed

+85
-23
lines changed

9 files changed

+85
-23
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,55 @@ on:
88

99
jobs:
1010
tests:
11-
name: Tests on ${{ matrix.os }}
11+
name: Tests on ${{ matrix.os }} (Python ${{ matrix.python-version }})
1212
runs-on: ${{ matrix.os }}
1313
strategy:
1414
matrix:
1515
os: [ubuntu-latest, macos-latest, windows-latest]
16+
python-version: ["3.10", "3.11", "3.12", "3.13"]
1617
steps:
1718
- uses: actions/checkout@v4
18-
- uses: actions/setup-python@v5
19-
with:
20-
python-version: '3.x'
19+
- uses: astral-sh/setup-uv@v4
20+
- name: Install Python via uv
21+
shell: bash
22+
run: uv python install ${{ matrix.python-version }}
2123
- name: Run tests
2224
shell: bash
23-
run: python -m unittest discover -v
25+
run: uv run -p ${{ matrix.python-version }} -m unittest discover -v
2426

2527
nix-tests:
2628
runs-on: ubuntu-latest
2729
steps:
2830
- uses: actions/checkout@v4
2931
- uses: cachix/install-nix-action@v27
3032
with:
31-
nix_path: nixpkgs=channel:nixos-24.05
33+
nix_path: nixpkgs=channel:nixos-25.05
3234
extra_nix_config: |
3335
experimental-features = nix-command flakes
3436
- name: Run tests via Nix
3537
run: nix develop --command just test
3638

3739
rust-smoke:
38-
name: Rust module smoke test on ${{ matrix.os }}
40+
name: Rust module smoke test on ${{ matrix.os }} (Python ${{ matrix.python-version }})
3941
runs-on: ${{ matrix.os }}
4042
strategy:
4143
matrix:
4244
os: [ubuntu-latest, macos-latest, windows-latest]
45+
python-version: ["10", "11", "12", "13"]
4346
steps:
4447
- uses: actions/checkout@v4
4548
- uses: actions/setup-python@v5
4649
with:
47-
python-version: '3.x'
50+
python-version: 3.${{ matrix.python-version }}
51+
- uses: astral-sh/setup-uv@v4
4852
- uses: messense/maturin-action@v1
4953
with:
5054
command: build
51-
args: -m crates/codetracer-python-recorder/Cargo.toml --release
52-
- name: Install built wheel
53-
shell: bash
54-
run: python -m pip install --upgrade pip && python -m pip install crates/codetracer-python-recorder/target/wheels/*.whl
55-
- name: Import smoke test
55+
args: --interpreter python3.${{ matrix.python-version }} -m crates/codetracer-python-recorder/Cargo.toml --release
56+
- name: Install and smoke test built wheel with uv (pytest)
5657
shell: bash
57-
run: python -c "import codetracer_python_recorder as m; print(m.hello())"
58+
run: |
59+
v={{matrix.python-version}}
60+
file=(crates/codetracer-python-recorder/target/wheels/codetracer_python_recorder_*_cp3$v-cp3$v-*.whl)
61+
file="${file[0]}"
62+
uv run -p python3.$v --with "${file}" --with pytest -- python -m pytest crates/codetracer-python-recorder/test -q

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
**/__pycache__/
33
.aider*
44
.venv/
5-
**/target/
5+
**/target/
6+
build

Justfile

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Development helpers for the monorepo
22

3+
# Python versions used for multi-version testing/building with uv
4+
PY_VERSIONS := "3.10 3.11 3.12 3.13"
5+
PY_SHORT_VERSIONS := "10 11 12 13"
36
# Print toolchain versions to verify the dev environment
47
env:
58
python3 --version
@@ -10,7 +13,6 @@ env:
1013
# Create a local virtualenv for Python tooling
1114
venv:
1215
test -d .venv || python3 -m venv .venv
13-
.venv/bin/python -m pip install -U pip
1416

1517
# Build and develop-install the Rust-backed Python module
1618
build-rust:
@@ -19,8 +21,28 @@ build-rust:
1921

2022
# Smoke test the Rust module after build
2123
smoke-rust:
22-
.venv/bin/python -c "import codetracer_python_recorder as m; print(m.hello())"
24+
.venv/bin/python -m pip install -U pip pytest
25+
.venv/bin/python -m pytest crates/codetracer-python-recorder/test -q
2326

2427
# Run the Python test suite for the pure-Python recorder
2528
test:
2629
python3 -m unittest discover -v
30+
31+
# Run the test suite across multiple Python versions using uv
32+
test-uv-all:
33+
uv python install {{PY_VERSIONS}}
34+
for v in {{PY_VERSIONS}}; do uv run -p "$v" -m unittest discover -v; done
35+
36+
# Build wheels for all target Python versions with maturin
37+
build-rust-uv-all:
38+
for v in {{PY_VERSIONS}}; do \
39+
maturin build --interpreter "python$v" -m crates/codetracer-python-recorder/Cargo.toml --release; \
40+
done
41+
42+
# Smoke the built Rust wheels across versions using uv
43+
smoke-rust-uv-all:
44+
for v in {{PY_SHORT_VERSIONS}}; do \
45+
file=(crates/codetracer-python-recorder/target/wheels/codetracer_python_recorder-*-cp3$v-cp3$v-*.whl); \
46+
file="${file[0]}"; \
47+
uv run -p "python3.$v" --with "${file}" --with pytest -- python -m pytest crates/codetracer-python-recorder/test -q; \
48+
done
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""Smoke test for codetracer_python_recorder wheel."""
2+
3+
def main() -> None:
4+
import codetracer_python_recorder as m
5+
print(m.hello())
6+
7+
if __name__ == "__main__":
8+
main()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import codetracer_python_recorder as m
2+
3+
4+
def test_hello_returns_expected_string() -> None:
5+
assert m.hello() == "Hello from codetracer-python-recorder (Rust)"

crates/codetracer-python-recorder/uv.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
description = "Development environment for CodeTracer recorders (pure-python and rust-backed)";
33

4-
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
55

66
outputs = { self, nixpkgs }:
77
let
@@ -14,14 +14,18 @@
1414
default = pkgs.mkShell {
1515
packages = with pkgs; [
1616
bashInteractive
17-
python3
17+
python310
18+
python311
19+
python312
20+
python313
1821
just
1922
git-lfs
2023

2124
# Linters and type checkers for Python code
2225
ruff
2326
black
2427
mypy
28+
python3Packages.pytest
2529

2630
# Rust toolchain for the Rust-backed Python module
2731
cargo
@@ -31,6 +35,7 @@
3135

3236
# Build tooling for Python extensions
3337
maturin
38+
uv
3439
pkg-config
3540
];
3641
};

uv.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)