Repository navigation
Give code cells the Quarto 1 execute environment (QUARTO_EXECUTE_INFO and friends) - #1161
Conversation
…O for code cells (bd-8fmuyh4d) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code cells now see QUARTO_PROJECT_ROOT, QUARTO_DOCUMENT_PATH,
QUARTO_DOCUMENT_FILE, QUARTO_EXECUTE_INFO and QUARTO_FIG_*, as in
Quarto 1. q2 never mutates its own process environment: the values are
computed once per document in EngineExecutionStage and delivered per
engine.
- engine/execute_info.rs: a port of Q1's metadataAsFormat into the
six-bin format (key lists tested against ts-packages/quarto-api), the
`language` bin from the resolved quarto.language table, execute
visibility and figure defaults, and format.render.brand.{light,dark}.
- The JSON file is written into the document's temp dir only when code
runs. QUARTO_PERF_STATS=1 prints a perf.execute-info gauge.
- knitr: Command::envs on the per-document R process.
- Jupyter: kernels are shared across a project's documents, so a silent
setup request sets the values inside the kernel (Python, R, Julia)
before the document's first cell.
- quarto-sass: resolve_brand_modes returns the dark half only when the
brand defines dark values.
- Docs: guides/authoring/execution-context.qmd.
Measured: 6.4 KB / 0.24 ms on claude-notes, 19.4 KB / 0.35 ms on docs
(mostly the website sidebar config). Details in
claude-notes/plans/2026-11-10-execute-environment.md.
No snapshot files changed.
Found while implementing: bd-i7yz08uh (parallel renders interleave
cells across documents on a shared kernel), bd-08hfh3ut (project brand
path resolves against the document dir after engine execution),
bd-x3h4zjhl (TS engines follow-up).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
We're going to merge this to increase Quarto 1 compatibility, but I'll note for the record that this is a feature we probably will deprecate in the future (we want to minimize our dependence on filesystems for access to information because of a variety of reasons). |
FWIW, I might be the only one using that feature at the moment, mostly to gain access to metadata otherwise not available to code cells / engines, e.g., brand.yml and project options. edit: it seems plotnine (Python), flextable (R) are using it. |
Closes #1131.
Code cells now see the environment Quarto 1 gives them:
QUARTO_PROJECT_ROOT,QUARTO_DOCUMENT_PATH,QUARTO_DOCUMENT_FILEQUARTO_EXECUTE_INFO: path to a JSON file withdocument-pathand the resolved six-binformat(identifier,execute,render,pandoc,language,metadata), includingformat.render.brand.{light,dark}QUARTO_FIG_WIDTH,QUARTO_FIG_HEIGHT,QUARTO_FIG_DPI,QUARTO_FIG_FORMATDesign
q2 never mutates its own process environment. The values are computed once per document in
EngineExecutionStage(ExecutionContext.execute_env) and each engine delivers them:Command::envson the per-document R process.execute_request(store_history: false,silent: true) sets them inside the kernel before the document's first cell, for Python, R and Julia kernels. This is how Quarto 1 already setsQUARTO_FIG_*.engine/execute_info.rsports Q1'smetadataAsFormat. Its key lists are tested againstts-packages/quarto-api/src/config/index.ts, so the file and the Node engine host can't drift apart.quarto-sassgainsresolve_brand_modes, which returns the dark half only when the brand defines dark values.Cost
Measured with the new
QUARTO_PERF_STATS=1gauge (perf.execute-info), debug build:claude-noteswebsitedocswebsiteThe cost is per document that executes code, small next to starting an engine. Most of the
docssize is the website sidebar config, which Quarto 1 includes too.Differences from Quarto 1
These are listed in the new docs page
docs/guides/authoring/execution-context.qmd:brand.darkis present whenever the brand defines dark values.dataandbrandDir, not Q1's whole internalBrandobject.QUARTO_FIG_*report q2's figure defaults (png, 96 dpi), not Q1's HTMLretina.juliaandmarimoengines don't receive the variables yet (bd-x3h4zjhl).Tests
engine/execute_info.rs: partition, key-list parity, fig env, paths, brand, per-language setup code with escaping.quarto-sassbrand-mode tests.execute_env_cli_e2e: drivesq2 renderwith a knitr document in a subdirectory with a light/dark brand, and two Jupyter documents on one shared kernel, each seeing its own document. Skips without R+knitr or apython3kernel.cargo nextest run -p quarto-core -p quarto-sass -p quarto-brand -p quarto: 9,152 of 9,153 pass. The one failure iscapture_classifies_pieces, which also fails onmainwith newer rlang (bd-54odm3rz).-D warnings,cargo xtask lint, andnpm run build:wasmpass.No snapshot files changed.
Found along the way (separate strands, not fixed here)
QUARTO_JOBS=2. The new Jupyter test runs withQUARTO_JOBS=1until it is fixed.brand:resolves against the document directory once code runs, for a document in a subdirectory. This is pre-existing onmain.Triage record:
claude-notes/issue-reports/1131/triage.md. Plan and measurements:claude-notes/plans/2026-11-10-execute-environment.md.🤖 Generated with Claude Code