Skip to content

Print a @warn message if the user provides an unsupported kwarg #40

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

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/slurmmanager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,60 @@ function _new_environment_additions(params_env::Dict{String, String})
return env2
end

function warn_if_unexpected_params(params::Dict)
params_that_we_support = [:dir, :exename, :exeflags]
upstreams_defaults = Distributed.default_addprocs_params()
for (k, v) in pairs(params)
if k == :env
# We special-case `:env`, because our support status depends on the Julia version
if v == []
# Either the user didn't provide the `:env` kwarg,
# or the user provided `env=[]`.
#
# Either way, in this case, we don't print a log message.
# @debug "k == :env and v == []" k v
else
# In this case, the user has provided the `:env` kwarg, and it is nonempty.
if Base.VERSION < v"1.6.0"
@warn "The user provided the `env` kwarg, but SlurmClusterManager.jl's support for the `env` kwarg requires Julia 1.6 or later" Base.VERSION
else
# Here, the Julia version is >= 1.6, so we do support `:env`,
# and there is no problem.
end
end
elseif k in params_that_we_support
# We support this param, so no problem.
else
# We don't support this param.

# So let's see if this is something that Distributed.jl would provide by default.
if haskey(upstreams_defaults, k)
# This is a param that Distributed.jl would provide by default.
# So now the question is: is this the default value provided by Distributed.jl,
# or did the user override the value?
this_is_upstreams_default_value = v == upstreams_defaults[k]
if this_is_upstreams_default_value
# So now the question is: is this the default value provided by Distributed.jl,
# This IS the default value provided by Distributed.jl, so we won't print a log message.
# @debug "" k v this_is_upstreams_default_value
else
# This is NOT the default value provided by Distributed.jl.
# So the user must have overriden the value.
@warn "SlurmClusterManager.jl does not support this kwarg: $(k)" kwarg=k value=v
end
else
# This is not a param that Distributed.jl provides by default.
@warn "SlurmClusterManager.jl does not support this custom kwarg: $(k)" kwarg=k value=v
end
end
end
return nothing
end

function Distributed.launch(manager::SlurmManager, params::Dict, instances_arr::Array, c::Condition)
try
warn_if_unexpected_params(params)

exehome = params[:dir]
exename = params[:exename]
exeflags = params[:exeflags]
Expand Down