Skip to content

Commit

Permalink
feat(setup_executor.py): remove method `update_inner_referenced_featu…
Browse files Browse the repository at this point in the history
…re_instances()` from variation_executor and move similar method in setup executor
  • Loading branch information
matosys committed Jun 27, 2024
1 parent 95663e2 commit 30a9c22
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
32 changes: 32 additions & 0 deletions src/_balder/executor/setup_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from _balder.executor.scenario_executor import ScenarioExecutor
from _balder.previous_executor_mark import PreviousExecutorMark
from _balder.controllers.setup_controller import SetupController
from _balder.controllers.device_controller import DeviceController
from _balder.controllers.feature_controller import FeatureController

if TYPE_CHECKING:
from _balder.setup import Setup
Expand Down Expand Up @@ -72,6 +74,8 @@ def fixture_manager(self) -> FixtureManager:

def _prepare_execution(self, show_discarded):
print(f"SETUP {self.base_setup_class.__class__.__name__}")
if not show_discarded:
self.update_inner_referenced_feature_instances()

def _body_execution(self, show_discarded):
for cur_scenario_executor in self.get_scenario_executors():
Expand All @@ -89,6 +93,34 @@ def _cleanup_execution(self, show_discarded):

# ---------------------------------- METHODS -----------------------------------------------------------------------

def update_inner_referenced_feature_instances(self):
"""
This method ensures that all inner referenced feature instances of all devices that are used in this setup are
set to the correct feature instance. For every existing device, this method goes trough all assigned features
and checks for a inner-referenced feature. It makes sure, that every inner-referenced feature variable has the
final assigned setup feature that belongs to it.
# TODO check where we validate that inner references feature exists in setup
"""
for cur_setup_device in self.base_setup_controller.get_all_abs_inner_device_classes():
# these features are subclasses of the real defined one (because they are already the replaced ones)
all_device_features = DeviceController.get_for(cur_setup_device).get_all_instantiated_feature_objects()
all_instantiated_feature_objs_of_this_dev = [cur_feature for _, cur_feature in all_device_features.items()]
for _, cur_feature in all_device_features.items():
cur_feature_controller = FeatureController.get_for(cur_feature.__class__)
# now check the inner referenced features of this feature and check if that exists in the device
for cur_ref_feature_name, cur_ref_feature in \
cur_feature_controller.get_inner_referenced_features().items():
potential_candidates = [
candidate_feature for candidate_feature in all_instantiated_feature_objs_of_this_dev
if isinstance(candidate_feature, cur_ref_feature.__class__)]
if len(potential_candidates) != 1:
raise RuntimeError("found none or more than one potential replacing candidates")
replacing_candidate = potential_candidates[0]
# because `cur_feature` is only the object instance, the value will be overwritten only for this
# object
setattr(cur_feature, cur_ref_feature_name, replacing_candidate)

def get_scenario_executors(self) -> List[ScenarioExecutor]:
"""returns a list with all scenario executors that belongs to this setup executor"""
return self._scenario_executors
Expand Down
29 changes: 0 additions & 29 deletions src/_balder/executor/variation_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def _prepare_execution(self, show_discarded):
self.determine_abs_variation_connections()
self.update_scenario_device_feature_instances()
self.update_active_vdevice_device_mappings_in_all_features()
self.update_inner_referenced_feature_instances()
self.exchange_unmapped_vdevice_references()
self.update_vdevice_referenced_feature_instances()
self.set_conn_dependent_methods()
Expand Down Expand Up @@ -563,34 +562,6 @@ def revert_active_vdevice_device_mappings_in_all_features(self):
for cur_feature, cur_original_mapping in cur_feature_mapping_dict.items():
cur_feature.active_vdevices = cur_original_mapping

def update_inner_referenced_feature_instances(self):
"""
This method ensures that all inner referenced feature instances of the used feature object, will be replaced
with the related feature instances of the device object itself.
.. note::
Note that this method expects that the true defined scenario features are already replaced with the real
setup features. So the method requires that the method `update_scenario_device_feature_instances()` was
called before.
"""
for scenario_device, _ in self._base_device_mapping.items():
# these features are subclasses of the real defined one (because they are already the replaced ones)
all_device_features = DeviceController.get_for(scenario_device).get_all_instantiated_feature_objects()
all_instantiated_feature_objs = [cur_feature for _, cur_feature in all_device_features.items()]
for _, cur_feature in all_device_features.items():
cur_feature_controller = FeatureController.get_for(cur_feature.__class__)
# now check the inner referenced features of this feature and check if that exists in the device
for cur_ref_feature_name, cur_ref_feature in \
cur_feature_controller.get_inner_referenced_features().items():
potential_candidates = [candidate_feature for candidate_feature in all_instantiated_feature_objs
if isinstance(candidate_feature, cur_ref_feature.__class__)]
if len(potential_candidates) != 1:
raise RuntimeError("found none or more than one potential replacing candidates")
replacing_candidate = potential_candidates[0]
# because `cur_feature` is only the object instance, the value will be overwritten only for this
# object
setattr(cur_feature, cur_ref_feature_name, replacing_candidate)

def exchange_unmapped_vdevice_references(self):
"""
This method exchanges all :class:`VDevice` references to an instance of :class:`UnmappedVDevice` if the
Expand Down

0 comments on commit 30a9c22

Please sign in to comment.