Skip to content

Run bench-check's tracer as a script, not through PYTHONPATH - #1373

Merged
max-sixty merged 6 commits into
mainfrom
bench-check-tracer
Sep 27, 2026
Merged

max-sixty merged 6 commits into
mainfrom
bench-check-tracer

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

leaf-dev bench-check loaded its tracer by putting a directory holding sitecustomize.py first on the child's PYTHONPATH, so Python imported it at startup. The repository no longer edits an import path, so this was one of the items left in TODO.md. This PR removes it and deletes that TODO line.

The traced child now runs the command bin/leaf runs, uv run -q --no-dev --project <arm> python, with dev/leaf_dev/tracer/traced_leaf.py in place of -m leaf. The script installs the same sys.monitoring hooks, then runs leaf through runpy.run_module("leaf", run_name="__main__", alter_sys=True). argv, the leaf prog name and the exit status therefore match python -m leaf. The trace path and the function table are now arguments to the script; before, they were environment variables. The script sits alone in tracer/: Python puts a script's own directory first on sys.path, so there it shadows nothing, where -m would put the working directory. Only the /bin/sh that bin/leaf execs uv from drops out of the measured wall; the spans and the phase rows are unchanged.

Verified:

  • uv run leaf-dev bench-check ran end to end with the script tracer. Its tables have the same 80 rows as a run with the old sitecustomize.py tracer on this machine, with identical labels in the same order and no - cells, and no check failed.
  • Running the tracer directly: --root exits 0 and writes a trace. An unknown leaf page subcommand exits 2 with leaf's own usage line, and the trace records the cli span.
  • pre-commit passes on the changed files.

This was written by Claude Code on behalf of max-sixty

🤖 Generated with Claude Code

max-sixty and others added 6 commits September 27, 2026 16:04
bench-check traced `leaf page check --render` by putting a directory
holding sitecustomize.py first on the child's PYTHONPATH, so Python
imported it at startup. That is an import-path edit the repository no
longer makes.

The child now runs the command bin/leaf runs, `uv run -q --no-dev
--project ARM python`, with tracer/traced_leaf.py in place of `-m leaf`.
The script installs the same sys.monitoring hooks, takes the trace path
and function table as arguments rather than environment variables, and
runs leaf through runpy as `-m leaf` would, so argv, prog name and exit
status match. The spans and phase rows are unchanged; the wall leaves
out only the /bin/sh that bin/leaf execs uv from.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 0a44a40 into main Sep 27, 2026
5 checks passed
@max-sixty
max-sixty deleted the bench-check-tracer branch September 27, 2026 23:47
max-sixty added a commit that referenced this pull request Sep 28, 2026
…1384)

`scripts/` held what the suite could import only through pytest's
`pythonpath = ["scripts"]`. Each script becomes a `leaf-dev` command in
the module that owns it, the directory is gone, and nothing in the tree
reaches code through `sys.path`, `PYTHONPATH`, `pythonpath` or a file
path any more.

| Was | Now |
|---|---|
| `scripts/preview.py` | `leaf-dev preview` |
| `scripts/corpus.py` | `leaf-dev corpus` |
| `scripts/keydocs.py` | `leaf-dev keydocs` |
| `scripts/verify_site.py` (+ `verify-site-browser.js`) | `leaf-dev
verify-site` |
| `scripts/verify_codex_task.py` | `leaf-dev verify-codex-task` |
| `scripts/deploy-site-dev.sh` | `worker/deploy-dev.sh` (`npm run
deploy:dev`) |

- **Preview's worker.** `leaf-dev preview` execs its worker into the
selected checkout's `--no-dev` environment, overlaid with this
checkout's `leaf_dev` and `watchfiles`. The worker runs `python -m
leaf_dev.preview` rather than the command group, because the group's
other commands import `leaf_website`, which that environment lacks. The
argparse options become click options with the same names, and the
hidden `--_worker` flag becomes `--worker`. Usage errors still exit 2,
and a failed `leaf` call still exits with that call's own status.
- **Callers.** CI, `publish-site` (its run lines and path filters), the
eslint override, the Worker's npm script, and the tests all use the new
names. The suite imports `from leaf_dev import preview, verify_site,
corpus, keydocs`, and runs the preview as `python -m leaf_dev preview`.
- **Guidance.** `scripts/AGENTS.md` folds into `dev/AGENTS.md`, which
now states the rule against import-path edits. The `AGENTS.md`
repository map, `/developing-leaf` and the other docs name the commands.
- **Tests that faked a stale install.** Two tests put an older `leaf`
first on `PYTHONPATH` to stand in for a stale plugin install: the
`--version`/`--root` test and the re-vendor restart test. Each now
installs the payload (`install_payload`) and runs that install's own
`bin/leaf`, as a host does. Their assertions are unchanged.
- **Regenerated files.** `examples/corpus.html` and `docs/registry.html`
each change one line, the generator name in their header comment.

`TODO.md`'s "Repository tooling" item is done, so it is removed.
`leaf-dev bench-check` already stopped using `PYTHONPATH` in #1373.

**Checks:**

- `leaf-dev --help` lists the five new commands.
- `leaf-dev preview triage-board --export` writes the page. `leaf-dev
corpus` reproduces the committed corpus.
- pytest passed 153 of 153 on `test_interact_preview`,
`test_interact_product`, `test_website_server`, and the two rewritten
tests.
- pre-commit passes on every changed file.
- The nightly `test_render_export` tests that wait for a watched edit
fail locally. They fail on this machine regardless of the change: plain
`watchfiles.watch` on a fresh temp directory reports no edit at all
right now, at a load average above 40. Four of them, run alone on the
merge base (2553559), fail the same way. CI's run is the reading for
those tests.

> _This was written by Claude Code on behalf of max-sixty_

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants