I have many script-style small projects that I frequently need to switch between. Currently, I’m using the following two-step process to “launch” a project:
> julia --project=path/to/project
julia> includet("path/to/project/startup.jl")
# Now I'm in the state where I want to be:
# a fresh REPL with `path/to/project/Project.toml`
# as environment and all the content of `startup.jl`
# preloaded.
Since I have to do this often and often under time pressure (e.g. live demo), it would be really nice if these two steps could be broken down to one. Does Julia have a mechanism for this?
Some options I have considered and why they aren’t quite what I want:
Launch Julia using
julia --project=path/to/project -e "include(\"path/to/project/startup.jl\")"
Doesn’t drop me into REPL mode.
Add something like this to the global startup.jl:
using Pkg
startup_jl = joinpath(Pkg.project().path, "startup.jl")
if isfile(startup_jl)
includet(startup_jl)
end
Not self-contained.
Activate the correct environment at the beginning of path/to/project/startup.jl.
It’s still a two-step process: I still need to first launch julia (now without args), then I need to do includet("path/to/project/startup.jl").
What I mean by “not self-contained” is that I can’t then send my projects to someone else and expect my scripts to behave properly on their machine (without configure their startup.jl first).
I don’t think I was clear. I think it’s the solution, and it’s a ultimately good thing that you can’t trivially make a malicious project that executes code just by invoking julia --project=foo without loading any files or packages.
What sort of stuff do you have in these per-project startup.jls?
Personally, I always have a Makefile that organizes development tasks (make test, make docs). This always includes make devrepl, which loads up a customized REPL for interactive testing and working on the documentation.