Add json output to uv tool list#20516
Conversation
a108269 to
2d8a5c6
Compare
2d8a5c6 to
ac78cfa
Compare
| path: PathBuf, | ||
| commands: Vec<CommandPrintData>, | ||
| extras: Vec<String>, | ||
| version_specifiers: String, |
There was a problem hiding this comment.
Should this be an Option that's None when there aren't any version specifiers to get null instead of an empty string in the JSON data?
| // XXX I don't think we'll ever have more than 1 element here, since multiple | ||
| // specifiers like in 'twine[keyring]>=6.2.0,!=69' are all in the same string | ||
| .join(", "), |
There was a problem hiding this comment.
I kept this because it's used in the existing text output code. I could not find any case where we'd get multiple items here, because we only have one requirement as input here, and source.to_string already produces a single string.
| } | ||
|
|
||
| #[derive(Debug, Serialize)] | ||
| struct PythonPrintData { |
There was a problem hiding this comment.
I limited this to useful data like in the text output but included the key to allow matching it with data from uv python list
Merging this PR will improve performance by 5.03%
Performance Changes
Tip Curious why this is faster? Use the CodSpeed MCP and ask your agent. Comparing Footnotes
|
29b80a2 to
2b9efca
Compare
| "name": "flask", | ||
| "version": "3.0.2", | ||
| "latest_version": null, | ||
| "path": "[TEMP_DIR]/tools/flask", |
There was a problem hiding this comment.
This fails on windows, not sure where this slash nonsense is coming from, so no idea how to fix it (besides not running these tests on windows which is probably not a good idea)...
13 │- "path": "[TEMP_DIR]/tools/flask",
13 │+ "path": "D:\/uv-tmp\/uv\/tests\/[TMP]/flask",
| "python": { | ||
| "implementation": "cpython", | ||
| "version": "3.12.[X]", | ||
| "key": "cpython-3.12.[X]-linux-x86_64-gnu" |
There was a problem hiding this comment.
Of course this also fails on Windows, because it has -windows- instead of -linux- in the key...
No tests etc yet until the JSON format etc is fine.Added tests after it turned out to be trivial, snapshot tests FTW! :)Sample output:
without
--outdated:Details
{ "schema": { "version": "preview" }, "tools": [ { "name": "httpie", "version": "3.2.3", "latest_version": null, "path": "/home/adrian/.local/share/uv/tools/httpie", "commands": [ { "name": "http", "path": "/home/adrian/.local/bin/http" }, { "name": "httpie", "path": "/home/adrian/.local/bin/httpie" }, { "name": "https", "path": "/home/adrian/.local/bin/https" } ], "extras": [], "version_specifiers": "", "with": [], "python": { "implementation": "cpython", "version": "3.12.2", "key": "cpython-3.12.2-linux-x86_64-gnu" } }, { "name": "twine", "version": "6.2.0", "latest_version": null, "path": "/home/adrian/.local/share/uv/tools/twine", "commands": [ { "name": "twine", "path": "/home/adrian/.local/bin/twine" } ], "extras": [ "keyring" ], "version_specifiers": ">=6.2.0, !=69", "with": [ "markupsafe!=69", "werkzeug" ], "python": { "implementation": "cpython", "version": "3.13.3", "key": "cpython-3.13.3-linux-x86_64-gnu" } }, ] }with
--outdated:Details
{ "schema": { "version": "preview" }, "tools": [ { "name": "httpie", "version": "3.2.3", "latest_version": "3.2.4", "path": "/home/adrian/.local/share/uv/tools/httpie", "commands": [ { "name": "http", "path": "/home/adrian/.local/bin/http" }, { "name": "httpie", "path": "/home/adrian/.local/bin/httpie" }, { "name": "https", "path": "/home/adrian/.local/bin/https" } ], "extras": [], "version_specifiers": "", "with": [], "python": { "implementation": "cpython", "version": "3.12.2", "key": "cpython-3.13.2-linux-x86_64-gnu" } } ] }closes #10219