Skip to content

Commit 9b8fbaa

Browse files
committed
WS2
1 parent a6d2403 commit 9b8fbaa

File tree

5 files changed

+103
-317
lines changed

5 files changed

+103
-317
lines changed

Justfile

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ coverage-python:
6767

6868
# Build the module in release mode
6969
build:
70-
just venv \
71-
uv run --directory codetracer-python-recorder maturin build --release
70+
just venv
71+
uv run --directory codetracer-python-recorder maturin build --release --sdist
7272

7373
# Build wheels for all target Python versions with maturin
7474
build-all:
7575
just venv
76-
uv run --directory codetracer-python-recorder maturin build --release --interpreter {{PY_VERSIONS}}
76+
uv run --directory codetracer-python-recorder maturin build --release --sdist --interpreter {{PY_VERSIONS}}
7777

7878
# Smoke the built Rust wheels across versions using uv
7979
test-all:
@@ -82,3 +82,18 @@ test-all:
8282
file="${file[0]}"; \
8383
uv run -p "python3.$v" --with "${file}" --with pytest -- pytest -q; \
8484
done
85+
86+
# Install a freshly built artifact and run a CLI smoke test
87+
smoke-wheel artifact="wheel" interpreter=".venv/bin/python":
88+
just build
89+
VENV_DIR="$(mktemp -d)"; \
90+
trap 'rm -rf "$VENV_DIR"' EXIT; \
91+
"{{interpreter}}" -m venv "$VENV_DIR"; \
92+
VENV_PY="$VENV_DIR/bin/python"; \
93+
if [ ! -x "$VENV_PY" ]; then \
94+
VENV_PY="$VENV_DIR/Scripts/python.exe"; \
95+
fi; \
96+
"$VENV_PY" -m pip install --upgrade pip; \
97+
FILE="$("$VENV_PY" scripts/select_recorder_artifact.py --wheel-dir codetracer-python-recorder/target/wheels --mode "{{artifact}}")"; \
98+
"$VENV_PY" -m pip install "$FILE"; \
99+
"$VENV_PY" -m codetracer_python_recorder --help >/dev/null

codetracer-python-recorder/tests/python/test_codetracer_api.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ def test_context_manager(self) -> None:
3333
self.assertIsInstance(session, codetracer.TraceSession)
3434
self.assertFalse(codetracer.is_tracing())
3535

36+
def test_start_emits_trace_files(self) -> None:
37+
with tempfile.TemporaryDirectory() as tmpdir:
38+
trace_dir = Path(tmpdir)
39+
codetracer.start(trace_dir)
40+
# Execute a small workload to ensure callbacks fire.
41+
def _workload() -> int:
42+
return sum(range(5))
43+
44+
self.assertEqual(_workload(), 10)
45+
codetracer.stop()
46+
47+
metadata = trace_dir / "trace_metadata.json"
48+
paths = trace_dir / "trace_paths.json"
49+
self.assertTrue(metadata.exists(), "expected trace_metadata.json to be created")
50+
self.assertTrue(paths.exists(), "expected trace_paths.json to be created")
51+
3652
def test_environment_auto_start(self) -> None:
3753
script = "import codetracer_python_recorder as codetracer, sys; sys.stdout.write(str(codetracer.is_tracing()))"
3854
with tempfile.TemporaryDirectory() as tmpdir:

design-docs/codetracer-python-recorder-pypi-release-implementation-plan.status.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
- ✅ Introduced `scripts/check_recorder_version.py` and wired it into CI to enforce version parity.
77
- ✅ Documented supported environments in `codetracer-python-recorder/README.md` and added a release checklist under `design-docs/`.
88

9+
## Workstream 2 – Build & test enhancements
10+
- ✅ Updated `Justfile` build targets to emit wheels and sdists and added a `smoke-wheel` recipe that installs artefacts via an isolated venv.
11+
- ✅ Added `scripts/select_recorder_artifact.py` to choose interpreter-compatible wheels and wired the smoke test to use it.
12+
- ✅ Expanded the Python API tests to cover end-to-end tracing via `start`/`stop` (`test_start_emits_trace_files`).
13+
- ✅ Verified `just py-test` passes with the new coverage.
14+
915
## Next Tasks
10-
- Begin Workstream 2: enhance build/test automation (extend Just recipes, add smoke install target, ensure integration coverage).
11-
- Draft changes to the release workflow (`recorder-release.yml`) once Workstream 2 groundwork is ready.
16+
- Kick off Workstream 3: design the cross-platform release workflow (`recorder-release.yml`) and wire in TestPyPI publishing.
17+
- Add release-pipeline steps to invoke the new smoke install target once the workflow skeleton exists.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
"""Select the appropriate recorder build artifact for a given interpreter."""
3+
4+
from __future__ import annotations
5+
6+
import argparse
7+
import sys
8+
from pathlib import Path
9+
10+
11+
def parse_args() -> argparse.Namespace:
12+
parser = argparse.ArgumentParser(description=__doc__)
13+
parser.add_argument(
14+
"--wheel-dir",
15+
type=Path,
16+
required=True,
17+
help="Directory containing maturin build outputs (wheels and/or sdists).",
18+
)
19+
parser.add_argument(
20+
"--mode",
21+
choices=("wheel", "sdist"),
22+
default="wheel",
23+
help="Prefer a wheel for the current interpreter or fallback to the source distribution.",
24+
)
25+
return parser.parse_args()
26+
27+
28+
def choose_artifact(wheel_dir: Path, mode: str) -> Path:
29+
candidates = []
30+
if mode == "wheel":
31+
abi = f"cp{sys.version_info.major}{sys.version_info.minor}"
32+
pattern = f"codetracer_python_recorder-*-{abi}-{abi}-*.whl"
33+
candidates = sorted(wheel_dir.glob(pattern))
34+
if not candidates:
35+
candidates = sorted(wheel_dir.glob("codetracer_python_recorder-*.tar.gz"))
36+
if not candidates:
37+
raise FileNotFoundError(f"No build artefacts found in {wheel_dir}")
38+
return candidates[-1]
39+
40+
41+
def main() -> int:
42+
args = parse_args()
43+
artifact = choose_artifact(args.wheel_dir, args.mode)
44+
sys.stdout.write(str(artifact))
45+
return 0
46+
47+
48+
if __name__ == "__main__":
49+
raise SystemExit(main())

0 commit comments

Comments
 (0)