diff --git a/docs/src/index.md b/docs/src/index.md index 4146bd0..9f03489 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -26,6 +26,7 @@ Unless otherwise specified, all methods of `tree` function support following kwa | `compat` | `false` | show compat info in tree | | `show_link` | `false` | show packages' repo link in tree | | `dedup` | `true` | hide duplicate dependencies in tree | +| `stdlib` | `false` | show packages from Standard Library | ## API diff --git a/src/PkgDependency.jl b/src/PkgDependency.jl index 6aae82f..efdecd8 100644 --- a/src/PkgDependency.jl +++ b/src/PkgDependency.jl @@ -10,7 +10,7 @@ function __init__() end """ - tree(...; reverse=false, compat=false, show_link=false, dedup=true) + tree(...; reverse=false, compat=false, show_link=false, dedup=true, stdlib=false) """ function tree end @@ -20,7 +20,7 @@ function tree end Print dependency tree of current project. `reverse` kwarg is not supported in this method. """ -function tree(; compat=false, show_link=false, dedup=true) +function tree(; compat=false, show_link=false, dedup=true, stdlib=false) project = Pkg.project() if project.ispackage name = something(project.name, "Unnamed Project") @@ -31,7 +31,7 @@ function tree(; compat=false, show_link=false, dedup=true) end registries = check_and_get_registries(; show_link) - Tree(builddict(project.uuid, project; compat, registries, dedup), title="$name $version") + Tree(builddict(project.uuid, project; compat, registries, dedup, stdlib), title="$name $version") end """ @@ -39,7 +39,7 @@ end Print dependency tree of a package identified by UUID """ -function tree(uuid::UUID; reverse=false, compat=false, show_link=false, dedup=true) +function tree(uuid::UUID; reverse=false, compat=false, show_link=false, dedup=true, stdlib=false) graph = Pkg.dependencies() if reverse revgraph = Pkg.dependencies() @@ -59,7 +59,7 @@ function tree(uuid::UUID; reverse=false, compat=false, show_link=false, dedup=tr # registries is used to find url registries = check_and_get_registries(; show_link) - Tree(builddict(uuid, project; graph, compat, registries, dedup), title="$name v$version") + Tree(builddict(uuid, project; graph, compat, registries, dedup, stdlib), title="$name v$version") end """ @@ -110,7 +110,7 @@ compatstr(c::String) = c compatstr(c::Any) = c.str # returns dependencies of info as OrderedDict, or nothing when no dependencies -function builddict(uuid::Union{Nothing,UUID}, info; graph=Pkg.dependencies(), listed=Set{UUID}(), dedup=true, compat=false, registries=nothing) +function builddict(uuid::Union{Nothing,UUID}, info; graph=Pkg.dependencies(), listed=Set{UUID}(), dedup=true, compat=false, registries=nothing, stdlib=false) deps = info.dependencies compats = compat && !isnothing(uuid) ? compatinfo(uuid) : Dict() children = OrderedDict() @@ -127,7 +127,7 @@ function builddict(uuid::Union{Nothing,UUID}, info; graph=Pkg.dependencies(), li end subpkg = graph[uuid] - if isnothing(subpkg.version) + if isnothing(subpkg.version) && ! stdlib continue end postfix = uuid ∈ listed ? " (*)" : "" @@ -136,6 +136,9 @@ function builddict(uuid::Union{Nothing,UUID}, info; graph=Pkg.dependencies(), li postfix = postfix * " compat=\"$(compatstr(cinfo))\"" end name = "$(subpkg.name) v$(subpkg.version)$postfix" + if isnothing(subpkg.version) + name = "$(subpkg.name) StdLib v$VERSION$postfix" + end if registries !== nothing && !isempty(link) name *= " ($link)" end @@ -143,7 +146,7 @@ function builddict(uuid::Union{Nothing,UUID}, info; graph=Pkg.dependencies(), li child = nothing if uuid ∉ listed push!(listed, uuid) - child = builddict(uuid, subpkg; graph, listed, compat, registries, dedup) + child = builddict(uuid, subpkg; graph, listed, compat, registries, dedup, stdlib) if !dedup pop!(listed, uuid) end diff --git a/test/runtests.jl b/test/runtests.jl index b0134dc..959705e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,14 +5,16 @@ import Term: Tree @testset "Make sure function runs without error" begin for dedup in [true; false] for compat in [true; false] - @test PkgDependency.tree(; compat, dedup) isa Tree - @test PkgDependency.tree("Term"; compat, dedup) isa Tree - @test PkgDependency.tree("Term"; reverse=true, compat, dedup) isa Tree + for stdlib in [true; false] + @test PkgDependency.tree(; compat, dedup, stdlib) isa Tree + @test PkgDependency.tree("Term"; compat, dedup, stdlib) isa Tree + @test PkgDependency.tree("Term"; reverse=true, compat, dedup, stdlib) isa Tree if VERSION < v"1.7" - @test_throws ErrorException PkgDependency.tree("Term"; compat, show_link=true, dedup) isa Tree + @test_throws ErrorException PkgDependency.tree("Term"; compat, show_link=true, dedup, stdlib) isa Tree else - @test PkgDependency.tree("Term"; compat, show_link=true, dedup) isa Tree + @test PkgDependency.tree("Term"; compat, show_link=true, dedup, stdlib) isa Tree end end end + end end