Skip to content
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

Rename at-scriptdir project argument to at-script and search upwards for Project.toml #53356

Merged
merged 1 commit into from
May 28, 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 HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ difference between defining a `main` function and executing the code directly at
* The `--compiled-modules` and `--pkgimages` flags can now be set to `existing`, which will
cause Julia to consider loading existing cache files, but not to create new ones ([#50586]
and [#52573]).
* 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])

Multi-threading changes
-----------------------
Expand Down
9 changes: 7 additions & 2 deletions base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function load_path_expand(env::AbstractString)::Union{String, Nothing}
env == "@" && return active_project(false)
env == "@." && return current_project()
env == "@stdlib" && return Sys.STDLIB
if startswith(env, "@scriptdir")
if startswith(env, "@script")
if @isdefined(PROGRAM_FILE)
dir = dirname(PROGRAM_FILE)
else
Expand All @@ -289,7 +289,12 @@ function load_path_expand(env::AbstractString)::Union{String, Nothing}
end
dir = dirname(ARGS[1])
end
return abspath(replace(env, "@scriptdir" => dir))
if env == "@script" # complete match, not startswith, so search upwards
return current_project(dir)
else
# starts with, so assume relative path is after
return abspath(replace(env, "@script" => dir))
end
end
env = replace(env, '#' => VERSION.major, count=1)
env = replace(env, '#' => VERSION.minor, count=1)
Expand Down