diff --git a/src/hdmf/__init__.py b/src/hdmf/__init__.py index 2e193f4cb..15b1ba651 100644 --- a/src/hdmf/__init__.py +++ b/src/hdmf/__init__.py @@ -7,7 +7,6 @@ # a global TermSetConfigurator -global TS_CONFIG TS_CONFIG = TermSetConfigurator() @docval({'name': 'config_path', 'type': str, 'doc': 'Path to the configuartion file.', diff --git a/src/hdmf/container.py b/src/hdmf/container.py index ead820ee2..7fd7de23e 100644 --- a/src/hdmf/container.py +++ b/src/hdmf/container.py @@ -240,17 +240,16 @@ def init_validation(self, fields): from . import TS_CONFIG #update path # Before calling super().__init__() and before setting fields, check for config file for # validation via TermSetWrapper. - with open(TS_CONFIG.path, 'r') as config: - termset_config = yaml.safe_load(config) - object_name = self.__class__.__name__ - - for obj_config in termset_config: - if obj_config['data_type'] == object_name: - for attr in obj_config['fields']: - if attr in fields: # make sure any custom fields are not handled (i.e., make an extension) - termset_path = obj_config['fields'][attr] - termset = TermSet(term_schema_path=termset_path) - fields[attr] = TermSetWrapper(value=fields[attr], termset=termset) + termset_config = TS_CONFIG.load_termset_config() + object_name = self.__class__.__name__ + + for obj_config in termset_config: + if obj_config['data_type'] == object_name: + for attr in obj_config['fields']: + if attr in fields: # make sure any custom fields are not handled (i.e., make an extension) + termset_path = obj_config['fields'][attr] + termset = TermSet(term_schema_path=termset_path) + fields[attr] = TermSetWrapper(value=fields[attr], termset=termset) @property def read_io(self): @@ -801,7 +800,6 @@ class Data(AbstractContainer): """ A class for representing dataset containers """ - @docval({'name': 'name', 'type': str, 'doc': 'the name of this container'}, {'name': 'data', 'type': ('scalar_data', 'array_data', 'data'), 'doc': 'the source of the data'}) def __init__(self, **kwargs): diff --git a/src/hdmf/term_set.py b/src/hdmf/term_set.py index 4a196d5cc..f8cb1eb08 100644 --- a/src/hdmf/term_set.py +++ b/src/hdmf/term_set.py @@ -316,13 +316,19 @@ def __init__(self): # def config_path(self): # return self.__config_path - @docval({'name': 'config_path', 'type': str, 'doc': 'Path to the configuartion file.'}) + @docval({'name': 'config_path', 'type': str, 'doc': 'Path to the configuartion file.', + 'default': None}) def load_termset_config(config_path: str): """ Load the configuration file for validation on the fields defined for the objects within the file. By default, the curated configuration file is used, but can take in a custom file. """ - self.path = config_path + if config_path not None: + self.path = config_path + + with open(self.path, 'r') as config: + termset_config = yaml.safe_load(config) + return termset_config def unload_termset_config(): """