Last active
July 15, 2020 19:25
-
-
Save matbesancon/ac508805b0f9ca9461f49892ab2180d0 to your computer and use it in GitHub Desktop.
Dependencies on LightGraphs.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script assumes the Julia session is running at the root of the General repository | |
# https://github.com/JuliaRegistries/General | |
# Need these 3 installed | |
using LightGraphs, MetaGraphs, GraphPlot | |
import Pkg | |
function find_direct_deps(pkg_paths, source) | |
direct_deps = filter(pkg_paths) do pkg_path | |
deps_file = joinpath(pkg_path.path, "Deps.toml") | |
isfile(deps_file) && begin | |
deps_struct = Pkg.TOML.parsefile(joinpath(pkg_path.path, "Deps.toml")) | |
any(map(values(deps_struct)) do d | |
source in keys(d) | |
end) | |
end | |
end | |
end | |
g = MetaDiGraph() | |
add_vertex!(g) | |
set_prop!(g, 1, :name, "LightGraphs") | |
# must be executed in root of General | |
# or pass the appropriate path to Registry.toml | |
pkg_paths = map(values(Pkg.TOML.parsefile("Registry.toml")["packages"])) do d | |
(name = d["name"], path = d["path"]) | |
end | |
explored_nodes = ["LightGraphs"] | |
i = 1 | |
while true | |
global i, g | |
source = get_prop(g, i, :name) | |
direct_deps = find_direct_deps(pkg_paths, source) | |
filter!(d -> d.name ∉ explored_nodes, direct_deps) | |
if isempty(direct_deps) && i >= nv(g) | |
break | |
end | |
for ddep in direct_deps | |
push!(explored_nodes, ddep.name) | |
add_vertex!(g) | |
set_prop!(g, nv(g), :name, ddep.name) | |
add_edge!(g, i, nv(g)) | |
end | |
i += 1 | |
end | |
# TODO: make it readable | |
gplothtml(g, nodelabel= get_prop.(Ref(g), 1:nv(g), :name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment