-
-
Notifications
You must be signed in to change notification settings - Fork 269
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
Macro to add "using" packages automatically #2027
Comments
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 |
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 JuliaLang/julia#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 |
Effectively closed by JuliaLang/julia#39026 |
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!The text was updated successfully, but these errors were encountered: