TradingDerivatives.eu
TradingDerivatives.eu

Reputation: 408

Fill an iterable with Julia packages

Pkg.status() is well-known. However, it outputs to stdout. I need the package names in an iterable, like a list or a vector or so. It would be silly to use Suppressor. How can this be achieved?

Based on the answer below:

for v in values(Pkg.dependencies())
    println(v.name)
end

Upvotes: 3

Views: 61

Answers (1)

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42214

What you are looking for is dependencies()

julia> Pkg.dependencies()
Dict{Base.UUID, Pkg.API.PackageInfo} with 399 entries:
  UUID("49dc2e85-a5d0-5ad3-a950-438e2897f1b9") => PackageInfo("Calculus", v"0.5.1", "f641eb0a4f00c343bbc32346e1217b86f3ce9da…
  UUID("efcefdf7-47ab-520b-bdef-62a2eaa19f15") => PackageInfo("PCRE2_jll", v"10.40.0+0", nothing, false, false, false, false…
...

This returns an iterator of pars. The value element of the pair contains a PackageInfo element that has the following fields:

julia> fieldnames(Pkg.API.PackageInfo)
(:name, :version, :tree_hash, :is_direct_dep, :is_pinned, :is_tracking_path, :is_tracking_repo, :is_tracking_registry, :git_revision, :git_source, :source, :dependencies)

And here is a sample usage:

julia> for (uuid, dep) in Pkg.dependencies()
            dep.is_direct_dep || continue
            dep.version === nothing && continue
            println("$(dep.name) $(dep.version)")
       end
ZipFile 0.10.0
DataFrames 1.4.1
Revise 3.4.0
Symbolics 4.11.1
BenchmarkTools 1.3.1
IJulia 1.23.3
...

Upvotes: 5

Related Questions