Skip to content

Commit

Permalink
feat: add @temp to the DEFAULT_LOAD_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
ven-k committed Feb 13, 2024
1 parent 75a85a6 commit f8e7121
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ end
# entries starting with `@` are named environments:
# - the first three `#`s in a named environment are replaced with version numbers
# - `@stdlib` is a special name for the standard library and expands to its path
# - `@temp` expands to a temporary directory path

# if you want a current env setup, use direnv and
# have your .envrc do something like this:
Expand All @@ -131,21 +132,23 @@ end
# this will inherit an existing JULIA_LOAD_PATH value or if there is none, leave
# a trailing empty entry in JULIA_LOAD_PATH which will be replaced with defaults.

const DEFAULT_LOAD_PATH = ["@", "@v#.#", "@stdlib"]
const DEFAULT_LOAD_PATH = ["@", "@temp", "@v#.#", "@stdlib"]

"""
LOAD_PATH
An array of paths for `using` and `import` statements to consider as project
environments or package directories when loading code. It is populated based on
the [`JULIA_LOAD_PATH`](@ref JULIA_LOAD_PATH) environment variable if set;
otherwise it defaults to `["@", "@v#.#", "@stdlib"]`. Entries starting with `@`
otherwise it defaults to `["@", "@temp", "@v#.#", "@stdlib"]`. Entries starting with `@`
have special meanings:
- `@` refers to the "current active environment", the initial value of which is
initially determined by the [`JULIA_PROJECT`](@ref JULIA_PROJECT) environment
variable or the `--project` command-line option.
- `@temp` expands to a temporary directory.
- `@stdlib` expands to the absolute path of the current Julia installation's
standard library directory.
Expand Down
6 changes: 5 additions & 1 deletion test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ end

# Base.active_project when version directory exist in depot, but contains no project file
mktempdir() do dir
vdir = Base.DEFAULT_LOAD_PATH[2]
vdir = Base.DEFAULT_LOAD_PATH[3]
vdir = replace(vdir, "#" => VERSION.major, count = 1)
vdir = replace(vdir, "#" => VERSION.minor, count = 1)
vdir = replace(vdir, "#" => VERSION.patch, count = 1)
Expand All @@ -699,6 +699,10 @@ mktempdir() do dir
@test success(cmd)
end

@testset "`@temp` in `DEFAULT_LOAD_PATH`" begin
@test tempdir() == Base.load_path_expand(Base.DEFAULT_LOAD_PATH[2])[1:lastindex(tempdir())]
end

@testset "expansion of JULIA_LOAD_PATH" begin
s = Sys.iswindows() ? ';' : ':'
tmp = "/this/does/not/exist"
Expand Down

0 comments on commit f8e7121

Please sign in to comment.