Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mkexp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esmenv
mkexp
Commits
c86dd350
Commit
c86dd350
authored
2 years ago
by
Karl-Hermann Wieners
Browse files
Options
Downloads
Patches
Plain Diff
Config: added incremental adding and removing (+=, -=)
Currently for lists only
parent
81190e8c
Branches
basic_dataset
No related tags found
No related merge requests found
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
CHANGES.txt
+6
-1
6 additions, 1 deletion
CHANGES.txt
doc/mkexp.fodt
+1975
-1862
1975 additions, 1862 deletions
doc/mkexp.fodt
doc/mkexp.pdf
+0
-0
0 additions, 0 deletions
doc/mkexp.pdf
expconfig.py
+58
-0
58 additions, 0 deletions
expconfig.py
test.py
+53
-0
53 additions, 0 deletions
test.py
with
2092 additions
and
1863 deletions
CHANGES.txt
+
6
−
1
View file @
c86dd350
...
...
@@ -12,7 +12,12 @@ Release 1.2.0
Global
------
* Fixed "missing config" test for python3
* Fixed "missing config" test for python3
Config
------
* Added incremental adding and removing (+=, -=), currently for lists only
Release 1.1.6
=============
...
...
This diff is collapsed.
Click to expand it.
doc/mkexp.fodt
+
1975
−
1862
View file @
c86dd350
This diff is collapsed.
Click to expand it.
doc/mkexp.pdf
+
0
−
0
View file @
c86dd350
No preview for this file type
This diff is collapsed.
Click to expand it.
expconfig.py
+
58
−
0
View file @
c86dd350
...
...
@@ -162,6 +162,59 @@ class ExpConfig(ConfigObj):
break
return
config_name
# Incremental list assignments (+=, -=)
def
add_to_list
(
section
,
key
,
base_key
):
if
isinstance
(
section
[
key
],
(
list
,
tuple
)):
section
[
base_key
].
extend
(
section
[
key
])
else
:
section
[
base_key
].
append
(
section
[
key
])
def
remove_from_list
(
section
,
key
,
base_key
):
values
=
section
[
key
]
if
not
isinstance
(
values
,
(
list
,
tuple
)):
values
=
[
values
]
for
value
in
values
:
try
:
section
[
base_key
].
remove
(
value
)
except
ValueError
:
pass
list_assign_re
=
re
.
compile
(
r
'
(.*?)\s*([-+])$
'
)
def
list_assign
(
section
):
del_keys
=
[]
for
key
in
section
.
scalars
:
is_list_assign
=
re
.
match
(
list_assign_re
,
key
)
if
is_list_assign
:
base_key
=
is_list_assign
.
group
(
1
)
list_op
=
is_list_assign
.
group
(
2
)
if
not
base_key
in
section
:
section
[
base_key
]
=
[]
if
not
isinstance
(
section
[
base_key
],
(
list
,
tuple
)):
section
[
base_key
]
=
[
section
[
base_key
]]
section
.
main
.
interpolation
=
'
template
'
base_value
=
section
[
base_key
]
section
.
main
.
interpolation
=
False
section
[
base_key
]
=
base_value
if
list_op
==
'
+
'
:
add_to_list
(
section
,
key
,
base_key
)
elif
list_op
==
'
-
'
:
remove_from_list
(
section
,
key
,
base_key
)
del_keys
.
append
(
key
)
for
key
in
del_keys
:
del
section
[
key
]
for
key
in
section
.
sections
:
list_assign
(
section
[
key
])
# Helper functions for value definitions
def
read_value
(
value
):
if
os
.
path
.
exists
(
value
):
stream
=
open
(
value
)
...
...
@@ -414,6 +467,7 @@ class ExpConfig(ConfigObj):
if
os
.
path
.
exists
(
setup_config_name
):
pre_config
.
merge
(
ConfigObj
(
setup_config_name
,
interpolation
=
False
))
split_jobs
(
pre_config
)
list_assign
(
pre_config
)
register_version
(
pre_config
,
config_versions
)
lib_config_name
=
get_config_name
(
ExpConfig
.
exp_lib_dir
,
...
...
@@ -421,6 +475,7 @@ class ExpConfig(ConfigObj):
if
os
.
path
.
exists
(
lib_config_name
):
pre_config
.
merge
(
ConfigObj
(
lib_config_name
,
interpolation
=
False
))
split_jobs
(
pre_config
)
list_assign
(
pre_config
)
register_version
(
pre_config
,
config_versions
)
else
:
feedback
.
warning
(
"
cannot find experiment config for
'
%s
'
,
"
+
...
...
@@ -432,6 +487,7 @@ class ExpConfig(ConfigObj):
if
os
.
path
.
exists
(
lib_config_name
):
pre_config
.
merge
(
ConfigObj
(
lib_config_name
,
interpolation
=
False
))
split_jobs
(
pre_config
)
list_assign
(
pre_config
)
register_version
(
pre_config
,
config_versions
)
else
:
feedback
.
warning
(
"
cannot find config for option
'
%s
'
, using
"
+
...
...
@@ -444,6 +500,7 @@ class ExpConfig(ConfigObj):
if
os
.
path
.
exists
(
lib_config_name
):
pre_config
.
merge
(
ConfigObj
(
lib_config_name
,
interpolation
=
False
))
list_assign
(
pre_config
)
register_version
(
pre_config
,
config_versions
)
# Warn user if at least one config had no version info
...
...
@@ -456,6 +513,7 @@ class ExpConfig(ConfigObj):
interpolation
=
False
)
pre_config
.
merge
(
experiment_config
)
split_jobs
(
pre_config
)
list_assign
(
pre_config
)
# Add extra dictionary
pre_config
.
merge
(
extra_dict
)
...
...
This diff is collapsed.
Click to expand it.
test.py
+
53
−
0
View file @
c86dd350
...
...
@@ -433,6 +433,59 @@ class ContentTestCase(MkexpSimpleTestCase):
result
=
align
(
result
)
self
.
assertMultiLineEqual
(
expected
,
result
)
class
StaticAssignmentTestCase
(
MkexpSimpleTestCase
):
def
test_add_to_list
(
self
):
self
.
run_test
(
u
"""
%{LIST1}
%{LIST2}
%{LIST3}
"""
,
u
"""
[
'
a
'
]
[
'
b
'
,
'
c
'
]
[
'
d
'
,
'
e
'
,
'
f
'
,
'
g
'
]
"""
,
u
"""
LIST1 += a
LIST2 = b
LIST2 += c
LIST3 = d, e
LIST3 + = f, g
"""
)
def
test_remove_from_list
(
self
):
self
.
run_test
(
u
"""
%{LIST1}
%{LIST2}
%{LIST3}
"""
,
u
"""
[]
[
'
b
'
,
'
c
'
]
[
'
d
'
,
'
f
'
]
"""
,
u
"""
LIST1 = a
LIST1 -= a
LIST2 = b, c
LIST2 -= z
LIST3 = d, e, f, g
LIST3 - = e, g
"""
)
def
test_order_add_remove_list
(
self
):
self
.
run_test
(
u
"""
%{LIST1}
%{LIST2}
"""
,
u
"""
[
'
a
'
,
'
b
'
]
[
'
a
'
,
'
b
'
,
'
c
'
]
"""
,
u
"""
LIST1 = a, b
LIST1 += c
LIST1 -= c
LIST2 = a, b
LIST2 -= c
LIST2 += c
"""
)
class
NamelistTestCase
(
MkexpSimpleTestCase
):
def
test_namelist_comments
(
self
):
...
...
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