Add JSON output for uv tree - #19904
Closed
charliermarsh wants to merge 3 commits into
Closed
Conversation
uv test inventory changesThis PR changes the tests when compared with the latest
|
zanieb
reviewed
Jun 18, 2026
|
|
||
| /// The format in which to display the dependency graph. | ||
| #[arg(long, value_enum, default_value_t = TreeFormat::default())] | ||
| pub format: TreeFormat, |
zanieb
reviewed
Jun 18, 2026
| }, | ||
| "roots": [ | ||
| { | ||
| "id": 3 |
Member
There was a problem hiding this comment.
I think we'd want to use the ids from uv workspace metadata? cc @Gankra on this pull request you're probably the best reviewer?
zanieb
reviewed
Jun 18, 2026
Comment on lines
+116
to
+118
| "schema": { | ||
| "version": "preview" | ||
| }, |
Member
There was a problem hiding this comment.
Why is the schema version nested inside the graph key?
zanieb
reviewed
Jun 18, 2026
Comment on lines
+881
to
+892
| #[derive(Debug, Serialize)] | ||
| struct JsonNode<'env> { | ||
| id: usize, | ||
| name: &'env PackageName, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| version: Option<&'env Version>, | ||
| source: JsonSource, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| latest_version: Option<&'env Version>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| size_bytes: Option<u64>, | ||
| } |
Member
There was a problem hiding this comment.
Similarly to my other comment, I think we'll want to be consistent with uv workspace metadata in some way for the structure of the nodes
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.
Summary
This adds
--format jsontouv tree, providing a machine-readable representation of the selected dependency graph while preserving the existing text format by default.The output follows the NetworkX node-link format: packages appear once in
nodes, while dependency relationships appear separately inedgesand refer to package IDs throughsourceandtarget. The graph is directed and a multigraph, allowing the same package pair to retain distinct production, optional-extra, and dependency-group relationships.{ "directed": true, "multigraph": true, "graph": { "schema": { "version": "preview" }, "roots": [{ "id": 0 }], "inverted": false }, "nodes": [ { "id": 0, "name": "example", "version": "0.1.0", "source": { "editable": "." } }, { "id": 1, "name": "anyio", "version": "4.9.0", "source": { "registry": "https://pypi.org/simple" } } ], "edges": [ { "source": 0, "target": 1, "key": 0, "kind": "production", "requested_extras": [] } ] }Node IDs are deterministic within the document. Package nodes include normalized names, versions, and tagged source metadata, with
latest_versionandsize_byteswhen requested. Edges distinguishproduction,optional, anddevelopmentdependencies and retain activating extras, dependency groups, and requested extras. Thegraphmetadata records the preview schema version, the displayed roots, and whether the graph was inverted.The JSON projection operates on the same dependency graph as the text tree and supports its filtering and display options, including depth limits and inversion. Depth traversal tracks each package together with its expanded extras so an extra-only descendant is emitted only when its activating path is within the requested depth. JSON also remains available under
--quiet, allowing resolution progress to be suppressed without discarding the command result.