When working on a package
Foo, I often have to type commands like
] dev .
] activate .
F = Foo
This, on a daily basis, means that I have to type a lot when switching between packages and when Julia occasionally has to shut down or shuts down due to an error.
I figured that I could, for example, add an
init.jl file to a package with
F = Foo
and load this automatically from
file = joinpath(pwd(), "init.jl")
Alternatively, I could avoid adding an
init.jl file to all the projects I work on, and add the content of
startup.jl directly with some changes to make it more dynamic.
However, this is not very versatile. It could be that I don’t want to activate the package. Then, I could start doing things like
$ export ACTIVATE=true; julia
startup.jl do something like
if "ACTIVATE" in keys(ENV) && ENV["ACTIVATE"] == "true"
However, this feels like a workaround. So my question is: are there better approaches for this problem?
In a given environment, you only have to use
Pkg.develop once. After that, this information is written to the manifest. No need to do it every session.
You can call
--project to select (activate) a particular environment. See
julia --help or the docs.
I am not sure why you want
Pkg.test every time you are
I added Pkg.develop as default for two reasons:
- It can be required multiple times for a package if you’re switching between PRs. For example, if I’m working on a PR for Memoize.jl, then I’ll use my development version.When working on another package again, I’ll install the normal Memoize again.
- I like to store all my git projects under
~/git, whether or not I have loaded them via
development(path="."). Then, when adding a package to the manifest and project, it is required to load the package again, or Julia complains about missing dependencies.
Pkg.develop doesn’t take too much time, I figured that it can save me some time and typing overall if I just run it each time I start Julia.
The project flag is a good suggestion. That can save some typing.
I am not sure I understand what you are doing, but separate environments can just use different versions of the same package.
Pkg will take care of this automatically, you do not need to do anything special. See Managing Packages.
I probably do not have a developing workflow as complex as yours, but what I do is to go to the directory of the package and start Julia with
julia --project. Then, in Julia, I type, for example:
julia> devPDBTools=(); using Revise; using PDBTools
Next time, since that gets stored into the history, I only type
devPDB and tab, and I have my developing session setup again, without having any extra file.
@Tamas_Papp For most situations that is indeed enough, but I sometimes also work on script projects without an environment and Pluto scripts. Still, good suggestions you are making. I did not consider --project yet, and should possibly add more environments to scripts.
@lmiq Haha, great hack! Nice one! The history search (CTRL + R) is not the smoothest and your tab suggestion sounds great. I’m gonna use that
I just noticed that we could also use the
-i flag as well. For example,
julia -ie 'using Revise; using PDBTools'
will drop you in a REPL where Revise and PDBTools are active. I find this very useful in combination with fuzzy finders like https://github.com/junegunn/fzf, and thought maybe you too