Skip to content

Commit

Permalink
placeholder'
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Jan 22, 2024
1 parent 66d0752 commit c77e06d
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 63 deletions.
10 changes: 6 additions & 4 deletions src/hdmf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from .utils import docval, getargs
from .term_set import TermSet, TermSetWrapper, TermSetConfigurator

import os

# a global TermSetConfigurator
TS_CONFIG = TermSetConfigurator(path='src/hdmf/hdmf_config.yaml')

def get_termset_config():
return TS_CONFIG.config
# a global TermSetConfigurator
CUR_DIR = os.path.dirname(os.path.realpath(__file__))
path_to_config = os.path.join(CUR_DIR, 'hdmf_config.yaml')
TS_CONFIG = TermSetConfigurator(path=path_to_config)
TS_CONFIG.unload_termset_config()

@docval({'name': 'config_path', 'type': str, 'doc': 'Path to the configuartion file.',

Check failure on line 17 in src/hdmf/__init__.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

configuartion ==> configuration
'default': None})
Expand Down
102 changes: 54 additions & 48 deletions src/hdmf/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,62 +234,68 @@ def __init__(self, **kwargs):
self.__read_io = None
self.__obj = None

@docval({'name': 'constructor_args', 'type': dict, 'doc': 'The fields/parameters/attibutes for the object.'})
def init_validation(self, constructor_args):
# load termset configuartion file from global Config
def get_config(self):
from . import TS_CONFIG #update path
return TS_CONFIG

termset_config = TS_CONFIG.config
if termset_config is None:
msg = 'TermSet Configuration is not loaded.'
raise ValueError(msg)
object_name = self.__class__.__name__

# Check that the object data_type is in the loaded namespace
def get_type_map(self):
from .common import get_type_map
tm = get_type_map()
return tm

container_types_dict = tm.container_types
object_exists = False
for namespace in container_types_dict:
if object_name in container_types_dict[namespace]:
object_exists = True
else:
continue

if not object_exists:
msg = "%s is not in the loaded Namespace(s)." % object_name
raise warn(msg)

# Wrap supported fields with TermSetWrapper
obj_wrapped = False
if object_name in termset_config:
obj_wrapped = True
for attr in termset_config[object_name]['fields']:
obj_mapper = tm.get_map(self)
# get the spec according to attr name in schema
# Note: this is the name for the field in the config
spec = obj_mapper.get_attr_spec(attr)

# In the case of dealing with datasets directly or not defined in the spec.
# (Data/VectorData/DynamicTable/etc)
if spec is None:
# constr_name= attr
msg = "Spec not found for %s" % attr
raise warn(msg)
# From the spec, get the corresponding constructor name
@docval({'name': 'constructor_args', 'type': dict,
'doc': 'The fields/parameters/attibutes for the object.'})

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

View workflow job for this annotation

GitHub Actions / Check for spelling errors

attibutes ==> attributes
def init_validation(self, constructor_args):
# load termset configuartion file from global Config

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

View workflow job for this annotation

GitHub Actions / Check for spelling errors

configuartion ==> configuration
config = self.get_config()
termset_config = config.config
if termset_config is not None:
object_name = self.__class__.__name__

# Check that the object data_type is in the loaded namespace
tm = self.get_type_map()

container_types_dict = tm.container_types
object_exists = False
for namespace in container_types_dict:
if object_name in container_types_dict[namespace]:
object_exists = True
else:
constr_name = obj_mapper.get_const_arg(spec)
continue

if not object_exists:
msg = "%s is not in the loaded Namespace(s)." % object_name
warn(msg)

# Wrap supported fields with TermSetWrapper
obj_wrapped = False
if object_name in termset_config:
obj_wrapped = True
for attr in termset_config[object_name]['fields']:
obj_mapper = tm.get_map(self)
# get the spec according to attr name in schema
# Note: this is the name for the field in the config
spec = obj_mapper.get_attr_spec(attr)

# In the case of dealing with datasets directly or not defined in the spec.
# (Data/VectorData/DynamicTable/etc)
if spec is None:
# constr_name= attr
msg = "Spec not found for %s" % attr
warn(msg)
# From the spec, get the corresponding constructor name
else:
constr_name = obj_mapper.get_const_arg(spec)

if constr_name in constructor_args: # make sure any custom fields are not handled (i.e., make an extension)
termset_path = termset_config[object_name]['fields'][attr]
termset = TermSet(term_schema_path=termset_path)
constructor_args[attr] = TermSetWrapper(value=constructor_args[attr], termset=termset)
if constr_name in constructor_args: # make sure any custom fields are not handled (i.e., make an extension)
termset_path = termset_config[object_name]['fields'][attr]
termset = TermSet(term_schema_path=termset_path)
constructor_args[attr] = TermSetWrapper(value=constructor_args[attr], termset=termset)

# Even if the data_type is in the namespace, it might not be in the configuration.
if object_exists and not obj_wrapped:
msg = "%s is not in the loaded TermSet Configuration." % object_name
raise warn(msg)
# Even if the data_type is in the namespace, it might not be in the configuration.
if object_exists and not obj_wrapped:
msg = "%s is not in the loaded TermSet Configuration." % object_name
warn(msg)

@property
def read_io(self):
Expand Down
7 changes: 3 additions & 4 deletions src/hdmf/term_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ class TermSetConfigurator:
"""
"""
@docval({'name': 'path', 'type': str, 'doc': 'Path to the configuartion file.',
'default': None})
@docval({'name': 'path', 'type': str, 'doc': 'Path to the configuartion file.'})

Check failure on line 313 in src/hdmf/term_set.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

configuartion ==> configuration
def __init__(self, **kwargs):
self.path = [kwargs['path']]
self.config = None
Expand Down Expand Up @@ -341,9 +340,9 @@ def load_termset_config(self,config_path):
# append path to new config to self.path
self.path.append(config_path)

def unload_termset_config():
def unload_termset_config(self):
"""
Remove validation according to termset configuration file.
"""
self.path = ['src/hdmf/hdmf_config.yaml']
self.path = []
self.config = None
2 changes: 1 addition & 1 deletion tests/unit/test_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ VectorData:
fields:
data: /Users/mavaylon/Research/NWB/hdmf2/hdmf/tests/unit/example_test_term_set.yaml
field2: ...
DataType2:
DynamicTable:
namespace:
namespace_version:
fields:
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/test_config2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespaces:
core:
version:
data_types:
VectorData:
data: '...'
field2: '...'
experimental:
version:

#
# VectorData:
# namespace:
# namespace_version:
# fields:
# data: /Users/mavaylon/Research/NWB/hdmf2/hdmf/tests/unit/example_test_term_set.yaml
# field2: ...
# DynamicTable:
# namespace:
# namespace_version:
# fields:
# data: /Users/mavaylon/Research/NWB/hdmf2/hdmf/tests/unit/example_test_term_set.yaml
# field2: ...
7 changes: 1 addition & 6 deletions tests/unit/test_termset_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from hdmf.testing import TestCase
from hdmf import get_termset_config, load_termset_config, unload_termset_config
from hdmf import load_termset_config, unload_termset_config
from hdmf.term_set import TermSetConfigurator

class TestConfig(TestCase):
Expand All @@ -25,11 +25,6 @@ def test_unload_termset_config(self):
self.assertEqual(config.path, ['src/hdmf/hdmf_config.yaml'])
self.assertEqual(config.config, None)

def test_get_termset_config(self):
config = get_termset_config()
self.assertEqual(config.path, ['src/hdmf/hdmf_config.yaml'])
# self.assertEqual(config.config, None)

def test_unload_global_config(self):
config = get_termset_config()
unload_termset_config()
Expand Down

0 comments on commit c77e06d

Please sign in to comment.