Project-specific startup.jl file

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\")"
    

    :no_good_man: 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
    

    :no_good_man: Not self-contained.

  • Activate the correct environment at the beginning of path/to/project/startup.jl.
    :no_good_man: 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").

You could make local startup.jl files work via code loading in your global config/startup.jl

That’s this solution, no?

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?

I think you might be looking for

julia --project=path/to/project -ie 'include("path/to/project/startup.jl")"'

This is the (very) short form of --interactive -e.

1 Like

Small scripts wrapped in functions.

Yup, this will do. Thank you!

julia -L my_script.jl -i
2 Likes

What does -f do? I don’t see it documented in julia --help

Sorry, I managed to copy the letter wrong, was supposed to be L, not f, I edited the post to avoid confusion:

-L, --load <file>	Load <file> immediately on all processors
1 Like

Sweet, that’s technically even better except I assume files loaded with -l won’t be Reviseable?

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.