Pkg.jl
Pkg.jl copied to clipboard
[Feature request] option to automatically install a package when using `using`
As suggested by @KristofferC in the following link:
https://discourse.julialang.org/t/using-package-install-automatically/70896/5
I am opening an issue so that maintainers can discuss whether they deem it useful or not to have an option to automatically install a package when using using
. That option would bypass the prompt message asking whether the user wants to install the package or not.
Just speaking for myself here (i.e. not for other users), but when I use using X
, I will probably answer yes 99% of the time to the question "do you want to install package X".
That option could be implemented via macro or env variable, I don't really have a strong view on it.
I just think it is a nice to have option.
Thank you
In 1.8 you get the options y/n/o where o
lets you choose the environment you want to install into. If you're not in the main environment this can be useful for installing packages like Revise or BenchmarkTools into the main env that you don't want in your current project, but will want available.
There could be an env var to automatically select y
but it would side-step that functionality, which seems a shame. But given it would be opt-in, then it sounds reasonable, as long as new users aren't persuaded to add the env var by default.
In my original test implementation of installing during using
I had that pressing Y
would remember your choice (while y
would not). But you would still have to make one active choice. Perhaps an env variable so that you can set it even before the first using
is a better idea.
One thought.. would removing the need to confirm open users up more to typo issues, malicious or not. I guess they'd still see the package installation, so that would give them pause?
Well, that's something that is up to the user. Just by installing a package (or doing an update), you are already opening yourself up to some level of possible maliciousness.
Yeah I guess I just meant that if there's no confirm, they might not be aware they're installing a new package. But the messaging probably makes it clear.
Would you be ok with a macro like the following?
@add_pkg using DataFrames, CSV
We can call the macro as you wish and it would need to be available in Julia when the session starts.
The same macro coukd install from a local directory.
@add_pkg "C:/temp/MyPackage" using MyPackage
Similarly we can have @dev_pkg
macro.
I am not fan of environment variable. I always forget about them or to set them up. I prefer to have everything in the code.
Alternatively we could have some like:
using install=true DataFrames, CSV
Is that something you would consider?
Or we can simply have a macro that install packages at the beginning of the script without the need to load Pkg:
@add_pkg DataFrames, CSV
using DataFrames
import CSV
The macro would check if the packages are install or not and if not then install them automatically without prompt message requesting input from the user every time a package needs to be installed.
I tried to think who would actually use a feature like this, and came up with 3 scenarios:
- An experienced Julia user starts a simulation on a Friday afternoon, leaves for the weekend and comes back Monday morning to a prompt asking him if he wants to Install the
DataFrames
package, instead of having a set of simulation results. - A teacher has a 2 hour hands on class with some students that have little programming experience and know nothing about Julia. In order to simplify their experience she would like to avoid the complication of explaining packages.
- An employee in the IT-department is making a program for the sales department. He/she does not want the program to have the complication of answering questions about installing packages. This can of course be done without this new feature, but this feature could greatly reduce the number of lines of code needed to do this, which would hopefully both save time and reduce the probability of bugs.
Scenarios 1 and 2 would benefit from something simple that can be done either just before Julia starts or just after. @KristofferC s suggestion of an env variable would be just perfect for this, you can put it in your startup.jl , you can set it in your .bashrc , you can use it with the -i -e commandline options, you can type it manually in the REPL and a lot more. To use it in the example given by @gitboy16 you would write something like:
ENV["JULIA_PKG_USING_AUTOINSTALL"] = "yes"
using DataFrames
import CSV
Like @IanButterworth , I also get a gut reaction that creating this feature could have some bad consequences. Maybe Julia could get the blame for a bad user experience caused by this. Would it be a good idea to explicitly warn about the dangers of using the feature in the documentation of it?
I also want to say that I am not sure that I would use this feature personally, I like the current behaviour, but I do see situations where others could find it useful.
The only reason why I prefer a macro over an environment variable is because it forces the user to add it to the script/code and makes it clear to whoever is reading the code. Anyway feel free to close if you don't care about it.