Skip to content

Commit 1a2955a

Browse files
satraclaude
andauthored
Add scalene profiling wrapper as opt-in dependency group (#507)
* Add scalene profiling wrapper as opt-in dependency group Adds scripts/profile_with_scalene.py: a thin CLI wrapper around Scalene 2.2's `run` and `view` subcommands. Accepts .py or .ipynb targets, auto-converts notebooks via nbconvert (with an injected IPython stub so magic calls survive the conversion), and writes self-contained HTML or JSON reports under artifacts/scalene/. Scalene + nbconvert live in a new [dependency-groups.profiling] entry in pyproject.toml, so default `uv sync` is unaffected — production installs do not pay the profiler's cost. To use: uv sync --group profiling uv run python scripts/profile_with_scalene.py path/to/script.py uv run python scripts/profile_with_scalene.py tutorials/audio/x.ipynb Tests in src/tests/scripts/profile_with_scalene_test.py are guarded by @pytest.mark.skipif(not scalene_available), so they silently skip on the default install path and the existing CI suite is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Inject IPython stub after __future__ imports in converted notebooks Notebooks containing `from __future__ import annotations` (or any other __future__ import) failed to profile because the IPython stub was prepended to the converted .py, pushing the __future__ imports past line 1 and triggering a SyntaxError. Fix: walk the converted source for `from __future__` lines and insert the stub after the last one. When no future imports are present, the stub still goes at the very top. Adds a regression test using a synthetic notebook whose first cell line is `from __future__ import annotations`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c1b21c4 commit 1a2955a

5 files changed

Lines changed: 667 additions & 0 deletions

File tree

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ dev = [
108108
docs = [
109109
"pdoc~=16.0"
110110
]
111+
profiling = [
112+
"scalene>=2.2",
113+
"nbconvert>=7"
114+
]
111115

112116
[tool.hatch.build.targets.wheel]
113117
packages = ["src/senselab"]

0 commit comments

Comments
 (0)