opam icon indicating copy to clipboard operation
opam copied to clipboard

Add `opam tree` subcommand to display a dependency tree

Open g2p opened this issue 6 years ago • 7 comments

opam query only shows flat results.

opam tree, similar to cargo tree in Rust, would display a dependency tree. Here's how it looks like in Rust:

cargo tree
postgres v0.10.2 (file:///Volumes/git/rust/rust-postgres)
├── bufstream v0.1.1
├── byteorder v0.4.2
├── hex v0.1.0
├── log v0.3.4
│   └── libc v0.2.4
├── net2 v0.2.20
│   ├── cfg-if v0.1.0
│   ├── kernel32-sys v0.2.1
│   │   └── winapi v0.2.5
│   ├── libc v0.2.4 (*)
│   ├── winapi v0.2.5 (*)
│   └── ws2_32-sys v0.2.1
│       └── winapi v0.2.5 (*)
└── phf v0.7.9
    └── phf_shared v0.7.9

Note the Unicode-art.

Items marked with (*) are later instances of common subtrees; the subtrees are skipped instead of being printed another time.

Useful options: --duplicate

This displays a forest of inverted trees, starting at every duplicate dependency, towards the root. This is useful for examining how dependency versions get constrained.

g2p avatar Mar 09 '19 23:03 g2p

i often have install deps that fail, and i want this feature to see who is calling for it. perhaps the parent node has bad ranges, needs to be pinned, etc.

cdaringe avatar Nov 01 '20 19:11 cdaringe

npm ls / yarn why are additional prior art that emit reduced graphs with the requested package as the leaf, and print up the dep tree to the root. super helpful

cdaringe avatar Nov 01 '20 19:11 cdaringe

Is there any way to get that kind of information, albeit not as nicely for now? I experimented with opam lock and I was surprised by some of the dependencies of my little project. I tried to track some down on https://opam.ocaml.org/packages/ but for some of them I'm stumped. (Like cppo, I'd expect as a build dependency but it's a normal dependency. No idea who needs it.)

(To clarify: I know that opam-query exists but it is incompatible with OCaml 4.08+ because of a dependency on an old version of containers. So I'm looking for other ways to get the information.)

vphantom avatar Jan 26 '22 13:01 vphantom

I'm working on it and got this so far: image

I'll open a PR once I complete docs and add adequate tests.

cannorin avatar Jun 30 '22 14:06 cannorin

Your opam why output looks absolutely awesome. I want this in opam! :-)

avsm avatar Jun 30 '22 15:06 avsm

@cannorin if you have some time to spend on this I'd suggest to look at this paper which seems to have interesting techniques for ASCII DAG visualisations.

dbuenzli avatar Jun 30 '22 18:06 dbuenzli

@dbuenzli I've just read the paper. Looks interesting for sure, but it would need some additional work to allow annotating edges, which would be needed to show the constraints (e.g. (>= 4.0.0)). Also, we would need to try to make the graph as less wide as possible (since we are working with CLI), but the paper only mentions about it as a future work.

cannorin avatar Jul 01 '22 02:07 cannorin