@@ -73,12 +73,52 @@ elseif Base.VERSION < v"1.6.0"
73
73
end
74
74
75
75
function _new_environment_additions (params_env:: Dict{String, String} )
76
- env2 = Dict {String, String} ()
77
- for (name, value) in pairs (params_env)
78
- # For each key-value mapping in `params[:env]`, we respect that mapping and we pass it
79
- # to the workers.
80
- env2[name] = value
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."
83
+ end
84
+ end
85
+
86
+ directory_separator = Sys. iswindows () ? ' ;' : ' :'
87
+
88
+ # If the user did not specify `JULIA_PROJECT` in `params[:env]`, then we pass
89
+ # JULIA_PROJECT=Base.active_project() to the workers.
90
+ #
91
+ # This use case is commonly hit when the user does NOT set the `JULIA_PROJECT` environment
92
+ # variable but DOES start Julia with either `julia --project` or `julia --project=something`.
93
+ #
94
+ # https://github.com/kleinhenz/SlurmClusterManager.jl/issues/16
95
+ if ! haskey (env2, " JULIA_PROJECT" )
96
+ # Important note: We use Base.active_project() here.
97
+ # We do NOT use Base.ACTIVE_PROJECT[], because it is not part of Julia's public API.
98
+ env2[" JULIA_PROJECT" ] = Base. active_project ()
99
+ @debug " Passing JULIA_PROJECT=Base.active_project()=$(env2[" JULIA_PROJECT" ]) to the workers"
81
100
end
101
+
102
+ # If the user did not specify `JULIA_LOAD_PATH` in `params[:env]`, then we pass
103
+ # JULIA_LOAD_PATH=Base.LOAD_PATH to the workers.
104
+ #
105
+ # This is a bit of an edge case, and I doubt that most users will need it.
106
+ # But upstream Distributed.jl does it, so we might as well do it too.
107
+ if ! haskey (env2, " JULIA_LOAD_PATH" )
108
+ env2[" JULIA_LOAD_PATH" ] = join (Base. LOAD_PATH , directory_separator)
109
+ @debug " Passing JULIA_LOAD_PATH=Base.LOAD_PATH=$(env2[" JULIA_LOAD_PATH" ]) to the workers"
110
+ end
111
+
112
+ # If the user did not specify `JULIA_DEPOT_PATH` in `params[:env]`, then we pass
113
+ # JULIA_DEPOT_PATH=Base.DEPOT_PATH to the workers.
114
+ #
115
+ # This is a bit of an edge case, and I doubt that most users will need it.
116
+ # But upstream Distributed.jl does it, so we might as well do it too.
117
+ if ! haskey (env2, " JULIA_DEPOT_PATH" )
118
+ env2[" JULIA_DEPOT_PATH" ] = join (Base. DEPOT_PATH , directory_separator)
119
+ @debug " Passing JULIA_DEPOT_PATH=Base.DEPOT_PATH=$(env2[" JULIA_DEPOT_PATH" ]) to the workers"
120
+ end
121
+
82
122
return env2
83
123
end
84
124
@@ -91,12 +131,8 @@ function launch(manager::SlurmManager, params::Dict, instances_arr::Array, c::Co
91
131
_srun_cmd_without_env = ` srun -D $exehome $exename $exeflags --worker`
92
132
93
133
@static if Base. VERSION >= v " 1.6.0"
94
- env_arr = params[:env ]
95
134
# Pass the key-value pairs from `params[:env]` to the `srun` command:
96
- env2 = Dict {String,String} ()
97
- for (name, value) in pairs (Dict {String,String} (env_arr))
98
- env2[name] = value
99
- end
135
+ env2 = _new_environment_additions (Dict {String,String} (params[:env ]))
100
136
srun_cmd_with_env = addenv (_srun_cmd_without_env, env2)
101
137
else
102
138
# See discussion above for why we don't support this functionality on Julia 1.5 and earlier.
0 commit comments