Skip to content

Commit a910824

Browse files
authored
Merge pull request #40 from DilumAluthge-forks/dpa/warn-unexpected-params
Print a `@warn` message if the user provides an unsupported kwarg
2 parents 7b6c453 + 7576c11 commit a910824

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/slurmmanager.jl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,60 @@ function _new_environment_additions(params_env::Dict{String, String})
122122
return env2
123123
end
124124

125+
function warn_if_unexpected_params(params::Dict)
126+
params_that_we_support = [:dir, :exename, :exeflags]
127+
upstreams_defaults = Distributed.default_addprocs_params()
128+
for (k, v) in pairs(params)
129+
if k == :env
130+
# We special-case `:env`, because our support status depends on the Julia version
131+
if v == []
132+
# Either the user didn't provide the `:env` kwarg,
133+
# or the user provided `env=[]`.
134+
#
135+
# Either way, in this case, we don't print a log message.
136+
# @debug "k == :env and v == []" k v
137+
else
138+
# In this case, the user has provided the `:env` kwarg, and it is nonempty.
139+
if Base.VERSION < v"1.6.0"
140+
@warn "The user provided the `env` kwarg, but SlurmClusterManager.jl's support for the `env` kwarg requires Julia 1.6 or later" Base.VERSION
141+
else
142+
# Here, the Julia version is >= 1.6, so we do support `:env`,
143+
# and there is no problem.
144+
end
145+
end
146+
elseif k in params_that_we_support
147+
# We support this param, so no problem.
148+
else
149+
# We don't support this param.
150+
151+
# So let's see if this is something that Distributed.jl would provide by default.
152+
if haskey(upstreams_defaults, k)
153+
# This is a param that Distributed.jl would provide by default.
154+
# So now the question is: is this the default value provided by Distributed.jl,
155+
# or did the user override the value?
156+
this_is_upstreams_default_value = v == upstreams_defaults[k]
157+
if this_is_upstreams_default_value
158+
# So now the question is: is this the default value provided by Distributed.jl,
159+
# This IS the default value provided by Distributed.jl, so we won't print a log message.
160+
# @debug "" k v this_is_upstreams_default_value
161+
else
162+
# This is NOT the default value provided by Distributed.jl.
163+
# So the user must have overriden the value.
164+
@warn "SlurmClusterManager.jl does not support this kwarg: $(k)" kwarg=k value=v
165+
end
166+
else
167+
# This is not a param that Distributed.jl provides by default.
168+
@warn "SlurmClusterManager.jl does not support this custom kwarg: $(k)" kwarg=k value=v
169+
end
170+
end
171+
end
172+
return nothing
173+
end
174+
125175
function Distributed.launch(manager::SlurmManager, params::Dict, instances_arr::Array, c::Condition)
126176
try
177+
warn_if_unexpected_params(params)
178+
127179
exehome = params[:dir]
128180
exename = params[:exename]
129181
exeflags = params[:exeflags]

0 commit comments

Comments
 (0)