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

Special treatment empty POSIXPath parameters #731

Merged
merged 14 commits into from
Jan 28, 2025
Merged
2 changes: 1 addition & 1 deletion cdci_data_analysis/analysis/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from urllib.parse import urlencode

from cdci_data_analysis.analysis.queries import _check_is_base_query
# from .parameters import POSIXPath
from ..analysis import tokenHelper, parameters
from .catalog import BasicCatalog
from .products import QueryOutput
Expand Down Expand Up @@ -167,7 +168,6 @@ def set_pars_from_dic(self, arg_dic, verbose=False):
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:
Expand Down
23 changes: 22 additions & 1 deletion cdci_data_analysis/analysis/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@

check_value=None,
allowed_values=None,
overwrite_default_value=False,
overwriting_default_value=None,
min_value=None,
max_value=None,
is_optional=False,
Expand Down Expand Up @@ -253,6 +255,8 @@
self.is_optional = is_optional
self._allowed_units = allowed_units
self._allowed_values = allowed_values
self.overwrite_default_value = overwrite_default_value
self.overwriting_default_value = overwriting_default_value
self._allowed_types = allowed_types
self.name = name
self.default_units = default_units
Expand Down Expand Up @@ -395,6 +399,11 @@

if in_dictionary is True:
return self.set_par(value=v, units=u, par_format=f)
# If the parameter is not provided as an argument and needs to be set to a specific default value,
# we decide to overwrite it. For example, in the POSIXPath class, we "force/overwrite" the default value to ''
# if no file is provided, from which we normally generate a download URL.
elif self.overwrite_default_value and self.overwriting_default_value is not None:
return self.set_par(value=self.overwriting_default_value, units=u, par_format=f)
else:
if verbose is True:
logger.debug('setting par: %s in the dictionary to its default value' % par_name)
Expand Down Expand Up @@ -583,7 +592,7 @@
class String(Parameter):
owl_uris = ("http://www.w3.org/2001/XMLSchema#str", "http://odahub.io/ontology#String")

def __init__(self, value, name_format='str', name=None, allowed_values = None, is_optional=False, extra_metadata = None):
def __init__(self, value, name_format='str', name=None, allowed_values = None, overwrite_default_value=False, overwriting_default_value=None, is_optional=False, extra_metadata = None):

_allowed_units = ['str']
super().__init__(value=value,
Expand All @@ -592,6 +601,8 @@
name=name,
allowed_units=_allowed_units,
allowed_values=allowed_values,
overwrite_default_value=overwrite_default_value,
overwriting_default_value=overwriting_default_value,
is_optional=is_optional,
extra_metadata=extra_metadata)

Expand All @@ -611,6 +622,16 @@
class POSIXPath(FileReference):
owl_uris = FileReference.owl_uris + ("http://odahub.io/ontology#POSIXPath",)

def __init__(self, *args, **kwargs):
overwriting_default_value = ''
super().__init__(*args,
overwrite_default_value=True,
overwriting_default_value=overwriting_default_value,
**kwargs)

def overwrite_default_value(self):
Fixed Show fixed Hide fixed
self.value = ''

class FileURL(FileReference):
owl_uris = FileReference.owl_uris + ("http://odahub.io/ontology#FileURL",)

Expand Down
Loading