diff --git a/common/python/nomadcore/local_backend.py b/common/python/nomadcore/local_backend.py index 6ab3e8aa4aeb2ecce755918c89b5629cecf339ca..26dfbbbaafb7f2e1de70d9d22e4098a7f7a35dc0 100644 --- a/common/python/nomadcore/local_backend.py +++ b/common/python/nomadcore/local_backend.py @@ -130,6 +130,8 @@ class LocalBackend(object): # Check the type dtype_str = dataManager.metaInfo.dtypeStr + if dtype_str is None: + raise TypeError("The metainfo '{}' does not define a dtypeStr".format(metaName)) single_types = self.single_value_type_for_metainfo_type(dtype_str) actual_numpy_type = type(value) if actual_numpy_type not in single_types: @@ -318,14 +320,14 @@ class Results(object): if metainfo is None: raise LookupError("The metainfo name '{}' does not exist in the metainfo environment. Check for typos or try updating the metainfo git package.".format(metaname)) - def traverse(self): + def traverse(self, root_section='section_run'): """A generator function for traversing the data in the parser results. This generator returns a tuple of three item: the metainfo name, the event type, and the event value. """ - root = self._sectionmanagers["section_run"] - for x in self.traverse_recursive("section_run", root.openSections): + root = self._sectionmanagers[root_section] + for x in self.traverse_recursive(root_section, root.openSections): yield x def traverse_recursive(self, name, open_sections): @@ -624,7 +626,7 @@ class SectionManager(object): gI = gIndex try: self.openSections[gI].addValue(valueMetaInfo, value) - except KeyError: + except (KeyError, IndexError): raise Exception("Cannot add value for metadata %s to section %d (%d) of %s, as it is not open" % (valueMetaInfo.name, gI, gIndex, self.metaInfo.name)) def setArrayValues(self, valueMetaInfo, value, offset=None, gIndex=-1): @@ -634,7 +636,7 @@ class SectionManager(object): gI = gIndex try: self.openSections[gI].setArrayValues(valueMetaInfo, value, offset) - except KeyError: + except (KeyError, IndexError): raise Exception("Cannot set array values for metadata %s to section %d (%d) of %s, as it is not open" % (valueMetaInfo.name, gI, gIndex, self.metaInfo.name)) def addArrayValues(self, valueMetaInfo, value, gIndex=-1): @@ -644,7 +646,7 @@ class SectionManager(object): gI = gIndex try: self.openSections[gI].addArrayValues(valueMetaInfo, value) - except KeyError: + except (KeyError, IndexError): raise Exception("Cannot add array values for metadata %s to section %d (%d) of %s, as it is not open" % (valueMetaInfo.name, gI, gIndex, self.metaInfo.name)) diff --git a/common/python/nomadcore/local_meta_info.py b/common/python/nomadcore/local_meta_info.py index c877522750744d94aa6f2caeab8f33d3c9665689..4cd9642118dabfcfd004c68154f1c75e97ecc7ce 100644 --- a/common/python/nomadcore/local_meta_info.py +++ b/common/python/nomadcore/local_meta_info.py @@ -10,6 +10,7 @@ import json import os, re from nomadcore.json_support import jsonCompactS, jsonCompactD, jsonIndentD from io import open +import nomad_meta_info """objects to handle a local InfoKinds with unique name (think self written json)""" class InfoKindEl(object): @@ -183,14 +184,20 @@ class RelativeDependencySolver(object): self.deps = {} def __call__(self, infoKindEnv, source, dep): - if "relativePath" not in dep: - raise Exception('Invalid dependency for relativeDependencySolver there must be a relativePath') - basePath = source.get('path') + if "metainfoPath" in dep: + basePath = nomad_meta_info.__file__ + path = dep["metainfoPath"] + elif "relativePath" in dep: + basePath = source.get('path') + path = dep["relativePath"] + else: + raise Exception('Invalid dependency for relativeDependencySolver there must be a relativePath or metainfoPath') + if basePath: baseDir = os.path.dirname(os.path.abspath(basePath)) else: baseDir = os.getcwd() - dPath = os.path.realpath(os.path.join(baseDir, dep['relativePath'])) + dPath = os.path.realpath(os.path.join(baseDir, path)) if dPath in self.deps: return self.deps[dPath] depInfo = None