From 5fbcdacec7ccaf58a3d0df86b07fd51963a10e2b Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 7 Sep 2016 20:20:20 +0800 Subject: [PATCH] environment: call prepare for children by default, closes #545 --- RELEASE_NOTES.rst | 2 ++ artiq/language/environment.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.rst b/RELEASE_NOTES.rst index a752b418f..7973d5920 100644 --- a/RELEASE_NOTES.rst +++ b/RELEASE_NOTES.rst @@ -8,6 +8,8 @@ Release notes * The --embed option of applets is replaced with the environment variable ARTIQ_APPLET_EMBED. +* EnvExperiment's prepare calls prepare for all its children. + 2.0rc1 ------ diff --git a/artiq/language/environment.py b/artiq/language/environment.py index 779d74fb8..3a3bed0e4 100644 --- a/artiq/language/environment.py +++ b/artiq/language/environment.py @@ -194,6 +194,7 @@ class HasEnvironment: """Provides methods to manage the environment of an experiment (arguments, devices, datasets).""" def __init__(self, managers_or_parent, *args, **kwargs): + self.children = [] if isinstance(managers_or_parent, tuple): self.__device_mgr = managers_or_parent[0] self.__dataset_mgr = managers_or_parent[1] @@ -202,11 +203,15 @@ class HasEnvironment: self.__device_mgr = managers_or_parent.__device_mgr self.__dataset_mgr = managers_or_parent.__dataset_mgr self.__argument_mgr = managers_or_parent.__argument_mgr + managers_or_parent.register_child(self) self.__in_build = True self.build(*args, **kwargs) self.__in_build = False + def register_child(self, child): + self.children.append(child) + def build(self): """Should be implemented by the user to request arguments. @@ -373,7 +378,11 @@ class EnvExperiment(Experiment, HasEnvironment): environment manager. Most experiment should derive from this class.""" - pass + def prepare(self): + """The default prepare method calls prepare for all children, in the + order of instantiation.""" + for child in self.children: + child.prepare() def is_experiment(o):