Feature request: --project=@script_dir

I’d like to run a command like

julia --project=@script_dir long/path/to/my/package/src/script.jl

rather than what I currently have to use, where the path is repeated verbatim

julia --project=long/path/to/my/package long/path/to/my/package/src/script.jl

Another inconvenient workaround is using Pkg within the script to activate the environment of @__DIR__ or the parent path thereof.

The proposed behavior is that julia wil recursively search the user-supplied script_dir and parent directories until Project.toml is found and use that as the virtual environment. What do you think?

1 Like

Maybe try @scriptdir? Allow `--project=@scriptdir` for easier co-packaging of scripts and p… by Keno · Pull Request #50864 · JuliaLang/julia · GitHub

Edit: ah maybe it’s @script: Rename @scriptdir to @script, and look for environments in parent directories · Issue #53352 · JuliaLang/julia · GitHub

Thanks for the links! I vaguely remember reading about it somewhere, but I couldn’t find any information about it when I ran julia -h today to look at the command line option list.

I just tried @script and it didn’t work. Looks like there’s an open issue about it:

This should be fixed and now that my attention is called to the PR to fix and test it, I’ll make sure those get merged (they seem to be stalled for lack of review). In the meantime, if you put this at the top of your script file, it has the same effect:

push!(empty!(LOAD_PATH), @__DIR__)
7 Likes