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
ddbc758e
Commit
ddbc758e
authored
8 years ago
by
Ask Hjorth Larsen
Browse files
Options
Downloads
Patches
Plain Diff
avoid mutable defaults like [], {} in method declarations
parent
cb80579d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/python/nomadcore/simple_parser.py
+36
-18
36 additions, 18 deletions
common/python/nomadcore/simple_parser.py
with
36 additions
and
18 deletions
common/python/nomadcore/simple_parser.py
+
36
−
18
View file @
ddbc758e
...
...
@@ -27,7 +27,7 @@ annotate = False
class
PushbackLineFile
(
object
):
"""
a file interface where it is possible to put back read lines
"""
def
__init__
(
self
,
fIn
,
lines
=
[]
):
def
__init__
(
self
,
fIn
,
lines
=
tuple
()
):
self
.
fIn
=
fIn
self
.
lines
=
list
(
lines
)
self
.
lineNr
=
0
...
...
@@ -57,7 +57,7 @@ class SimpleMatcher(object):
# if the matcher has weak == true, this matcher should nevel steal
# the matcher can/should repeat immediately
def
__init__
(
self
,
startReStr
,
endReStr
=
None
,
subMatchers
=
[]
,
sections
=
[]
,
def
__init__
(
self
,
startReStr
,
endReStr
=
None
,
subMatchers
=
tuple
()
,
sections
=
tuple
()
,
subFlags
=
SubFlags
.
Sequenced
,
weak
=
False
,
# this matcher should not "steal" the position
repeats
=
False
,
# this matcher is expected to repeat
...
...
@@ -67,10 +67,10 @@ class SimpleMatcher(object):
forwardMatch
=
False
,
# if start match should not eat input, but be forwarded to adHoc and subMatchers
name
=
""
,
adHoc
=
None
,
otherMetaInfo
=
[]
,
# The metainfos that are later manually added ot the backend
otherMetaInfo
=
tuple
()
,
# The metainfos that are later manually added ot the backend
fixedStartValues
=
None
,
fixedEndValues
=
None
,
dependencies
=
{}
,
dependencies
=
None
,
defLine
=
0
,
defFile
=
''
,
coverageIgnore
=
False
,
# mark line as ignored in coverage analysis
...
...
@@ -82,8 +82,8 @@ class SimpleMatcher(object):
self
.
index
=
-
1
self
.
startReStr
=
startReStr
self
.
endReStr
=
endReStr
self
.
subMatchers
=
subMatchers
self
.
sections
=
sections
self
.
subMatchers
=
list
(
subMatchers
)
self
.
sections
=
list
(
sections
)
self
.
subFlags
=
subFlags
self
.
weak
=
weak
self
.
repeats
=
repeats
...
...
@@ -92,7 +92,9 @@ class SimpleMatcher(object):
self
.
forwardMatch
=
forwardMatch
self
.
superMatcher
=
None
self
.
adHoc
=
adHoc
self
.
otherMetaInfo
=
otherMetaInfo
self
.
otherMetaInfo
=
list
(
otherMetaInfo
)
if
dependencies
is
None
:
dependencies
=
{}
self
.
dependencies
=
dependencies
self
.
name
=
name
self
.
fixedStartValues
=
fixedStartValues
...
...
@@ -239,9 +241,12 @@ class SimpleMatcher(object):
groups
.
extend
(
extractGroupNames
(
self
.
endReStr
))
return
groups
def
allMetaNames
(
self
,
metaNames
=
[]
):
def
allMetaNames
(
self
,
metaNames
=
None
):
"""
The names of the meta infos the could be matched by this matcher or its sub matchers.
groups can be a
"""
if
metaNames
is
None
:
metaNames
=
[]
metaNames
.
extend
(
self
.
directMetaNames
())
for
m
in
self
.
subMatchers
:
m
.
allMetaNames
(
metaNames
)
...
...
@@ -1281,20 +1286,20 @@ def defaultParseFile(parserInfo):
def
mainFunction
(
mainFileDescription
,
metaInfoEnv
,
parserInfo
,
parseFile
=
None
,
outF
=
sys
.
stdout
,
cachingLevelForMetaName
=
{}
,
defaultDataCachingLevel
=
CachingLevel
.
ForwardAndCache
,
defaultSectionCachingLevel
=
CachingLevel
.
Forward
,
superContext
=
None
,
onClose
=
{}
,
onOpen
=
{}
,
parseFile
=
None
,
outF
=
sys
.
stdout
,
cachingLevelForMetaName
=
None
,
defaultDataCachingLevel
=
CachingLevel
.
ForwardAndCache
,
defaultSectionCachingLevel
=
CachingLevel
.
Forward
,
superContext
=
None
,
onClose
=
None
,
onOpen
=
None
,
default_units
=
None
,
metainfo_units
=
None
,
superBackend
=
None
,
metaInfoToKeep
=
None
,
mainFile
=
None
,
strValueTransform
=
{}
):
strValueTransform
=
None
):
"""
Args:
default_units: A list of default unit definitions.
...
...
@@ -1330,6 +1335,16 @@ def mainFunction(mainFileDescription,
verbose
=
False
fileToParse
=
None
writeMatchTelemetry
=
False
if
cachingLevelForMetaName
is
None
:
cachingLevelForMetaName
=
{}
if
onClose
is
None
:
onClose
=
{}
if
onOpen
is
None
:
onOpen
=
{}
if
strValueTransform
is
None
:
strValueTransform
=
{}
ii
=
1
while
ii
<
len
(
sys
.
argv
):
arg
=
sys
.
argv
[
ii
]
...
...
@@ -1531,7 +1546,7 @@ class ParserOptimizer(object):
"""
For optimizing a hierarchy of SimpleMatchers based on a list of metainfo
names that should be included in the parsing.
"""
def
optimizeParsingTree
(
self
,
rootMatcher
,
metaInfoToKeep
=
[]
):
def
optimizeParsingTree
(
self
,
rootMatcher
,
metaInfoToKeep
=
None
):
"""
This function will remove any parsing unnecessary parsing actions
from the parsing tree based on the given list of metainfo names to keep
and metainfo names to skip.
...
...
@@ -1542,6 +1557,9 @@ class ParserOptimizer(object):
metaInfoToKeep: List of metainfonames to keep in parsing
"""
# First identify the parts that should be kept
if
metaInfoToKeep
is
None
:
metaInfoToKeep
=
[]
if
metaInfoToKeep
:
# Single values are put inside a list for convenience
...
...
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