Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
athena
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Sherwood
athena
Commits
d511f65a
Commit
d511f65a
authored
4 years ago
by
Tomasz Bold
Browse files
Options
Downloads
Patches
Plain Diff
Fixed how dynamic flags shoudl behave when not yet locked
parent
baae14c1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Control/AthenaConfiguration/python/AthConfigFlags.py
+35
-11
35 additions, 11 deletions
Control/AthenaConfiguration/python/AthConfigFlags.py
with
35 additions
and
11 deletions
Control/AthenaConfiguration/python/AthConfigFlags.py
+
35
−
11
View file @
d511f65a
# Copyright (C) 2002-20
19
CERN for the benefit of the ATLAS collaboration
# Copyright (C) 2002-20
20
CERN for the benefit of the ATLAS collaboration
from
__future__
import
print_function
...
...
@@ -11,24 +11,32 @@ class CfgFlag(object):
def
__init__
(
self
,
default
):
if
default
is
None
:
raise
RuntimeError
(
"
Default value of a flag must not be None
"
)
if
callable
(
default
):
self
.
_value
=
None
self
.
_setDef
=
default
else
:
self
.
_value
=
default
self
.
_setDef
=
None
self
.
set
(
default
)
return
def
set
(
self
,
value
):
self
.
_value
=
value
if
callable
(
value
):
self
.
_value
=
None
self
.
_setDef
=
value
else
:
self
.
_value
=
value
self
.
_setDef
=
None
return
def
get
(
self
,
flagdict
=
None
):
if
self
.
_value
is
None
:
#Have to call the method to obtain the default value
if
self
.
_value
is
not
None
:
return
deepcopy
(
self
.
_value
)
#Have to call the method to obtain the default value, and then reuse it in all next accesses
if
flagdict
.
locked
():
# optimise future reads, drop possibility to update this flag ever
self
.
_value
=
self
.
_setDef
(
flagdict
)
return
deepcopy
(
self
.
_value
)
self
.
_setDef
=
None
return
deepcopy
(
self
.
_value
)
else
:
#use function for as long as the flags are not locked
return
deepcopy
(
self
.
_setDef
(
flagdict
))
def
__repr__
(
self
):
if
self
.
_value
is
not
None
:
...
...
@@ -525,6 +533,21 @@ class TestOverwriteFlags(TestFlagsSetupDynamic):
copyf
.
dump
()
print
(
""
)
class
TestDynamicDependentFlags
(
unittest
.
TestCase
):
def
runTest
(
self
):
print
(
"""
... Check if dynamic dependent flags work
"""
)
flags
=
AthConfigFlags
()
flags
.
addFlag
(
"
A
"
,
True
)
flags
.
addFlag
(
"
B
"
,
lambda
prevFlags
:
3
if
prevFlags
.
A
is
True
else
10
)
flags
.
addFlag
(
"
C
"
,
lambda
prevFlags
:
'
A
'
if
prevFlags
.
A
is
True
else
'
B
'
)
assert
flags
.
B
==
3
flags
.
A
=
False
assert
flags
.
B
==
10
flags
.
A
=
True
flags
.
lock
()
assert
flags
.
C
==
'
A
'
print
(
""
)
class
flagsFromArgsTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
flags
=
AthConfigFlags
()
...
...
@@ -558,5 +581,6 @@ if __name__ == "__main__":
suite
.
addTest
(
TestDynamicFlagsRead
())
suite
.
addTest
(
TestDynamicFlagsSet
())
suite
.
addTest
(
TestOverwriteFlags
())
suite
.
addTest
(
TestDynamicDependentFlags
())
runner
=
unittest
.
TextTestRunner
(
failfast
=
False
)
runner
.
run
(
suite
)
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