Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nomad-lab
python-common
Commits
da63f05e
Commit
da63f05e
authored
9 years ago
by
Lauri Himanen
Browse files
Options
Downloads
Patches
Plain Diff
Streamlined the installation, updated readme accordingly.
parent
b925bb68
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+6
-0
6 additions, 0 deletions
README.md
common/python/nomadcore/baseclasses.py
+4
-2
4 additions, 2 deletions
common/python/nomadcore/baseclasses.py
common/python/nomadcore/local_backend.py
+44
-27
44 additions, 27 deletions
common/python/nomadcore/local_backend.py
setup.py
+3
-5
3 additions, 5 deletions
setup.py
with
57 additions
and
34 deletions
README.md
+
6
−
0
View file @
da63f05e
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
common/python/nomadcore/baseclasses.py
+
4
−
2
View file @
da63f05e
...
...
@@ -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
=
{}
...
...
This diff is collapsed.
Click to expand it.
common/python/nomadcore/local_backend.py
+
44
−
27
View file @
da63f05e
...
...
@@ -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
This diff is collapsed.
Click to expand it.
setup.py
+
3
−
5
View file @
da63f05e
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment