diff --git a/common/python/nomadcore/local_backend.py b/common/python/nomadcore/local_backend.py index 4cdb877c72c2005c9aa1bba339257ee5ac26edf3..8e7e4990a94b6b1aa0a8bdfeded55c6f57169181 100644 --- a/common/python/nomadcore/local_backend.py +++ b/common/python/nomadcore/local_backend.py @@ -131,6 +131,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: @@ -319,14 +321,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): @@ -625,7 +627,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): @@ -635,7 +637,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, **kwargs): @@ -644,8 +646,8 @@ class SectionManager(object): else: gI = gIndex try: - self.openSections[gI].addArrayValues(valueMetaInfo, value, **kwargs) - except KeyError: + self.openSections[gI].addArrayValues(valueMetaInfo, value) + 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..5251aa592209d8fc5da6bc0a667b0fb172f7ea3d 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 @@ -456,7 +463,7 @@ class InfoKindEnv(object): def toJsonList(self, withGids): infoKinds = list(self.infoKinds.keys()) - infoKinds.sort(lambda x, y: self.compareKeys(x.name, y.name)) + # infoKinds.sort(lambda x, y: self.compareKeys(x.name, y.name)) return [self.infoKinds[x].toDict(self, self if withGids else None) for x in infoKinds]