Skip to content

Conversation

@x0rw
Copy link
Contributor

@x0rw x0rw commented Mar 23, 2025

UPDATE:

Summary

This PR adds support for the --format=json flag to the uv sync --dry-run command. When enabled, the command outputs details in JSON format, making it easier to parse and integrate with other tools.

the dry run output json includes:

  • Project directory.
  • Environment path & action taken(Create/Update/None).
  • Python executable path.
  • Python version.
  • Lockfile path & action.
  • Packages (would install/download/remove).

The Json output is currently pretty-printed for readability.

Test Plan

Manual testing has been performed to verify JSON output.

--script

cargo run sync --dry-run --script foo.py --format=json
output:

{
  "project_dir": "/home/root/rust/uv/uv",
  "environment": {
    "path": "/home/root/.cache/uv/environments-v2/foo-bc19cb0acffe1e16",
    "action": "already_exist",
    "python_executable": "/home/root/.cache/uv/environments-v2/foo-bc19cb0acffe1e16/bin/python3",
    "python_version": "3.13.0"
  },
  "lockfile": null
}

--project

cargo run sync --dry-run --project test_dir --format=json
output:

{
  "project_dir": "/home/root/rust/uv/uv/test_dir",
  "environment": {
    "path": "/home/root/rust/uv/uv/test_dir/.venv",
    "action": "already_exist",
    "python_executable": "/home/root/rust/uv/uv/test_dir/.venv/bin/python3",
    "python_version": "3.13.0"
  },
  "lockfile": {
    "lockfile_path": "/home/root/rust/uv/uv/test_dir/uv.lock",
    "action": "create"
  }
}

Note: 2>/dev/null can be appended to the end of the command to redirect stderr away and show only the stdout(which contains the json only).
Related Issue
Resolves #12387.

@x0rw x0rw marked this pull request as draft March 23, 2025 23:21
@x0rw
Copy link
Contributor Author

x0rw commented Mar 25, 2025

I can't fix the failling test for windows atm, the issue arises from filtering directories on windows in the test(sync_dry_run_format), a custom filter or writing another test for windows will solve it

@x0rw x0rw marked this pull request as ready for review March 26, 2025 01:30
@x0rw
Copy link
Contributor Author

x0rw commented Apr 9, 2025

Hey @zanieb , this PR is almost complete, with just a small part left to finish. Could you please review it? If a rebase is needed, let me know.

@Gankra Gankra requested review from Gankra and removed request for InSyncWithFoo April 14, 2025 19:40
@Gankra
Copy link
Contributor

Gankra commented May 27, 2025

I've rebased and continued this impl over here:

zanieb added a commit that referenced this pull request Jul 14, 2025
This is a continuation of the work in 

* #12405 

I have:
* moved to an architecture where the human output is derived from the
json structs to centralize more of the printing state/logic
* cleaned up some of the names/types
* added tests
* removed the restriction that this output is --dry-run only

I have not yet added package info, which was TBD in their design.

---------

Co-authored-by: x0rw <[email protected]>
Co-authored-by: Zanie Blue <[email protected]>
Co-authored-by: John Mumm <[email protected]>
@zanieb
Copy link
Member

zanieb commented Jul 14, 2025

Added in #13689

@zanieb zanieb closed this Jul 14, 2025
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.

Support uv sync [--dry-run] --format=json

4 participants