Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include a method to create machine readable output #3199

Open
pfmoore opened this issue Apr 22, 2024 · 3 comments
Open

Include a method to create machine readable output #3199

pfmoore opened this issue Apr 22, 2024 · 3 comments
Labels
cli Related to the command line interface

Comments

@pfmoore
Copy link
Contributor

pfmoore commented Apr 22, 2024

When automating uv, having to parse the command output (which is intended for human readability) is not ideal. It would be useful to have an option to produce machine readable (probably JSON) output from the various uv commands.

  • For uv pip install something along the lines of the pip installation report would probably be a reasonable format.
  • For uv pip list, the pip list --format=json command is probably a good model.
  • uv pip show and uv pip freeze are machine readable, although having a --format=json equivalent for consistency might be worthwhile.
  • uv pip check probably doesn't need an output option, assuming the exit code is success or failure as appropriate.
  • uv pip compile and uv pip sync can probably have an installation report similar to uv pip install. I've not used these myself, though, so I don't know how useful they would be in practice.
  • uv venv could produce JSON output showing details of the created environment - path to the environment, Python executable path, scripts and site-package directories. Basically, the values that the stdlib venv module captures in the "context" object documented here.

To make automation easier, it's probably worth having some additional command line capabilities:

  • An isolated mode, to prevent user config affecting results (uv doesn't have as many possibilities for problems here as pip does, but that may change, I guess...)
  • A "guaranteed quiet" mode that ensures that just the JSON data will be printed to stdout, with any user messages either going to stderr or being suppressed. (Writing the data to a file is another possibility, but IMO it tends to be clumsy to manage).
  • I assume uv always writes its output as UTF-8, but if it doesn't (for example it follows the system defined encoding) then a "guaranteed UTF-8 output" mode would be important to avoid encoding problems.
@zanieb zanieb added the cli Related to the command line interface label Apr 22, 2024
@ChannyClaus
Copy link
Contributor

should we note in the description that uv pip list --format json already exists? https://github.com/astral-sh/uv/blob/main/crates/uv/src/commands/pip_list.rs#L115

$ python -m uv pip list --format json | jq .
[
  {
    "name": "certifi",
    "version": "2024.2.2"
  },
  {
    "name": "charset-normalizer",
    "version": "3.3.2"
  },
  {
    "name": "idna",
    "version": "3.6"
  },
  {
    "name": "requests",
    "version": "2.31.0"
  },
  {
    "name": "urllib3",
    "version": "2.2.1"
  }
]

@pfmoore
Copy link
Contributor Author

pfmoore commented Apr 24, 2024

Thanks, I’d missed that.

@sfc-gh-jcarroll
Copy link

We also need it for equivalent of --dry-run without doing the install.

Related:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to the command line interface
Projects
None yet
Development

No branches or pull requests

4 participants