Skip to content

Commit eb58aff

Browse files
committed
Add inmem-fom method to all objects
Also refactor the mixin a bit to remove the confusing "_get_app_or_mod_inst" method.
1 parent 3bd7ca3 commit eb58aff

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

var/ramble/repos/builtin/base_classes/modifier-base/base_class.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(self, file_path):
6666
self._on_executables = ["*"]
6767
self.expander = None
6868
self._usage_mode = None
69-
self._app_inst = None
69+
self.app_inst = None
7070

7171
self._verbosity = "short"
7272

@@ -81,6 +81,9 @@ def copy(self):
8181

8282
return new_copy
8383

84+
def satisfy_when(self, when_key):
85+
return self.expander.satisfies(when_key, self.object_variants)
86+
8487
def set_usage_mode(self, mode):
8588
"""Set the usage mode for this modifier.
8689
@@ -157,7 +160,7 @@ def inherit_from_application(self, app):
157160
self.object_variants.merge_multi_value_variants(app.object_variants)
158161
modded_vars = self.modded_variables(app)
159162
self.expander._variables.update(modded_vars)
160-
self._app_inst = app
163+
self.app_inst = app
161164

162165
def define_variable(self, var_name, var_value):
163166
"""Define a variable within this modifier's expander instance"""

var/ramble/repos/builtin/base_classes/object_mixin/base_class.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@
1212
class ObjectMixin:
1313
"""A mixin class for Ramble objects"""
1414

15-
def _get_app_or_mod_inst(self):
16-
# This helper gets the mod_inst for modifier, and the app_inst for others
15+
def _get_app_inst(self):
16+
# This helper gets the app_inst for different object types
1717
if hasattr(self, "app_inst"):
1818
return self.app_inst
1919
return self
2020

21+
def satisfy_when(self, when_key):
22+
app_inst = self._get_app_inst()
23+
return app_inst.expander.satisfies(when_key, app_inst.object_variants)
24+
2125
def get_required_variables(self):
2226
"""Get all the required variables based on the mode and when conditions."""
23-
inst = self._get_app_or_mod_inst()
2427
required_vars = self.required_vars
2528
filtered_vars = {}
2629
if required_vars:
2730
for var_name, var_props in required_vars.items():
28-
if inst.expander.satisfies(
29-
var_props["when"], inst.object_variants
30-
):
31+
if self.satisfy_when(var_props["when"]):
3132
filtered_vars[var_name] = {
3233
# Exclude the extra when prop
3334
k: var_props[k]
@@ -44,9 +45,8 @@ def selected_variables(self):
4445
"""
4546

4647
selected_vars = {}
47-
inst = self._get_app_or_mod_inst()
4848
for when_key, var_list in self.object_variables.items():
49-
if not inst.expander.satisfies(when_key, inst.object_variants):
49+
if not self.satisfy_when(when_key):
5050
continue
5151

5252
for var in var_list:
@@ -63,12 +63,11 @@ def selected_environment_variables(self):
6363
"""
6464

6565
selected_env_vars = {}
66-
inst = self._get_app_or_mod_inst()
6766
for (
6867
when_key,
6968
env_var_list,
7069
) in self.object_environment_variables.items():
71-
if not inst.expander.satisfies(when_key, inst.object_variants):
70+
if not self.satisfy_when(when_key):
7271
continue
7372

7473
for env_var in env_var_list:
@@ -77,4 +76,10 @@ def selected_environment_variables(self):
7776
return selected_env_vars
7877

7978
def format_doc(self, **kwargs):
79+
"""Doc formatting for Sphinx"""
8080
return format.format_doc(self.__doc__, **kwargs)
81+
82+
def add_inmem_fom_value(self, fom_map_key, value):
83+
"""Add an in-memory FOM value"""
84+
app_inst = self._get_app_inst()
85+
app_inst.add_inmem_fom_value(fom_map_key, value)

var/ramble/repos/builtin/modifiers/tunables/modifier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def _prepare_analysis(self, workspace):
107107
metric = next(iter(sum_dict))
108108
else:
109109
metric = sum_dict
110-
self._app_inst.add_inmem_fom_value(n, str(metric))
110+
self.add_inmem_fom_value(n, str(metric))
111111

112112
for conf in info_list:
113113
figure_of_merit(

0 commit comments

Comments
 (0)