Skip to content

Commit

Permalink
added standard library packages
Browse files Browse the repository at this point in the history
  • Loading branch information
oheil committed Apr 16, 2024
1 parent be405ef commit b5b3551
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 11 additions & 8 deletions src/PkgDependency.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -31,15 +31,15 @@ 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

"""
tree(uuid::UUID; kwargs...)
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()
Expand All @@ -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

"""
Expand Down Expand Up @@ -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()
Expand All @@ -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 ? " (*)" : ""
Expand All @@ -136,14 +136,17 @@ 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

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
Expand Down
12 changes: 7 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b5b3551

Please sign in to comment.