Skip to content

Commit af51bcc

Browse files
Include default user depot when JULIA_DEPOT_PATH has leading empty entry (#56195)
1 parent c4effc3 commit af51bcc

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

base/initdefs.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,23 @@ function init_depot_path()
112112

113113
# otherwise, populate the depot path with the entries in JULIA_DEPOT_PATH,
114114
# expanding empty strings to the bundled depot
115-
populated = false
116-
for path in eachsplit(str, Sys.iswindows() ? ';' : ':')
115+
pushfirst_default = true
116+
for (i, path) in enumerate(eachsplit(str, Sys.iswindows() ? ';' : ':'))
117117
if isempty(path)
118118
append_bundled_depot_path!(DEPOT_PATH)
119119
else
120120
path = expanduser(path)
121121
path in DEPOT_PATH || push!(DEPOT_PATH, path)
122-
populated = true
122+
if i == 1
123+
# if a first entry is given, don't add the default depot at the start
124+
pushfirst_default = false
125+
end
123126
end
124127
end
125128

126129
# backwards compatibility: if JULIA_DEPOT_PATH only contains empty entries
127130
# (e.g., JULIA_DEPOT_PATH=':'), make sure to use the default depot
128-
if !populated
131+
if pushfirst_default
129132
pushfirst!(DEPOT_PATH, joinpath(homedir(), ".julia"))
130133
end
131134
else

doc/src/manual/environment-variables.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,19 @@ environment variable or if it must have a value, set it to the string `:`.
130130

131131
### [`JULIA_DEPOT_PATH`](@id JULIA_DEPOT_PATH)
132132

133-
The [`JULIA_DEPOT_PATH`](@ref JULIA_DEPOT_PATH) environment variable is used to populate the global Julia
134-
[`DEPOT_PATH`](@ref) variable, which controls where the package manager, as well
135-
as Julia's code loading mechanisms, look for package registries, installed
136-
packages, named environments, repo clones, cached compiled package images,
137-
configuration files, and the default location of the REPL's history file.
133+
The [`JULIA_DEPOT_PATH`](@ref JULIA_DEPOT_PATH) environment variable is used to populate the
134+
global Julia [`DEPOT_PATH`](@ref) variable, which controls where the package manager, as well
135+
as Julia's code loading mechanisms, look for package registries, installed packages, named
136+
environments, repo clones, cached compiled package images, configuration files, and the default
137+
location of the REPL's history file.
138138

139139
Unlike the shell `PATH` variable but similar to [`JULIA_LOAD_PATH`](@ref JULIA_LOAD_PATH),
140-
empty entries in [`JULIA_DEPOT_PATH`](@ref JULIA_DEPOT_PATH) are expanded to the default
141-
value of `DEPOT_PATH`, excluding the user depot. This allows easy overriding of the user
142-
depot, while still retaining access to resources that are bundled with Julia, like cache
143-
files, artifacts, etc. For example, to switch the user depot to `/foo/bar` just do
140+
empty entries in [`JULIA_DEPOT_PATH`](@ref JULIA_DEPOT_PATH) have special behavior:
141+
- At the end, it is expanded to the default value of `DEPOT_PATH`, *excluding* the user depot.
142+
- At the start, it is expanded to the default value of `DEPOT_PATH`, *including* the user depot.
143+
This allows easy overriding of the user depot, while still retaining access to resources that
144+
are bundled with Julia, like cache files, artifacts, etc. For example, to switch the user depot
145+
to `/foo/bar` use a trailing `:`
144146
```sh
145147
export JULIA_DEPOT_PATH="/foo/bar:"
146148
```
@@ -150,6 +152,12 @@ resources will still be available. If you really only want to use the depot at `
150152
and not load any bundled resources, simply set the environment variable to `/foo/bar`
151153
without the trailing colon.
152154

155+
To append a depot at the end of the full default list, including the default user depot, use a
156+
leading `:`
157+
```sh
158+
export JULIA_DEPOT_PATH=":/foo/bar"
159+
```
160+
153161
There are two exceptions to the above rule. First, if [`JULIA_DEPOT_PATH`](@ref
154162
JULIA_DEPOT_PATH) is set to the empty string, it expands to an empty `DEPOT_PATH` array. In
155163
other words, the empty string is interpreted as a zero-element array, not a one-element

test/loading.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ end
731731
"" => [],
732732
"$s" => [default; bundled],
733733
"$tmp$s" => [tmp; bundled],
734-
"$s$tmp" => [bundled; tmp],
734+
"$s$tmp" => [default; bundled; tmp],
735735
)
736736
for (env, result) in pairs(cases)
737737
script = "DEPOT_PATH == $(repr(result)) || error(\"actual depot \" * join(DEPOT_PATH,':') * \" does not match expected depot \" * join($(repr(result)), ':'))"

0 commit comments

Comments
 (0)