Commit 1a2955a
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
- scripts
- src/tests/scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
111 | 115 | | |
112 | 116 | | |
113 | 117 | | |
| |||
0 commit comments