astral-sh / uv

An extremely fast Python package installer and resolver, written in Rust.
https://astral.sh/
Apache License 2.0
14.72k stars 419 forks source link

`uv pip tree` machine readable output #4711

Open ibraheemdev opened 6 days ago

ibraheemdev commented 6 days ago

e.g. JSON with -j. This is useful for interacting with graph tools such as mermaid.

zanieb commented 6 days ago

I think we should probably use --format json for consistency with other interfaces?

zanieb commented 6 days ago

See also https://github.com/astral-sh/uv/issues/411

ChannyClaus commented 4 days ago

should this be part of uv pip tree or uv pip list? uv pip list --format json seems to already print something very similar to what pipdeptree --json prints:

$ uv pip list --format json | jq 
[
  {
    "name": "certifi",
    "version": "2024.6.2"
  },
  {
    "name": "charset-normalizer",
    "version": "3.3.2"
  },
  {
    "name": "idna",
    "version": "3.7"
  },
  {
    "name": "requests",
    "version": "2.32.3"
  },
  {
    "name": "urllib3",
    "version": "2.2.2"
  }
]

additionally the output of pipdeptree --json doesn't seem to necessarily relate to the concept of tree, since when there's a nested dependency, it doesn't actually nest it in the json output.

thoughts @dsully @kdeldycke?

kdeldycke commented 4 days ago

Oh I'm not really picky about the shape of the JSON output, as long as it is machine readable.

That's because I'm only interested in creating a Mermaid diagram to visualize dependencies like so: https://kdeldycke.github.io/meta-package-manager/install.html#python-dependencies

So whatever the JSON looks like, I'll have to write a script to generate the .mmd file out of uv pip tree output.