To my knowledge, it's currently not possible to specify shared named environments via JULIA_PROJECT
or julia --project=...
without using the full path.
It would be very useful to have an equivalent to ] activate --shared ...
- both for convenience, but also because the full path may be system-dependent, making things complicated in a heterogeneous environment, esp. when access to remote systems is involved.
See also https://discourse.julialang.org/t/activating-a-shared-named-environment-via-julia-project/36975 .
It would be awesome if the @
that already works in the REPL for shared env worked for --project
and JULIA_PROJECT
as well.
diff --git a/base/initdefs.jl b/base/initdefs.jl
index 85a3d57..f90f5c5 100644
--- a/base/initdefs.jl
+++ b/base/initdefs.jl
@@ -217,7 +217,9 @@ function init_load_path()
HOME_PROJECT[] =
project === nothing ? nothing :
project == "" ? nothing :
- project == "@." ? current_project() : abspath(expanduser(project))
+ project == "@." ? current_project() :
+ startswith(project, '@') ? find_env_in_depot(project[2:end]) :
+ abspath(expanduser(project))
append!(empty!(LOAD_PATH), paths)
end
@@ -235,17 +237,7 @@ function load_path_expand(env::AbstractString)::Union{String, Nothing}
env = replace(env, '#' => VERSION.minor, count=1)
env = replace(env, '#' => VERSION.patch, count=1)
name = env[2:end]
- # look for named env in each depot
- for depot in DEPOT_PATH
- path = joinpath(depot, "environments", name)
- isdir(path) || continue
- for proj in project_names
- file = abspath(path, proj)
- isfile_casesensitive(file) && return file
- end
- end
- isempty(DEPOT_PATH) && return nothing
- return abspath(DEPOT_PATH[1], "environments", name, project_names[end])
+ return find_env_in_depot(name)
end
# otherwise, it's a path
path = abspath(env)
@@ -261,6 +253,20 @@ function load_path_expand(env::AbstractString)::Union{String, Nothing}
end
load_path_expand(::Nothing) = nothing
+# looks for named env in each depot
+function find_env_in_depot(name::String)
+ for depot in DEPOT_PATH
+ path = joinpath(depot, "environments", name)
+ isdir(path) || continue
+ for proj in project_names
+ file = abspath(path, proj)
+ isfile_casesensitive(file) && return file
+ end
+ end
+ isempty(DEPOT_PATH) && return nothing
+ return abspath(DEPOT_PATH[1], "environments", name, project_names[end])
+end
+
function active_project(search_load_path::Bool=true)
for project in (ACTIVE_PROJECT[], HOME_PROJECT[])
project == "@" && continue
Will break people that have directories with @
though.
Thanks, @fredrikekre !
Will break people that have directories with
@
though.
In the same way that it breaks them in the REPL case, right? And they can always use ./@myfolder
, right? While this might break some folks, I think it is actually more important that the REPL and command line and env var story is in sync, i.e. @foo
always does the same thing.
I guess we can assume few (or no) people will use directory names starting with "@" :-)
Yes, it would be good if we supported this consistently.
Would @fredrikekre 's solution be acceptable?
@fredrikekre , are you planning to make a PR? If you have your hands full, I can do it, but I don't want to claim credit for your solution.
Go ahead. You can put me as co-author if you think it matters.
Ok, I'll see that I get this in for v1.6.
Most helpful comment
It would be awesome if the
@
that already works in the REPL for shared env worked for--project
andJULIA_PROJECT
as well.