Skip to content

Commit a60f22e

Browse files
authored
Rename at-scriptdir project argument to at-script and search upwards for Project.toml (#53356)
Closes #53352 I also noticed it wasn't mentioned in the NEWs.md and so I added it . Reconciling the relative path behavior, with the search upwads behavour requested in #53352 is a thing.
1 parent 58ed793 commit a60f22e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ difference between defining a `main` function and executing the code directly at
6868
* The `--compiled-modules` and `--pkgimages` flags can now be set to `existing`, which will
6969
cause Julia to consider loading existing cache files, but not to create new ones ([#50586]
7070
and [#52573]).
71+
* The `--project` argument now accepts `@script` to give a path to a directory with a Project.toml relative to the passed script file. `--project=@script/foo` for the `foo` subdirectory. If no path is given after (i.e. `--project=@script`) then (like `--project=@.`) the directory and its parents are searched for a Project.toml ([#50864] and [#53352])
7172

7273
Multi-threading changes
7374
-----------------------

base/initdefs.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ function load_path_expand(env::AbstractString)::Union{String, Nothing}
278278
env == "@" && return active_project(false)
279279
env == "@." && return current_project()
280280
env == "@stdlib" && return Sys.STDLIB
281-
if startswith(env, "@scriptdir")
281+
if startswith(env, "@script")
282282
if @isdefined(PROGRAM_FILE)
283283
dir = dirname(PROGRAM_FILE)
284284
else
@@ -289,7 +289,12 @@ function load_path_expand(env::AbstractString)::Union{String, Nothing}
289289
end
290290
dir = dirname(ARGS[1])
291291
end
292-
return abspath(replace(env, "@scriptdir" => dir))
292+
if env == "@script" # complete match, not startswith, so search upwards
293+
return current_project(dir)
294+
else
295+
# starts with, so assume relative path is after
296+
return abspath(replace(env, "@script" => dir))
297+
end
293298
end
294299
env = replace(env, '#' => VERSION.major, count=1)
295300
env = replace(env, '#' => VERSION.minor, count=1)

0 commit comments

Comments
 (0)