Internals

Package dependency graphs

PkgGraph.DepGraph.depgraphFunction
depgraph(pkgname; jll = true, stdlib = true)

Build a directed graph of the dependencies of the given package, using the active project's Manifest file.

The returned deps object is a flat list of "PkgA" => "PkgB" dependency pairs.

Binary JLL dependencies and packages in the standard library can be filtered out from the result by setting jll and stdlib to false.

Example:

julia> using PkgGraph.DepGraph

julia> depgraph(:Test)
8-element Vector{Pair{String, String}}:
             "Test" => "InteractiveUtils"
 "InteractiveUtils" => "Markdown"
         "Markdown" => "Base64"
             "Test" => "Logging"
             "Test" => "Random"
           "Random" => "SHA"
           "Random" => "Serialization"
             "Test" => "Serialization"
source

Dot-strings

PkgGraph.DotString.to_dot_strFunction
to_dot_str(
    edges;
    dark      = false,
    bg        = "transparent",
    style     = default_style(),
    indent    = 4,
    emptymsg  = nothing,
    faded     = nothing,
    nodeinfo  = nothing,
)

Build a string that represents the given directed graph in the Graphviz DOT format ↗.

Keyword arguments

dark

Default is false i.e. light-mode: black lines and black text with white backgrounds. For dark = true, it's white lines and white text, with black backgrounds. Note that locally-generated SVGs get both colour-schemes simultaneously, so this option is irrelevant for them.

bg

Background colour for the image.
Default is "transparent".
"white" (in combination with dark = false) might be a sensible value when you are creating a PNG but do not know on what background it will be seen. (A light-mode PNG with transparent background looks bad on a dark background).

style

A list of strings, inserted as lines in the output (after the lines generated for dark and bg, and just before the graph edge lines). To use Graphviz's default style, pass style = []. For the default see default_style. For more on how dot-graphs can be styled, see Styling Graphviz output.

indent

The number of spaces to indent each line in the "digraph" block with.

emptymsg

If there are no edges, a single node with emptymsg is created. If emptymsg is nothing (default), no nodes are created, and the image rendered from the DOT-string will be empty.

faded

A function (nodename) -> Bool that determines whether this node – and its incoming and outgoing edges – should be drawn in gray. If nothing (default), no nodes are faded.

nodeinfo

A mapping node::String => info::String, or nothing (default). For any node present in this mapping, its info is printed underneath its name in the graph.

Example:

julia> edges = [:A => :B, "yes" => "no"];

julia> style = ["node [color=\"red\"]"];

julia> using PkgGraph

julia> PkgGraph.to_dot_str(edges; style, bg=:blue, indent=2) |> println
digraph {
  bgcolor = "blue"
  node [fontcolor="black"]
  edge [color="black"]
  node [color="red"]
  A -> B
  yes -> no
}

julia> emptymsg="(empty graph)";

julia> PkgGraph.to_dot_str([]; emptymsg, dark=true, style=[]) |> println
digraph {
    bgcolor = "transparent"
    node [fontcolor="white"]
    edge [color="white"]
    onlynode [label=" (empty graph) ", shape=plaintext]
}
source

Package graph as Dot-string

PkgGraph.depgraph_as_dotstrFunction
depgraph_as_dotstr(
    pkgname;
    emptymsg = "($pkgname has no dependencies)",
    faded    = is_in_stdlib,
    time     = false,
    kw...
)

Render the dependency graph of pkgname as a Dot-string.

First calls depgraph(pkgname), and then calls to_dot_str on the result. Keyword arguments are passed on to whichever of those two functions accepts them.

By default, packages in the Julia standard library are drawn in gray. To disable this, pass faded = nothing.
Note that standard library packages can be filtered out entirely by passing stdlib = false (see depgraph).

When time is true, calls time_imports and displays the results in the graph. (Julia 1.8 and higher only).

source

Measuring load time

PkgGraph.LoadTime.time_importsFunction
time_imports(pkg)

Measure load times of the given package and its dependencies, by running @time_imports in a new julia process, and parsing its output.

@time_imports is new in Julia 1.8. If called with a lower Julia version, this method prints a warning and returns an empty list.

Example:

julia> using PkgGraph.LoadTime

julia> loadtimes = time_imports("EzXML");
┌ Info: Running command:
│ `julia --startup-file=no --project=. -e 'using InteractiveUtils; @time_imports using EzXML'`
└ Live output:
    423.5 ms  Preferences
      0.7 ms  JLLWrappers
      0.3 ms  Zlib_jll
      9.3 ms  Libiconv_jll 40.60% compilation time
      4.4 ms  XML2_jll
     54.1 ms  EzXML 53.25% compilation time

julia> last(loadtimes)
(pkgname = "EzXML", time_ms = 54.1)
source

Post-processing of SVG files

PkgGraph.SVG.add_darkmodeFunction
add_darkmode(path, out = path)

Edit an SVG file generated by Graphviz.

Remove repeated styling on individual elements, and replace it by a global stylesheet, with both light and dark modes. (This is achieved through a CSS @media query for prefers-color-scheme).

source

Online rendering

PkgGraph.urlFunction
url(dotstr, base = first(webapps))

Create a URL at which the given dot-string is rendered as an image, using an online Graphviz rendering service.

The dot-string is URL-encoded, and appended to a partly complete base URL (see webapps)

Example:

julia> base = PkgGraph.webapps[2];

julia> PkgGraph.url("digraph {Here->There}", base)
"http://magjac.com/graphviz-visual-editor/?dot=digraph%20%7BHere-%3EThere%7D"
source

Graphs.jl conversion

PkgGraph.DepGraph.verticesFunction
vertices(edges)

Extract the unique nodes from the given list of edges.

Example:

julia> using PkgGraph.DepGraph

julia> edges = depgraph(:Test);

julia> vertices(edges)
8-element Vector{String}:
 "Test"
 "InteractiveUtils"
 "Markdown"
 "Random"
 "Base64"
 "Logging"
 "SHA"
 "Serialization"
source
PkgGraph.DepGraph.node_indexFunction
node_index(edges)
node_index(vertices)

Create a function that returns the index of a given vertex.

This is useful because Graphs.jl requires vertices to be integers.

Example:

julia> using PkgGraph.DepGraph

julia> edges = ["A"=>"B", "B"=>"C"];

julia> node = node_index(edges);

julia> node("C")
3
source
PkgGraph.DepGraph.adjacency_matrixFunction
adjacency_matrix(edges)

A square bitmatrix A that is 0 everywhere except at A[i,j] when there is a connection from the node with index i to the node with index j.

Example:

julia> using PkgGraph.DepGraph

julia> edges = [
           :A => :A
           :A => :B
           :B => :C
       ];

julia> adjacency_matrix(edges)
3×3 BitMatrix:
 1  1  0
 0  0  1
 0  0  0
source