Centralize uv and PEP 723 operations - #10695
Open
manzt wants to merge 3 commits into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
dmadisetti
self-requested a review
August 31, 2026 20:11
marimo shells out to uv from several modules, each with its own
subprocess idiom, availability check, and stderr handling. Failures
either escape as bare CalledProcessError or are silently swallowed.
These changes add `marimo._environments.uv` as the single way to invoke
uv with captured output. A nonzero exit raises a typed error,
classified once from stderr, that callers recover on.
```py
try:
uv(["export", "--script", name])
except UvMissingScriptMetadataError:
... # script has no PEP 723 block yet
```
Streaming package installs keep their existing path.
marimo writes script metadata blocks in several different code paths with separate serialization strategies. - `uv add --script` edits it in the package manager - `tomlkit` re-serialization edits it in scripts.py - regex splices that serialization entirely These changes add `marimo._environments.script_metadata` as the single reader and writer. In-place edits of a user file delegate to uv so formatting survives, while whole-block generation for converters, codegen, and export serializes with tomlkit, so the lossy fallback is gone. ```py script_metadata.add_dependencies(path, ["numpy"]) script_metadata.ensure_marimo(path) project = script_metadata.loads(code) code = script_metadata.replace_block(code, script_metadata.dumps(project)) ``` Metadata edit verbs normalize missing-tool, command, timeout, and filesystem failures as `ScriptMetadataError`. Callers such as the package manager can therefore preserve their boolean failure contract without knowing how uv was invoked. Markdown and qmd notebooks round-trip their frontmatter header verbatim through a carrier, a hidden sidecar next to the notebook (`.marimo-v1-<name>.py`), so uv anchors relative paths in the metadata against the notebook's directory. The versioned, deterministic name marks the file as marimo's; a carrier exists only while uv runs, and every edit first sweeps strays a killed process may have left. The document is only rewritten when the edit succeeds. `PyProjectReader` remains the read-only view over the parsed block.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
marimo invoked uv and edited PEP 723 metadata from several code paths. CLI sandboxing, exports, converters, file management, and package installation each carried part of that logic, so working directories, error handling, and serialization could drift.
This PR gives those operations two owners:
marimo._environments.uvowns executable discovery, invocation, and errors.marimo._environments.script_metadataowns reading and writing PEP 723 blocks. Existing callers now use these modules instead of constructing subprocess commands or rewriting metadata themselves.For Markdown and Quarto notebooks, metadata edits use a short-lived Python carrier beside the notebook. This lets uv resolve relative paths and directory configuration from the notebook directory while preserving the surrounding document.
This PR does not change how sandbox processes are launched. It establishes the command and metadata operations used by the rest of the stack.