From fa9e0f025a9d3e56289e1f7927da36d4d6c44ea2 Mon Sep 17 00:00:00 2001 From: mavaylon1 Date: Wed, 17 Jan 2024 17:10:04 -0800 Subject: [PATCH] support multiple config files --- src/hdmf/__init__.py | 11 +++-------- src/hdmf/term_set.py | 32 ++++++++++++-------------------- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/hdmf/__init__.py b/src/hdmf/__init__.py index a40084da2..482297986 100644 --- a/src/hdmf/__init__.py +++ b/src/hdmf/__init__.py @@ -12,9 +12,6 @@ def get_termset_config(): return TS_CONFIG.config -def get_config_types(): - return TS_CONFIG.get_data_types() - @docval({'name': 'config_path', 'type': str, 'doc': 'Path to the configuartion file.', 'default': None}) def load_termset_config(config_path: str): @@ -28,12 +25,10 @@ def load_termset_config(config_path: str): - If the data_type is not present, then they will be loaded alongside the default curated configuration. """ if config_path is None: - TS_CONFIG.path = "/Users/mavaylon/Research/NWB/hdmf2/hdmf/docs/gallery/example_config.yaml" + TS_CONFIG.unload_termset_config() TS_CONFIG.load_termset_config() - - - - + else: + TS_CONFIG.load_termset_config(config_path) def unload_termset_config(): """ diff --git a/src/hdmf/term_set.py b/src/hdmf/term_set.py index a26055b0f..f4d52bff6 100644 --- a/src/hdmf/term_set.py +++ b/src/hdmf/term_set.py @@ -315,14 +315,6 @@ def __init__(self): self.config = None self.load_termset_config() - def get_data_types(self): - """ - Return list of data_types within current configuration file. - """ - data_types = [] - for data_type_dict in self.config: - data_types.append(data_type_dict['data_type']) - @docval({'name': 'config_path', 'type': str, 'doc': 'Path to the configuartion file.', 'default': None}) def load_termset_config(self,config_path): @@ -334,18 +326,18 @@ def load_termset_config(self,config_path): with open(self.path[0], 'r') as config: termset_config = yaml.safe_load(config) self.config = termset_config - - # # Check data_types within new config to see if they already exist in the current config - # with open(config_path, 'r') as config: - # termset_config = yaml.safe_load(config) - # for data_type_dict in termset_config: - # if data_type_dict['data_type'] in self.get_data_types(): - # pass - # - # - # # append path to new config to self.path - # if config_path is not None: - # self.path.append(config_path) + else: + # Check data_types within new config to see if they already exist in the current config + with open(config_path, 'r') as config: + termset_config = yaml.safe_load(config) + for data_type in termset_config: + if data_type in self.config: + self.config[data_type] = termset_config[data_type] + termset_config.pop(data_type) + self.config.update(termset_config) + + # append path to new config to self.path + self.path.append(config_path) def unload_termset_config():