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

Allow for specifying shared named environments on Julia start #35354

Closed
oschulz opened this issue Apr 3, 2020 · 12 comments
Closed

Allow for specifying shared named environments on Julia start #35354

oschulz opened this issue Apr 3, 2020 · 12 comments

Comments

@oschulz
Copy link
Contributor

oschulz commented Apr 3, 2020

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 .

@davidanthoff
Copy link
Contributor

It would be awesome if the @ that already works in the REPL for shared env worked for --project and JULIA_PROJECT as well.

@fredrikekre
Copy link
Member

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.

@oschulz
Copy link
Contributor Author

oschulz commented Apr 3, 2020

Thanks, @fredrikekre !

@davidanthoff
Copy link
Contributor

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.

@oschulz
Copy link
Contributor Author

oschulz commented Apr 3, 2020

I guess we can assume few (or no) people will use directory names starting with "@" :-)

@StefanKarpinski
Copy link
Member

Yes, it would be good if we supported this consistently.

@oschulz
Copy link
Contributor Author

oschulz commented May 15, 2020

Would @fredrikekre 's solution be acceptable?

@oschulz
Copy link
Contributor Author

oschulz commented Jul 29, 2020

@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.

@fredrikekre
Copy link
Member

Go ahead. You can put me as co-author if you think it matters.

@oschulz
Copy link
Contributor Author

oschulz commented Sep 6, 2020

Ok, I'll see that I get this in for v1.6.

@oschulz
Copy link
Contributor Author

oschulz commented Mar 14, 2021

Sorry, kinda missed that v1.6 window (by a lot), due to overload ...

@oschulz
Copy link
Contributor Author

oschulz commented Mar 14, 2021

Sorry this took so long, for such a tiny thing: #40025

@musm musm closed this as completed Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants