Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing a PkgId to @require #109

Open
frankier opened this issue Apr 12, 2022 · 0 comments
Open

Passing a PkgId to @require #109

frankier opened this issue Apr 12, 2022 · 0 comments

Comments

@frankier
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant