Commit da63f05e authored by Lauri Himanen's avatar Lauri Himanen

Streamlined the installation, updated readme accordingly.

parent b925bb68
......@@ -41,6 +41,12 @@ and then installing the package itself with the provided installation script:
python setup.py develop --user
```
This will install a development version, which means that if you update the
source code, all the changes will be available immediately without reinstall of
the package. The current setup also assumes a certain location for the metainfo
repository. If you place all the repositories (python-common, nomad-meta-info,
parser repository) in the same folder, things should work.
After this the package will be available to import by simply calling
```python
......
......@@ -35,7 +35,7 @@ class ParserInterface(object):
__metaclass__ = ABCMeta
metainfo_env = None
def __init__(self, main_file, metainfo_to_keep=None, backend=None, default_units=None, metainfo_units=None):
def __init__(self, main_file, metainfo_to_keep=None, backend=None, default_units=None, metainfo_units=None, debug=True, store=True):
"""
Args:
main_file: A special file that can be considered the main file of the
......@@ -46,6 +46,8 @@ class ParserInterface(object):
backend: An object to which the parser will give all the parsed data.
The backend will then determine where and when to output that data.
"""
self.debug = debug
self.store = store
self.initialize(main_file, metainfo_to_keep, backend, default_units, metainfo_units)
def initialize(self, main_file, metainfo_to_keep, backend, default_units, metainfo_units):
......@@ -78,7 +80,7 @@ class ParserInterface(object):
if backend is not None:
self.parser_context.super_backend = backend(type(self).metainfo_env)
else:
self.parser_context.super_backend = LocalBackend(type(self).metainfo_env)
self.parser_context.super_backend = LocalBackend(type(self).metainfo_env, debug=self.debug, store=self.store)
# Check the list of default units
default_unit_map = {}
......
......@@ -6,14 +6,29 @@ from collections import defaultdict
logger = logging.getLogger(__name__)
#===============================================================================
class DummyFile:
def write(self,input):
pass
#===============================================================================
class LocalBackend(object):
"""A backend that outputs results into a regular python dictionary. This is
useful if you wan't to run the parser with python only.
"""
def __init__(self, metaInfoEnv, fileOut=StringIO.StringIO(), debug=True):
def __init__(self, metaInfoEnv, debug=True, store=True):
"""
Args:
metaInfoEnv: The description of the metainfo environment.
debug: Boolean indicating whether some debugging should be done
(check that correct types and shapes are pushed into backend)
store: Boolean indicating whether the parsed results should be
stored in memory. Useful to skip the storing if you just want
to quickly check that everything is runnning fine and don't
want to waste RAM in doing so.
"""
self.__metaInfoEnv = metaInfoEnv
self.fileOut = fileOut
self.fileOut = DummyFile()
self.__gIndex = -1
self.__openSections = set()
self.__lastIndex = {}
......@@ -22,6 +37,7 @@ class LocalBackend(object):
self.sectionManagers = {}
self.results = Results(metaInfoEnv, self.dataManagers, self.sectionManagers)
self.debug = debug
self.store = store
for ikNames, ik in metaInfoEnv.infoKinds.items():
if ik.kindStr == "type_section":
......@@ -177,12 +193,7 @@ class LocalBackend(object):
#===============================================================================
class Results(object):
"""The collection of results gathered by a parser.
The results are input into a dictionary that is augmented with supporting
functionality.
Attributes:
"""A wrapper object for the collection of results gathered by a parser.
"""
def __init__(self, metaInfoEnv, datamanagers, sectionmanagers):
self._datamanagers = datamanagers
......@@ -297,29 +308,32 @@ class Section(object):
results.append(path)
def addValue(self, metaInfo, value):
vals = self.simpleValues.get(metaInfo.name, None)
if vals is None:
self.simpleValues[metaInfo.name] = [value]
else:
vals.append(value)
if self.backend.store:
vals = self.simpleValues.get(metaInfo.name, None)
if vals is None:
self.simpleValues[metaInfo.name] = [value]
else:
vals.append(value)
def setArrayValues(self, metaInfo, values, offset=None):
vals = self.arrayValues.get(metaInfo.name, None)
if vals is None:
raise Exception("setArrayValues(%s,...) called before adding a value" % metaInfo.name)
else:
if offset:
idxs = map(lambda i: slice(offset[i], offset[i] + values.shape[i]), range(len(offset)))
if self.backend.store:
vals = self.arrayValues.get(metaInfo.name, None)
if vals is None:
raise Exception("setArrayValues(%s,...) called before adding a value" % metaInfo.name)
else:
idxs = map(lambda x: slice(0, x), values.shape)
vals[len(vals) - 1][idxs] = values
if offset:
idxs = map(lambda i: slice(offset[i], offset[i] + values.shape[i]), range(len(offset)))
else:
idxs = map(lambda x: slice(0, x), values.shape)
vals[len(vals) - 1][idxs] = values
def addArrayValues(self, metaInfo, values):
vals = self.arrayValues.get(metaInfo.name, None)
if vals is None:
self.arrayValues[metaInfo.name] = [values]
else:
vals.append(values)
if self.backend.store:
vals = self.arrayValues.get(metaInfo.name, None)
if vals is None:
self.arrayValues[metaInfo.name] = [values]
else:
vals.append(values)
def addSubsection(self, metaInfo, section):
vals = self.subSectionValues.get(metaInfo.name, None)
......@@ -331,7 +345,8 @@ class Section(object):
#===============================================================================
class SectionManager(object):
"""Manages the sections for the given metainfo.
"""
def __init__(self, metaInfo, parentSectionNames, lastSectionGIndex=-1, openSections={}):
self.metaInfo = metaInfo
self.parentSectionNames = parentSectionNames
......@@ -405,6 +420,8 @@ class SectionManager(object):
#===============================================================================
class DataManager(object):
"""Stores the parent (SectionManager) for the given metainfo.
"""
def __init__(self, metaInfo, superSectionManager):
self.metaInfo = metaInfo
self.superSectionManager = superSectionManager
......@@ -11,14 +11,12 @@ def main():
setup(
name="nomadcore",
version="0.1",
description="Tools for NOMAD parser development",
description="Tools for NOMAD parser development.",
package_dir={'': 'common/python'},
packages=["nomadcore", "nomadcore.unit_conversion", "nomadscripts"],
include_package_data=True,
packages=find_packages("common/python"),
package_data={
'nomadcore.unit_conversion': ['*.txt'],
},
zip_safe=False
}
)
# Run main function by default
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment