`from_tuple()` now takes a default folder where data can be sourced from if they are not found in the current directory
@@ -19,7 +19,7 @@ class KeywordsMatching(object):
self.filename_not_contains = list_not_contain
@classmethod
- def from_tuple(cls, input_tuple):
+ def from_tuple(cls, input_tuple, default_folder=None):
"""
In the config file, constraints for a given search can be of three
types:
@@ -27,6 +27,8 @@ class KeywordsMatching(object):
associated value is a string. Multiple constraints are delimited by a ,
This function creates the corresponding matching object with the list
of constraints for each of these subtypes.
+ :param default_folder: relative paths are first tested against the current folder, and then against this
+ default folder
:param input_tuple:
:return:
"""
@@ -37,13 +39,22 @@ class KeywordsMatching(object):
if name == "path_to_search":
value = value.split(',')
for path_i in value:
- path_i = os.path.abspath(path_i.strip())
- if os.path.exists(path_i):
- path.append(path_i)
+ path_i = path_i.strip()
+ path_orig = os.path.abspath(path_i)
+ if os.path.exists(path_orig):
+ path.append(path_orig)
else:
+ if not default_folder:
raise ValueError('data input folder {} not found, did'
' you maybe forget to download data?'
- .format(value))
+ .format(path_i))
+ path_def = os.path.abspath(os.path.join(default_folder, path_i))
+ if os.path.exists(path_def):
+ path.append(path_def)
+ else:
+ raise ValueError('data input folder {} not found, did'
+ ' you maybe forget to download data?'
+ .format(path_i))
elif name == "filename_contains":
contain = tuple(set(value))
elif name == "filename_not_contains":
