# How to display project dependencies in a tree?

**URL:** https://discourse.julialang.org/t/how-to-display-project-dependencies-in-a-tree/79567
**Category:** General Usage
**Tags:** question
**Created:** [April 16, 2022, 8:35am UTC](https://discourse.julialang.org/t/how-to-display-project-dependencies-in-a-tree/79567 "2022-04-16T08:35:15Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [April 16, 2022, 8:35am UTC](https://discourse.julialang.org/t/how-to-display-project-dependencies-in-a-tree/79567/1 "2022-04-16T08:35:15Z")

</div>

Using the package manager I can display the direct dependencies of my package:

```julia
(KiteModels) pkg> st
     Project KiteModels v0.2.2
      Status `~/repos/KiteModels/Project.toml`
  [39dd38d3] Dierckx v0.5.2
  [ffbed154] DocStringExtensions v0.8.6
  [9de5dc81] KitePodModels v0.1.2
  [90980105] KiteUtils v0.3.2
  [2774e3e8] NLsolve v4.5.1
  [d96e819e] Parameters v0.12.3
  [90137ffa] StaticArrays v1.4.3
  [c3572dad] Sundials v4.9.3
  [1e6cf692] TestEnv v1.7.2
  [37e2e46d] LinearAlgebra

```

Is there a way to also display the sub-dependencies and sub-sub-dependencies in a tree like structure similar to the command `tree` in Linux?

---

<div class="post-metadata">

### Author: ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)
#### Post date: [April 16, 2022, 9:30am UTC](https://discourse.julialang.org/t/how-to-display-project-dependencies-in-a-tree/79567/2 "2022-04-16T09:30:59Z")

</div>

Don’t know of a tree-like visualization option, but there is `st --manifest` for showing all dependencies (typing on my mobile phone and can’t check the precise name of the option.)

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [April 16, 2022, 9:34am UTC](https://discourse.julialang.org/t/how-to-display-project-dependencies-in-a-tree/79567/3 "2022-04-16T09:34:15Z")

</div>

You could read in the `Manifest.toml` using [TOML](https://docs.julialang.org/en/v1/stdlib/TOML/) and then use [REPLTreeViews.jl](https://github.com/pfitzseb/REPLTreeViews.jl) to look at the dictionary.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [April 16, 2022, 10:45am UTC](https://discourse.julialang.org/t/how-to-display-project-dependencies-in-a-tree/79567/4 "2022-04-16T10:45:00Z")

</div>

Thank you!  
But how did you know about that option? I could not find any options for any Pkg commands yet…

```julia
(KiteModels) pkg> st --help
ERROR: option 'help' is not a valid option

```

OK, found it:

```julia
(KiteModels) pkg> ?st
  [st|status] [-d|--diff] [pkgs...]
  [st|status] [-d|--diff] [-p|--project] [pkgs...]
  [st|status] [-d|--diff] [-m|--manifest] [pkgs...]

  Show the status of the current environment. In --project mode (default), the status of the project file is summarized. In --manifest mode the output also includes the recursive dependencies of added packages given in the manifest. If there are any packages listed as arguments the output will be limited to those
  packages. The --diff option will, if the environment is in a git repository, limit the output to the difference as compared to the last git commit.

  │ Julia 1.1
  │
  │ pkg> status with package arguments requires at least Julia 1.1.

  │ Julia 1.3
  │
  │ The --diff option requires Julia 1.3. In earlier versions --diff is the default for environments in git repositories.

```

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [April 16, 2022, 10:46am UTC](https://discourse.julialang.org/t/how-to-display-project-dependencies-in-a-tree/79567/5 "2022-04-16T10:46:50Z")

</div>

Thanks for suggesting this package!  
But does Manifest.toml contain the information needed to create a tree?  
I thought it is just a flat list.

---

<div class="post-metadata">

### Author: ![FMeirinhos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fmeirinhos/32/19527_2.png) [@FMeirinhos](https://discourse.julialang.org/u/FMeirinhos)
#### Post date: [April 17, 2022, 9:57am UTC](https://discourse.julialang.org/t/how-to-display-project-dependencies-in-a-tree/79567/6 "2022-04-17T09:57:51Z")

</div>

For pedagogical reasons I will write out how I came about the solution (since I am **not** a `Pkg` expert – i would bet there are easier ways to access this information).

The [documentation](https://pkgdocs.julialang.org/v1/api/) of `Pkg.status` cross-refs the functions `Pkg.project` and `Pkg.dependencies` as alternatives that don’t print out the results, so we are going to use those.

Now the hard part: knowing that `AbstractTrees.jl` – which we can use to transverse the tree – already has a [print function](https://github.com/JuliaCollections/AbstractTrees.jl/blob/master/src/AbstractTrees.jl#L10) so all we have to do is chain both.

```julia
using AbstractTrees
using Pkg

function AbstractTrees.printnode(io::IO, uuid::Base.UUID)
    dep = get(Pkg.dependencies(), uuid, nothing)
    print(io, dep.name)
end

function AbstractTrees.children(uuid::Base.UUID)
    dep = get(Pkg.dependencies(), uuid, nothing)
    dep.dependencies
end

# Example (with some package you have in your Project.toml -- in my case Pluto)
AbstractTrees.print_tree(Pkg.project().dependencies["Pluto"])

# Print all dependencies: definitely do not recommend
# AbstractTrees.children(x::Pkg.API.ProjectInfo) = x.dependencies
# AbstractTrees.printnode(io::IO, x::Pkg.API.ProjectInfo) = x.name
# AbstractTrees.print_tree(Pkg.project())

```

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [April 17, 2022, 12:13pm UTC](https://discourse.julialang.org/t/how-to-display-project-dependencies-in-a-tree/79567/7 "2022-04-17T12:13:42Z")

</div>

Very nice and easy solution!

Does anybody know what the meaning is of the triple dots that appear for example here:

```julia
│ ├─ Tables
│ │ ├─ DataAPI
│ │ ├─ OrderedCollections
│ │ ├─ LinearAlgebra
│ │ │ ├─ libblastrampoline_jll
│ │ │ │ ├─ OpenBLAS_jll
│ │ │ │ │ ⋮
│ │ │ │ │  
│ │ │ │ ├─ Libdl
│ │ │ │ │ ⋮
│ │ │ │ │  
│ │ │ │ └─ Artifacts
│ │ │ │ ⋮
│ │ │ │     
│ │ │ └─ Libdl

```

---

<div class="post-metadata">

### Author: ![FMeirinhos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fmeirinhos/32/19527_2.png) [@FMeirinhos](https://discourse.julialang.org/u/FMeirinhos)
#### Post date: [April 17, 2022, 1:02pm UTC](https://discourse.julialang.org/t/how-to-display-project-dependencies-in-a-tree/79567/9 "2022-04-17T13:02:02Z")

</div>

If you check the documentation of `print_tree`

```julia
?AbstractTrees.print_tree

```

you’ll see that there’s a `maxdepth` keyword argument that truncates the output. Setting it to a large value should get rid of those dots

```julia
AbstractTrees.print_tree(Pkg.project().dependencies["Pluto"], maxdepth=Inf)

```

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [April 17, 2022, 3:33pm UTC](https://discourse.julialang.org/t/how-to-display-project-dependencies-in-a-tree/79567/10 "2022-04-17T15:33:56Z")

</div>

Perfect! Thank you.

Learning a lot by studying these trees! 😀

---

<div class="post-metadata">

### Author: ![Alec\_Loudenback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alec_loudenback/32/278_2.png) [@Alec\_Loudenback](https://discourse.julialang.org/u/Alec_Loudenback)
#### Post date: [October 11, 2022, 3:45am UTC](https://discourse.julialang.org/t/how-to-display-project-dependencies-in-a-tree/79567/11 "2022-10-11T03:45:10Z")

</div>

For anyone landing on this topic: there is now [GitHub - peng1999/PkgDependency.jl: Show dependency tree of Julia project](https://github.com/peng1999/PkgDependency.jl)

---

<div class="post-metadata">

### Author: ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)
#### Post date: [October 11, 2022, 6:32am UTC](https://discourse.julialang.org/t/how-to-display-project-dependencies-in-a-tree/79567/12 "2022-10-11T06:32:50Z")

</div>

I was thinking that the right visualization would not be a tree, since, if we root at the current environment, the same package might appear at several places. A directed graph would be a better representation.

---

<div class="post-metadata">

### Author: ![Alec\_Loudenback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alec_loudenback/32/278_2.png) [@Alec\_Loudenback](https://discourse.julialang.org/u/Alec_Loudenback)
#### Post date: [November 8, 2023, 3:17pm UTC](https://discourse.julialang.org/t/how-to-display-project-dependencies-in-a-tree/79567/13 "2023-11-08T15:17:10Z")

</div>

Crosspost for a way to visualize dependencies with their import timings:

> [@Quick guide to get graph of dependencies with import times](https://discourse.julialang.org/t/quick-guide-to-get-graph-of-dependencies-with-import-times/105557):
>
> tl;dr - a script to plot dependencies and the associated @time\_imports time. I’m in the process of putting one of my packages through a diet and wanted to better understand the upstream dependencies and their impact on my TTFX. This isn’t the whole picture, but I hadn’t seen something like this shared before and wanted to post if helpful and maybe improve on it. My package of interest right now is FinanceModels, so this will show an example as of FinanceModels v4.3.0. Setup: Create a tempora…
