[ANN] AutoPkg.jl - install and use packages in one go

Motivated by the need to create Google Colab notebooks that handle package installation in a very simple, beginner-friendly way (for didactic scenarios), I’ve registered a little package AutoPkg. It provides a macro @autopkg that makes it easy to add and use packages in one go (Colab example link).

Just have a cell like

import Pkg; Pkg.add("AutoPkg"); using AutoPkg

at the top of the notebook (Colab, Jupyter, VS-Code), then you can just do

@autopkg begin
    using Distributions
    using Makie
    import CairoMakie
end

On Google Colab, @autopkg installs packages directly (since the notebooks run in isolated containers anyway), otherwise it activates a temporary Julia project env. It also always sets $JULIA_PKG_PRESERVE_TIERED_INSTALLED to "true".

In addition to notebooks, I’ve also found @autopkg useful to quickly try out some packages on the REPL. It also, at least partially, addresses Pkg issues 3027.

(@autopkg is not intended for Pluto notebooks, Pluto has built-in package management after all.)

@autopkg can handle more complex block of code as well, like

@autopkg begin
    using SomePackage, SomeOtherPackage
    import YetAnotherPackage

    if some_condition
        using OneMorePackage: some_feature
    end
end
2 Likes

For REPL, is it basically the default behavior + auto-click “o + Enter” at the prompt? Or something different?