Skip to content
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

Ignore class of arguments #723

Open
burnout87 opened this issue Jan 3, 2025 · 1 comment
Open

Ignore class of arguments #723

burnout87 opened this issue Jan 3, 2025 · 1 comment
Assignees

Comments

@burnout87
Copy link
Collaborator

Following discussion in oda-hub/ontology#42 (comment)

An approach could be based on ignoring arguments that starts with underscore, by extending the function inside the instrument module

def set_pars_from_dic(self, arg_dic, verbose=False):
product_type = arg_dic.get('product_type', None)
if product_type is not None:
query_name = self.get_product_query_name(product_type)
query_obj = self.get_query_by_name(query_name)
# loop over the list of parameters for the requested query,
# but also of the instrument query and source query
param_list = (query_obj.parameters +
self.instrumet_query.parameters +
self.src_query.parameters)
else:
param_list = [par for _query in self._queries_list for par in _query.parameters]
updated_arg_dic = arg_dic.copy()
for par in param_list:
self.logger.info("before normalizing, set_pars_from_dic>> par: %s par.name: %s par.value: %s par_dic[par.name]: %s",
par, par.name, par.value, arg_dic.get(par.name, None))
# this is required because in some cases a parameter is set without a name (eg UserCatalog),
# or they don't have to set (eg scw_list)
if par.name is not None and par.name not in params_not_to_be_included:
# set the value for par to a default format,
# or to a default value if this is not included within the request
updated_arg_dic[par.name] = par.set_value_from_form(arg_dic, verbose=verbose)
if par.units_name is not None:
if par.default_units is not None:
updated_arg_dic[par.units_name] = par.default_units
else:
raise InternalError("Error when setting the parameter %s: "
"default unit not specified" % par.name)
if par.par_format_name is not None:
if par.par_default_format is not None:
updated_arg_dic[par.par_format_name] = par.par_default_format
else:
raise InternalError("Error when setting the parameter %s: "
"default format not specified" % par.name)
self.logger.info("after normalizing, set_pars_from_dic>> par: %s par.name: %s par.value: %s par_dic[par.name]: %s",
par, par.name, par.value, arg_dic.get(par.name, None))
if par.name == "scw_list":
self.logger.info("set_pars_from_dic>> scw_list is %s", par.value)
if arg_dic.get('allow_unknown_args', None):
self.allow_unknown_arguments = arg_dic.get('allow_unknown_args', 'False') == 'True'
known_argument_names = non_parameter_args + self.get_arguments_name_list()
self.unknown_arguments_name_list = []
for k in list(updated_arg_dic.keys()):
if k not in known_argument_names:
if not self.allow_unknown_arguments:
updated_arg_dic.pop(k)
self.logger.warning("argument '%s' is in the request but not used by instrument '%s', removing it", k, self.name)
self.unknown_arguments_name_list.append(k)
else:
self.logger.warning("argument '%s' not defined for instrument '%s'", k, self.name)
return updated_arg_dic

Ideally, also an extension of the tab generator would be needed?

@burnout87 burnout87 self-assigned this Jan 3, 2025
@dsavchenko
Copy link
Member

The idea is to change some_file_parameter_type to _some_file_parameter_type to avoid accidental clash with the workflow parameter names and to easily mute warnings "parameter not used".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants