Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to build package dependency tree in julia-lang?

Tags:

julia

Using npm list will show a tree of installed packages, versions and relations:

enter image description here

Although Julia package management is differ (e.g normally no duplicate copy of a package exists), But is there any way to:

  • Know why one package have been installed?
  • or build a package dependency tree.
like image 865
Reza Afzalan Avatar asked Apr 15 '16 08:04

Reza Afzalan


People also ask

How do I import packages to Julia?

To install packages, use Pkg , Julia's built-in package manager, to add packages to your active environment. To use packages already in your active environment, write import X or using X , as described in the Modules documentation.

How many packages does Julia have?

The Julia ecosystem contains over 7,400 packages that are registered in the General registry, which means that finding the right package can be a challenge.

Where are Julia packages stored?

One or more modules can be stored in a package, and these are managed using the git version control system. Most Julia packages, including the official ones, are stored on GitHub, where each Julia package is, by convention, named with a ". jl" suffix.


3 Answers

I don't think there's a simple function, but it shouldn't be too hard to do with these two functions:

julia> Pkg.dependents("Cairo")
10-element Array{AbstractString,1}:
 "Tk"
 "Gtk"
 "Mamba"
 "Drawing"
 "GtkUtilities"
 "ProfileView"
 "Brim"
 "Winston"
 "EcologicalNetwork"
 "VennEuler"

julia> Pkg.installed()
Dict{ASCIIString,VersionNumber} with 119 entries:
  "Libz"             => v"0.0.2"
  "Gtk"              => v"0.9.3"
  "Interact"         => v"0.3.0"
  "ForwardDiff"      => v"0.1.4"
  "Benchmark"        => v"0.1.0"
  "AxisAlgorithms"   => v"0.1.4"
  "Cairo"            => v"0.2.31+"
  "HttpParser"       => v"0.1.1"
  "DataFrames"       => v"0.6.10"
  "Requests"         => v"0.3.4"
  "QuartzImageIO"    => v"0.1.0+"
  "Markdown"         => v"0.3.0"
  "Requires"         => v"0.2.2"
  "ArgParse"         => v"0.3.0"
  ⋮                  => ⋮
like image 191
daycaster Avatar answered Nov 15 '22 10:11

daycaster


simple code bellow will printout the requires-by result for a package:

whorequires(pkgname) = whorequires(pkgname, 0);
function whorequires(pkgname, i)
  deps = Pkg.dependents(pkgname);
  [print('-') for j=1:i];
  println(pkgname);
  length(deps) > 0 && [whorequires(dep,i+1) for dep in deps];
end

julia> whorequires("JuliaParser");
JuliaParser
-CodeTools
--Atom
-ASTInterpreter
--Gallium
-Jewel

EDIT (to cover issue commented by @amrods)

whorequires(pkgname) = whorequires(pkgname, 0, Dict{ASCIIString,Vector{ASCIIString}}());
function whorequires(pkgname, i, m)
  [print('-') for j=1:i];
  if (haskey(m,pkgname))
    println("$pkgname *[duplicated]* is required by ", length(m[pkgname]), " packages");
  else
    println(pkgname);
    m[pkgname] = Pkg.dependents(pkgname);
    if (length(m[pkgname]) > 0)
        for dep in m[pkgname]
            whorequires(dep,i+1,m);
        end
    end
  end
end
like image 40
Reza Afzalan Avatar answered Nov 15 '22 10:11

Reza Afzalan


There is a package, although not registered, which does this: https://github.com/peng1999/PkgDependency.jl It's quite straightforward to use

pkg> add https://github.com/peng1999/PkgDependency.jl
julia> using PkgDependency
julia> PkgDependency.tree("HTTP")
HTTP v0.9.13 
    NetworkOptions v1.2.0
    IniFile v0.5.0
    URIs v1.3.0
    MbedTLS v1.0.3
        MbedTLS_jll v2.16.8+1
            JLLWrappers v1.3.0
                Preferences v1.2.2
                    TOML v1.0.3
            Artifacts v1.3.0

It relies on a new (>1.4) experimental API, which can be used on its own to list (direct) dependencies, but it's quite ugly:

julia> using Pkg

julia> Pkg.dependencies()[Pkg.project().dependencies["HTTP"]].dependencies
Dict{String, Base.UUID} with 5 entries:
  "Dates"   => UUID("ade2ca70-3891-5945-98fb-dc099432e06a")
  "Base64"  => UUID("2a0f44e3-6c83-55bd-87e4-b1978d98bd5f")
  "Sockets" => UUID("6462fe0b-24de-5631-8697-dd941f90decc")
  "IniFile" => UUID("83e8ac13-25f8-5344-8a64-a9f2b223428f")
  "MbedTLS" => UUID("739be429-bea8-5141-9913-cc70e7f3736d")

If you only want the list for dependencies of the currently active project, then Pkg.project().dependencies is enough.

I've opened a Pkg.jl issue to discuss this here.

like image 26
Matěj Račinský Avatar answered Nov 15 '22 09:11

Matěj Račinský