Skip to content

Commit 1e4ca44

Browse files
committed
By default, propagate Base.active_project(), Base.LOAD_PATH, and Base.DEPOT_PATH to the workers (but allow the user to override that behavior by specifying JULIA_{PROJECT,LOAD_PATH,DEPOT_PATH} in params[:env])
1 parent 83fe844 commit 1e4ca44

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/slurmmanager.jl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,67 @@ end
7474

7575
function _new_environment_additions(params_env::Dict{String, String})
7676
env2 = Dict{String, String}()
77+
user_did_specify_JULIA_PROJECT = false
78+
user_did_specify_JULIA_LOAD_PATH = false
79+
user_did_specify_JULIA_DEPOT_PATH = false
80+
7781
for (name, value) in pairs(params_env)
7882
# For each key-value mapping in `params[:env]`, we respect that mapping and we pass it
7983
# to the workers.
8084
env2[name] = value
85+
86+
# If the user did specify `JULIA_{PROJECT,LOAD_PATH,DEPOT_PATH}` in `params[:env]`, then
87+
# we respect that value, and we pass it to the workers.
88+
if name == "JULIA_PROJECT"
89+
user_did_specify_JULIA_PROJECT = true
90+
@debug "The user did specify a value for JULIA_PROJECT in the `env` kwarg to `addprocs()`; that value will be passed to the workers" env2[JULIA_PROJECT]
91+
end
92+
if name == "JULIA_LOAD_PATH"
93+
user_did_specify_JULIA_LOAD_PATH = true
94+
@debug "The user did specify a value for JULIA_LOAD_PATH in the `env` kwarg to `addprocs()`; that value will be passed to the workers" env2[JULIA_LOAD_PATH]
95+
end
96+
if name == "JULIA_DEPOT_PATH"
97+
user_did_specify_JULIA_DEPOT_PATH = true
98+
@debug "The user did specify a value for JULIA_DEPOT_PATH in the `env` kwarg to `addprocs()`; that value will be passed to the workers" env2[JULIA_DEPOT_PATH]
99+
end
81100
end
101+
102+
directory_separator = Sys.iswindows ? ';' : ':'
103+
104+
# If the user did not specify `JULIA_PROJECT` in `params[:env]`, then we pass
105+
# JULIA_PROJECT=Base.active_project() to the workers.
106+
#
107+
# This use case is commonly hit when the user does NOT set the `JULIA_PROJECT` environment
108+
# variable but DOES start Julia with either `julia --project` or `julia --project=something`.
109+
#
110+
# https://github.com/kleinhenz/SlurmClusterManager.jl/issues/16
111+
if !user_did_specify_JULIA_PROJECT
112+
# Important note: We use Base.active_project() here.
113+
# We do NOT use Base.ACTIVE_PROJECT[], because it is not part of Julia's public API.
114+
env2["JULIA_PROJECT"] = Base.active_project()
115+
@debug "Passing JULIA_PROJECT=Base.active_project() to the workers" env2["JULIA_PROJECT"]
116+
end
117+
118+
# If the user did not specify `JULIA_LOAD_PATH` in `params[:env]`, then we pass
119+
# JULIA_LOAD_PATH=Base.LOAD_PATH to the workers.
120+
#
121+
# This is a bit of an edge case, and I doubt that most users will need it.
122+
# But upstream Distributed.jl does it, so we might as well do it too.
123+
if !user_did_specify_JULIA_LOAD_PATH
124+
env2["JULIA_LOAD_PATH"] = join(Base.LOAD_PATH, directory_separator)
125+
@debug "Passing JULIA_LOAD_PATH=Base.LOAD_PATH to the workers" env2["JULIA_LOAD_PATH"]
126+
end
127+
128+
# If the user did not specify `JULIA_DEPOT_PATH` in `params[:env]`, then we pass
129+
# JULIA_DEPOT_PATH=Base.DEPOT_PATH to the workers.
130+
#
131+
# This is a bit of an edge case, and I doubt that most users will need it.
132+
# But upstream Distributed.jl does it, so we might as well do it too.
133+
if !user_did_specify_JULIA_DEPOT_PATH
134+
env2["JULIA_DEPOT_PATH"] = join(Base.DEPOT_PATH, directory_separator)
135+
@debug "Passing JULIA_DEPOT_PATH=Base.DEPOT_PATH to the workers" env2["JULIA_DEPOT_PATH"]
136+
end
137+
82138
return env2
83139
end
84140

0 commit comments

Comments
 (0)