Internals
Package dependency graphs
PkgGraph.DepGraph.depgraph
— Functiondepgraph(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"
PkgGraph.DepGraph.is_jll
— Functionis_jll(pkg)::Bool
PkgGraph.DepGraph.is_in_stdlib
— Functionis_in_stdlib(pkg)::Bool
Dot-strings
PkgGraph.DotString.to_dot_str
— Functionto_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]
}
PkgGraph.DotString.default_style
— Functiondefault_style()
The default style used by to_dot_str
:
node [fontname="sans-serif", fontsize=14]
node [color=none, shape=box, width=1, height=0.5]
edge [arrowsize=0.8]
Package graph as Dot-string
PkgGraph.depgraph_as_dotstr
— Functiondepgraph_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).
PkgGraph.print_dotstr
— Functionprint_dotstr(pkgname; kw...)
Like depgraph_as_dotstr
but prints the result instead of returning a string.
Measuring load time
PkgGraph.LoadTime.time_imports
— Functiontime_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)
Post-processing of SVG files
PkgGraph.SVG.add_darkmode
— Functionadd_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
).
Online rendering
PkgGraph.url
— Functionurl(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"
PkgGraph.webapps
— ConstantA list of websites that can render Graphviz dot-formatted strings. Used by url
.
Note that these are 'base URLs', to which url-encoded dot-strings can be directly appended.
Default contents:
Graphs.jl conversion
PkgGraph.DepGraph.as_graphsjl_input
— Functionas_graphsjl_input(edges)
Obtain the outputs of, respectively
..but without unnecessary repeat computation.
Useful when converting the output of depgraph
to a Graphs.jl
graph;
See the example script in Working with Graphs.jl.
PkgGraph.DepGraph.vertices
— Functionvertices(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"
PkgGraph.DepGraph.node_index
— Functionnode_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
PkgGraph.DepGraph.adjacency_matrix
— Functionadjacency_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