Skip to content

Commit

Permalink
need to clean
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Jan 31, 2024
1 parent 9aa468d commit ec36ee3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
9 changes: 4 additions & 5 deletions src/hdmf/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
# a global type map
global __TYPE_MAP

def load_termset_config(config_path: str):
def load_termset_config(config_path: str = None):
"""
This method will:
- Search the current configuration for data_types that are already present. These data_types will be
replaced with the new configuration.
- If the data_type is not present, then they will be loaded alongside the default curated configuration.
This method will either load the default config or the config provided by the path.
"""
if config_path is None:
config_path = path_to_config
__TYPE_MAP.ts_config.load_termset_config(config_path)

# a function to register a container classes with the global map
Expand Down
13 changes: 7 additions & 6 deletions src/hdmf/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class HERDManager:
This class manages whether to set/attach an instance of HERD to the subclass.
"""

@docval({'name': 'herd', 'type': 'hdmf.common.resources.HERD',
@docval({'name': 'herd', 'type': 'HERD',
'doc': 'The external resources to be used for the container.'},)
def link_resources(self, **kwargs):
"""
Expand Down Expand Up @@ -78,7 +78,8 @@ def _setter(cls, field): # dada
Make a setter function for creating a :py:func:`property`
"""
name = field['name']
# breakpoint()
# if name == 'electrodes':
# breakpoint()
if not field.get('settable', True):
return None

Expand All @@ -89,7 +90,6 @@ def setter(self, val):
msg = "can't set attribute '%s' -- already set" % name
raise AttributeError(msg)
self.fields[name] = self._field_config(arg_name=name, val=val)
# self.fields[name] = val

return setter

Expand All @@ -99,8 +99,6 @@ def _field_config(self, arg_name, val):
"""
# load termset configuartion file from global Config

Check failure on line 101 in src/hdmf/container.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

configuartion ==> configuration
# if arg_name == 'location':
# breakpoint()
configurator = self.type_map.ts_config
if len(configurator.path)>0:
CUR_DIR = os.path.dirname(os.path.realpath(configurator.path[0]))
Expand All @@ -120,6 +118,8 @@ def _field_config(self, arg_name, val):
msg = '%s not found within the configuration for %s' % (object_name, self.namespace)
else:
for attr in config_namespace['data_types'][object_name]:
# if object_name == 'NWBFile':
# breakpoint()
# if the attr has been manually wrapped then skip checking the config for the attr
if type(attr) == TermSetWrapper:
continue
Expand All @@ -141,6 +141,7 @@ def _field_config(self, arg_name, val):
if constr_name == arg_name: # make sure any custom fields are not handled (i.e., make an extension)
termset_path = os.path.join(CUR_DIR, config_namespace['data_types'][object_name][attr])
termset = TermSet(term_schema_path=termset_path)

val = TermSetWrapper(value=val, termset=termset)
return val
return val
Expand Down Expand Up @@ -496,7 +497,7 @@ def set_modified(self, **kwargs):
def children(self):
return tuple(self.__children)

@docval({'name': 'child', 'type': 'hdmf.container.Container',
@docval({'name': 'child', 'type': 'Container',
'doc': 'the child Container for this Container', 'default': None})
def add_child(self, **kwargs):
warn(DeprecationWarning('add_child is deprecated. Set the parent attribute instead.'))
Expand Down
3 changes: 2 additions & 1 deletion src/hdmf/term_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,11 @@ def load_termset_config(self,config_path):
msg = 'This configuration file path already exists within the configurator.'
raise ValueError(msg)
else:
for namespace in termset_config:
for namespace in termset_config['namespaces']:
if namespace not in self.config: # append namespace config if not present within self.config
self.config['namespaces'][namespace] = termset_config['namespaces'][namespace]
else: # check for any needed overrides within existing namespace configs
breakpoint()
for data_type in termset_config['namespaces'][namespace]['data_types']:
if data_type in self.config['namespaces'][namespace]['data_types']:
replace_config = termset_config['namespaces'][namespace]['data_types'][data_type]
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ namespaces:
field1: '...'
hdmf-experimental:
version: TBD
data_types:
type1:
field1: '/Users/mavaylon/Research/NWB/hdmf2/hdmf/tests/unit/example_test_term_set.yaml'
field2: '...'
5 changes: 5 additions & 0 deletions tests/unit/test_extension_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ namespaces:
field1: '...'
hdmf-experimental:
version: TBD
core:
data_types:
NWBFile:
experimenter: experimenter_termset2.yaml
blah: experimenter.yaml

0 comments on commit ec36ee3

Please sign in to comment.