Hello,
So I may be wrong, but I have been looking and asking around, and I found no package that builds a pretty tree of a package content.
Something like this:
ClimaLand
├─ Artifacts
├─ Bucket
├─ Canopy
│ └─ PlantHydraulics
├─ Diagnostics
├─ Domains
├─ Parameters
├─ Pond
├─ Snow
└─ Soil
├─ Biogeochemistry
└─ Runoff
that display the package main Module and submodules
and hopefully it’d be even better if you’d see functions and struct exported from the module, in different colors (e.g., red for functions, blue for struct), with the possibility to expand or collapse…
To get a list of the modules of the package ClimaLand I did:
function get_module_hierarchy(mod::Module, prefix="")
result = String[]
mod_name = string(nameof(mod))
full_prefix = isempty(prefix) ? mod_name : "$prefix.$mod_name"
for name in names(mod, all=true)
if !startswith(string(name), "#")
obj = getproperty(mod, name)
if obj isa Module && obj != mod
full_name = "$full_prefix.$name"
push!(result, full_name)
append!(result, get_module_hierarchy(obj, full_prefix))
end
end
end
return sort(result)
end
and to build the tree:
using AbstractTrees
# Define a simple tree node type
struct ModuleNode
name::String
children::Vector{ModuleNode}
end
# Implement the required methods for AbstractTrees
AbstractTrees.children(node::ModuleNode) = node.children
AbstractTrees.printnode(io::IO, node::ModuleNode) = print(io, node.name)
# Create your tree structure
climatree = ModuleNode("ClimaLand", [
ModuleNode("Artifacts", []),
ModuleNode("Bucket", []),
ModuleNode("Canopy", [
ModuleNode("PlantHydraulics", [])
]),
ModuleNode("Diagnostics", []),
ModuleNode("Domains", []),
ModuleNode("Parameters", []),
ModuleNode("Pond", []),
ModuleNode("Snow", []),
ModuleNode("Soil", [
ModuleNode("Biogeochemistry", []),
ModuleNode("Runoff", [])
])
])
But I wish there was a package that you just do e.g., PackageTree(nameofpackage)
and you’d have a beautiful tree… If it doesn’t exist, I am surprised, I think it would be amazing to have it in docs etc.