Skip to content

Set temporary env whenever Julia is started with --project=@temp #51149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Command-line option changes
* Enabling or disabling color text in Julia can now be controlled with the
[`NO_COLOR`](https://no-color.org/) or [`FORCE_COLOR`](https://force-color.org/) environment
variables. ([#53742]).
* `--project=@temp` starts Julia with a temporary environment.

Multi-threading changes
-----------------------
Expand Down
1 change: 1 addition & 0 deletions base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ function load_path_expand(env::AbstractString)::Union{String, Nothing}
# if you put a `@.` in LOAD_PATH manually, it's expanded late
env == "@" && return active_project(false)
env == "@." && return current_project()
env == "@temp" && return mktempdir()
env == "@stdlib" && return Sys.STDLIB
if startswith(env, "@script")
if @isdefined(PROGRAM_FILE)
Expand Down
2 changes: 1 addition & 1 deletion doc/src/manual/command-line-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ The following is a complete list of command-line switches available when launchi
|`-v`, `--version` |Display version information|
|`-h`, `--help` |Print command-line options (this message)|
|`--help-hidden` |Print uncommon options not shown by `-h`|
|`--project[={<dir>\|@.}]` |Set `<dir>` as the active project/environment. The default `@.` option will search through parent directories until a `Project.toml` or `JuliaProject.toml` file is found.|
|`--project[={<dir>\|@temp\|@.}]` |Set `<dir>` as the active project/environment. Or, create a temporary environment with `@temp`. The default `@.` option will search through parent directories until a `Project.toml` or `JuliaProject.toml` file is found.|
|`-J`, `--sysimage <file>` |Start up with the given system image file|
|`-H`, `--home <dir>` |Set location of `julia` executable|
|`--startup-file={yes*\|no}` |Load `JULIA_DEPOT_PATH/config/startup.jl`; if [`JULIA_DEPOT_PATH`](@ref JULIA_DEPOT_PATH) environment variable is unset, load `~/.julia/config/startup.jl`|
Expand Down
3 changes: 2 additions & 1 deletion src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ static const char opts[] =
" --help-hidden Print uncommon options not shown by `-h`\n\n"

// startup options
" --project[={<dir>|@.}] Set <dir> as the active project/environment.\n"
" --project[={<dir>|@temp|@.}] Set <dir> as the active project/environment.\n"
" Or, create a temporary environment with `@temp`\n"
" The default @. option will search through parent\n"
" directories until a Project.toml or JuliaProject.toml\n"
" file is found.\n"
Expand Down
4 changes: 4 additions & 0 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
@test expanded == readchomp(addenv(`$exename -e 'println(Base.active_project())'`, "JULIA_PROJECT" => "@foo", "HOME" => homedir()))
end

# handling of `@temp` in --project and JULIA_PROJECT
@test tempdir() == readchomp(`$exename --project=@temp -e 'println(Base.active_project())'`)[1:lastindex(tempdir())]
@test tempdir() == readchomp(addenv(`$exename -e 'println(Base.active_project())'`, "JULIA_PROJECT" => "@temp", "HOME" => homedir()))[1:lastindex(tempdir())]

# --quiet, --banner
let p = "print((Base.JLOptions().quiet, Base.JLOptions().banner))"
@test read(`$exename -e $p`, String) == "(0, -1)"
Expand Down