When creating a package, I often use dependencies that are purely for development and have nothing to do with my package’s functionality (e.g. Revise.jl, Debugger.jl, Infiltrator.jl. If I ever wanted to share my package, these unnecessary packages would be shared too unless I manually deleted them from the Project.toml.
Pipenv (for Python) makes a distinction between “dev” dependencies only needed for development ([dev-packages] in the Pipfile), and strictly necessary dependencies needed for running the project code ([packages]). A user can run pipenv install to install only the packages needed for running the code and ignore the “dev” packages. If they want to install the dev packages too, they can use pipenv install --dev.
I couldn’t find any similar functionality in the documentation for Pkg.jl. Can Pkg also distinguish between development and strictly necessary packages when installing a project environment?
Can all of that stuff go in test dependencies? Having the separate project and manifest for those seems to make sense and presumably you are doing development by editing/creating tests anyways?
Environments in Julia are nested, when working on a project you usually have access to both - package’s dependencies and dependencies in the enclosing environment (e.g. @v1.6):
(YourPackage) pkg> st
# prints dependencies of YourPackage
(YourPackage) pkg> activate. # switch to the default environment
Activating environment at `~/.julia/environments/v1.6/Project.toml`
(@v1.6) pkg> add Revise
# adding Revise to the enclosing environment
(@v1.6) pkg> activate . # switch back to the environment in the current directory
Activating environment at `...`
julia> using Revise
...
The way most people deal with this is to have all those dev packages, as you call them, installed in your Main environment ((@1.6), for example) and then create a new environment for your package ((@MyPkg)) . With this setup you have access to Revise and Debugger, and any other package you need to work on your package, but they are not part of the Project.toml file of your package.
So, technically, there are two separate @MyPkg environments, one in environments folder and the other in dev/MyPkg folder? Is there a workflow description for this thing?
It’s documented in the Pkg.jl docs introduction here. Basically, when you start the REPL with julia --project, you have access to your 1.6 environment as well as your MyPackageproject.toml.
This issue is about how stuff insideMyPackage can’t see the 1.6project.toml
But no. There are not two MyPkg environments. People above this post have been referring to the Main environment (@v1.6 for example) and your package’s environment @MyPkg. The packages that are installed in the main environment are accessible from all julia sessions no matter what other environment you have active.
You can build your own custom stack pretty easily (as briefly mentioned above). For example, if you keep dev tools installed in devtools/Project.toml as follows:
To handle this automatically I recommend using direnv. I wrote a blog post about direnv and Julia which has some more examples of this (and other nice things you can do with direnv together with Julia).