Requires.jl
Requires.jl copied to clipboard
Passing a PkgId to @require
It would be neat if it were possible to pass a PkgId to a version of require so that I could have dependency groups which can be installed a a group and also guarded on as a group. An example of what I would like is here with install_extra and require_extra.
function install_extra(extra)
pkgs = []
if extra == "all"
for (_, specs) in extras
append!(pkgs, specs)
end
else
append!(pkgs, extras[extra])
end
Pkg.add(pkgs)
end
function require_extra(cb, extra)
function helper(tail)
if length(tail) > 0
pkg = tail[1]
pkgid = Base.PkgId(pkg.uuid, pkg.name)
@require_pkgid pkgid begin
helper(tail[2:end])
end
else
cb()
end
end
helper(extras[extra])
end
function __init__()
require_extra("plots") do
include("Plots.jl")
end
end
function pkg(name, uuid)
PackageSpec(name, Base.UUID(uuid))
end
const extras = Dict(
"plots" => [
pkg("Makie", "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"),
pkg("CairoMakie", "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"),
pkg("GLMakie", "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"),
pkg("WGLMakie", "276b4fcb-3e11-5398-bf8b-a0c2d153d008"),
pkg("DataFrames", "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"),
pkg("AlgebraOfGraphics", "cbdf2221-f076-402e-a563-3d30da359d67")
]
)
Unfortunately my macro-fu is not sufficient to be able to write @require_pkgid but I am noting it here.