Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
payno
workflow_concepts
Commits
a988379f
Commit
a988379f
authored
Jun 10, 2021
by
Wout De Nolf
Browse files
make Task.inputs namespace read-only
parent
d1aca94b
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
esrftaskgraph/esrftaskgraph/task.py
View file @
a988379f
...
...
@@ -2,6 +2,7 @@ from esrftaskgraph import hashing
from
esrftaskgraph.variable
import
VARINFO
from
esrftaskgraph.variable
import
VariableContainer
from
esrftaskgraph.variable
import
VariableContainerNamespace
from
esrftaskgraph.variable
import
ReadOnlyVariableContainerNamespace
from
esrftaskgraph.registration
import
Registered
...
...
@@ -53,7 +54,7 @@ class Task(Registered, hashing.UniversalHashable, register=False):
value
=
ovars
,
uhash
=
self
.
_inputs
,
uhash_nonce
=
self
.
class_nonce
(),
**
varkw
)
self
.
_user_inputs
=
VariableContainerNamespace
(
self
.
_inputs
)
self
.
_user_inputs
=
ReadOnly
VariableContainerNamespace
(
self
.
_inputs
)
self
.
_user_outputs
=
VariableContainerNamespace
(
self
.
_outputs
)
# The task class has the same hash as its output
...
...
esrftaskgraph/esrftaskgraph/variable.py
View file @
a988379f
...
...
@@ -326,7 +326,11 @@ class MutableVariableContainer(VariableContainer, MutableMapping):
del
self
.
value
[
name
]
class
UnknownVariableError
(
AttributeError
):
class
UnknownVariableError
(
RuntimeError
):
pass
class
ReadOnlyVariableError
(
RuntimeError
):
pass
...
...
@@ -358,3 +362,11 @@ class VariableContainerNamespace:
return
self
.
_container
[
name
]
except
(
KeyError
,
TypeError
):
raise
UnknownVariableError
(
name
)
class
ReadOnlyVariableContainerNamespace
(
VariableContainerNamespace
):
def
__setattr__
(
self
,
name
,
value
):
if
name
in
self
.
_reserved_variable_names
():
super
(
VariableContainerNamespace
,
self
).
__setattr__
(
name
,
value
)
else
:
raise
ReadOnlyVariableError
(
name
)
esrftaskgraph/tests/test_task.py
View file @
a988379f
...
...
@@ -36,6 +36,12 @@ def test_task_missing_input(variable_kwargs):
SumTask
(
**
variable_kwargs
)
def
test_task_readonly_input
(
variable_kwargs
):
task
=
SumTask
(
a
=
10
,
**
variable_kwargs
)
with
pytest
.
raises
(
RuntimeError
):
task
.
inputs
.
a
=
10
def
test_task_optional_input
(
tmpdir
,
variable_kwargs
):
task
=
SumTask
(
a
=
10
,
**
variable_kwargs
)
assert
not
task
.
done
...
...
@@ -52,7 +58,7 @@ def test_task_uhash(variable_kwargs):
assert
task
.
uhash
==
task
.
output_variables
.
uhash
assert
task
.
uhash
!=
task
.
input_variables
.
uhash
task
.
input
s
.
a
+=
1
task
.
input
_variables
[
"a"
].
value
+=
1
assert
task
.
uhash
!=
uhash
assert
task
.
uhash
==
task
.
output_variables
.
uhash
assert
task
.
uhash
!=
task
.
input_variables
.
uhash
...
...
@@ -60,7 +66,7 @@ def test_task_uhash(variable_kwargs):
task
.
run
()
assert
task
.
done
task
.
input
s
.
a
+=
1
task
.
input
_variables
[
"a"
].
value
+=
1
assert
task
.
uhash
!=
uhash
assert
task
.
uhash
==
task
.
output_variables
.
uhash
assert
task
.
uhash
!=
task
.
input_variables
.
uhash
...
...
examples/taskgraph_representation.ipynb
View file @
a988379f
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment