Skip to content

Commit 2a981b8

Browse files
committed
feat: set temporary env whenever Julia is started with --project=--temp
- Update relevant docs. - Add tests for `--project=--temp` and `JULIA_PROJECT="--temp"`. This makes it convenient to start and run Julia in a temporary environment. This brings `Pkg.activate(; temp=true)` functionality to cmdline.
1 parent ec2f1d3 commit 2a981b8

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

base/initdefs.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ function init_active_project()
238238
set_active_project(
239239
project === nothing ? nothing :
240240
project == "" ? nothing :
241-
startswith(project, "@") ? load_path_expand(project) : abspath(expanduser(project))
241+
startswith(project, "@") ? load_path_expand(project) :
242+
project == "--temp" ? mktempdir() : abspath(expanduser(project))
242243
)
243244
end
244245

doc/src/manual/command-line-interface.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ The following is a complete list of command-line switches available when launchi
9595
|`-v`, `--version` |Display version information|
9696
|`-h`, `--help` |Print command-line options (this message).|
9797
|`--help-hidden` |Uncommon options not shown by `-h`|
98-
|`--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.|
98+
|`--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.|
9999
|`-J`, `--sysimage <file>` |Start up with the given system image file|
100100
|`-H`, `--home <dir>` |Set location of `julia` executable|
101101
|`--startup-file={yes*\|no}` |Load `JULIA_DEPOT_PATH/config/startup.jl`; if `JULIA_DEPOT_PATH` environment variable is unset, load `~/.julia/config/startup.jl`|

src/jloptions.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ static const char opts[] =
102102
" --help-hidden Uncommon options not shown by `-h`\n\n"
103103

104104
// startup options
105-
" --project[={<dir>|@.}] Set <dir> as the active project/environment\n"
105+
" --project[={<dir>|--temp|@.}]\n"
106+
" Set <dir> as the active project/environment.\n"
107+
" Or, create a temporary environment with `--temp`\n"
106108
" -J, --sysimage <file> Start up with the given system image file\n"
107109
" -H, --home <dir> Set location of `julia` executable\n"
108110
" --startup-file={yes*|no} Load `JULIA_DEPOT_PATH/config/startup.jl`; if `JULIA_DEPOT_PATH`\n"

test/cmdlineargs.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
225225
@test expanded == readchomp(addenv(`$exename -e 'println(Base.active_project())'`, "JULIA_PROJECT" => "@foo", "HOME" => homedir()))
226226
end
227227

228+
# handling of temp in --project and JULIA_PROJECT
229+
@test occursin(tempdir(), readchomp(`$exename --project=--temp -e 'println(Base.active_project())'`))
230+
@test occursin(tempdir(), readchomp(addenv(`$exename -e 'println(Base.active_project())'`, "JULIA_PROJECT" => "--temp", "HOME" => homedir())))
231+
228232
# --quiet, --banner
229233
let p = "print((Base.JLOptions().quiet, Base.JLOptions().banner))"
230234
@test read(`$exename -e $p`, String) == "(0, -1)"

0 commit comments

Comments
 (0)