Closed mossr closed 3 years ago
Thank you for linking those (I knew this wasn't a unique issue but failed to find those).
I created a separate package—AddPackage.jl—with this macro so I can use it within Pluto notebooks sent to students. Also, the threads you linked seem to focus on the interactive REPL responses when calling using Package
, where @add using Package
is helpful for notebooks or single one-off scripts without a Project.toml.
Everything has a Project.toml file, but perhaps Pluto can't handle the interactivity?
Pluto can handle adding packages within a cell, but the use-case is mainly for convenience so cells don't look like:
try
using Package
catch
using Pkg
Pkg.add("Package")
using Package
end
and instead look like:
@add using Package
(again, for lecture-style notebooks/Julia files that may be sent as single files and not part of a package, thus without a Project.toml)
I mean that if something like https://github.com/JuliaLang/julia/pull/26469 were implemented.
Good point, then I agree that Pluto may not be able to handle that level of interactivity.
I originally wanted to prompt to add packages when someone does using
and the package isn't already added. I still think that would be a nice feature to have.
Effectively closed by https://github.com/JuliaLang/julia/pull/39026 and probably by Pluto changes?
Not sure if this is where you'd like the Pkg manager to go, but I threw together an
@add
macro to automatically install missing packages when callingusing
. Example:This will run
using Clustering
if we already have it, otherwise it will add it, then runusing Clustering
.Here's the macro:
This also works for multiple comma separated packages:
I tried searching for related issues to no avail. My use-case is for one-off lecture-style Pluto notebooks given to students so I can just call a one-line
@add using Package
instead of wrapping everything in a try/catch or creating a light-weight package with a Project.toml just for one file. Thoughts and feedback welcome!