Skip to content

Commit 0bde517

Browse files
authored
Refactoring
1 parent bb9d511 commit 0bde517

File tree

1 file changed

+15
-35
lines changed

1 file changed

+15
-35
lines changed

src/slurmmanager.jl

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,13 @@ elseif Base.VERSION < v"1.6.0"
7373
end
7474

7575
function _new_environment_additions(params_env::Dict{String, String})
76-
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-
81-
for (name, value) in pairs(params_env)
82-
# For each key-value mapping in `params[:env]`, we respect that mapping and we pass it
83-
# to the workers.
84-
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]
76+
# For each key-value mapping in `params[:env]`, we respect that mapping and we pass it
77+
# to the workers.
78+
env2 = copy(params_env)
79+
80+
for name in ["JULIA_PROJECT", "JULIA_LOAD_PATH", "JULIA_DEPOT_PATH"]
81+
if haskey(env2, name)
82+
@debug "The user did specify $(name)=$(env2[name]) in the `env` kwarg to `addprocs()`. That value will be passed to the workers."
9983
end
10084
end
10185

@@ -108,31 +92,31 @@ function _new_environment_additions(params_env::Dict{String, String})
10892
# variable but DOES start Julia with either `julia --project` or `julia --project=something`.
10993
#
11094
# https://github.com/kleinhenz/SlurmClusterManager.jl/issues/16
111-
if !user_did_specify_JULIA_PROJECT
112-
# Important note: We use Base.active_project() here.
95+
if !haskey(env2, "JULIA_PROJECT")
96+
# Important note: We use Base.active_project() here.
11397
# We do NOT use Base.ACTIVE_PROJECT[], because it is not part of Julia's public API.
11498
env2["JULIA_PROJECT"] = Base.active_project()
115-
@debug "Passing JULIA_PROJECT=Base.active_project() to the workers" env2["JULIA_PROJECT"]
99+
@debug "Passing JULIA_PROJECT=Base.active_project()=$(env2["JULIA_PROJECT"]) to the workers"
116100
end
117101

118102
# If the user did not specify `JULIA_LOAD_PATH` in `params[:env]`, then we pass
119103
# JULIA_LOAD_PATH=Base.LOAD_PATH to the workers.
120104
#
121105
# This is a bit of an edge case, and I doubt that most users will need it.
122106
# But upstream Distributed.jl does it, so we might as well do it too.
123-
if !user_did_specify_JULIA_LOAD_PATH
107+
if !haskey(env2, "JULIA_LOAD_PATH")
124108
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"]
109+
@debug "Passing JULIA_LOAD_PATH=Base.LOAD_PATH=$(env2["JULIA_LOAD_PATH"]) to the workers"
126110
end
127111

128112
# If the user did not specify `JULIA_DEPOT_PATH` in `params[:env]`, then we pass
129113
# JULIA_DEPOT_PATH=Base.DEPOT_PATH to the workers.
130114
#
131115
# This is a bit of an edge case, and I doubt that most users will need it.
132116
# But upstream Distributed.jl does it, so we might as well do it too.
133-
if !user_did_specify_JULIA_DEPOT_PATH
117+
if !haskey(env2, "JULIA_DEPOT_PATH")
134118
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"]
119+
@debug "Passing JULIA_DEPOT_PATH=Base.DEPOT_PATH=$(env2["JULIA_DEPOT_PATH"]) to the workers"
136120
end
137121

138122
return env2
@@ -147,12 +131,8 @@ function launch(manager::SlurmManager, params::Dict, instances_arr::Array, c::Co
147131
_srun_cmd_without_env = `srun -D $exehome $exename $exeflags --worker`
148132

149133
@static if Base.VERSION >= v"1.6.0"
150-
env_arr = params[:env]
151134
# Pass the key-value pairs from `params[:env]` to the `srun` command:
152-
env2 = Dict{String,String}()
153-
for (name, value) in pairs(Dict{String,String}(env_arr))
154-
env2[name] = value
155-
end
135+
env2 = _new_environment_additions(Dict{String,String}(params[:env]))
156136
srun_cmd_with_env = addenv(_srun_cmd_without_env, env2)
157137
else
158138
# See discussion above for why we don't support this functionality on Julia 1.5 and earlier.

0 commit comments

Comments
 (0)