Skip to content

Commit

Permalink
verify db MACROS in builder2ibek
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Sep 24, 2023
1 parent 8027f2a commit a43a165
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(self, support_module_path, arg_value_overrides):
Builder2Support.arg_value_overrides = arg_value_overrides
self.yaml_tree = ordereddict()
self.builder_module, self.builder_classes = self._configure()
self.def_args = {} # Dict[def name: [Arg names]]

def _configure(self):
"""
Expand Down Expand Up @@ -220,7 +221,7 @@ def _instantiate_builder_objects(self, args, builder_class):
# instantiate a builder object using our mock arguments
return builder_class(**args_dict)

def _extract_substitutions(self):
def _extract_substitutions(self, name):
"""
Extract all of the database substitutions from the builder class
and populate the ibek YAML database object graph.
Expand Down Expand Up @@ -250,9 +251,15 @@ def _extract_substitutions(self):

database["args"] = {a[0]: None for a in first_substitution.args.items()}

missing = set(database["args"].keys()) - set(self.def_args[name])
if len(missing) > 0:
missed = ", ".join(missing)
database["warning"] = "MACROS missing from args: " + missed
return databases

def _make_init_script(self, builder_object, func_name, typ, script, when=None):
def _make_init_script(
self, builder_object, func_name, typ, script, name, when=None
):
"""
Find the source code for a builder class method and create an object
graph representing as script entries in the ibek YAML file.
Expand All @@ -276,7 +283,7 @@ def _make_init_script(self, builder_object, func_name, typ, script, when=None):
script_item["value"] = PreservedScalarString(commands)
script.append(script_item)

def _call_initialise(self, builder_object):
def _call_initialise(self, builder_object, name):
"""
Extract the code from the builder class Initialise() method
to insert into the ibek YAML script object graph.
Expand All @@ -288,10 +295,14 @@ def _call_initialise(self, builder_object):
pre_init = []
post_init = []
self._make_init_script(
builder_object, "InitialiseOnce", "text", pre_init, when="first"
builder_object, "InitialiseOnce", "text", pre_init, when="first", name=name
)
self._make_init_script(
builder_object, "Initialise", "text", pre_init, name=name
)
self._make_init_script(
builder_object, "PostIocInitialise", "text", post_init, name=name
)
self._make_init_script(builder_object, "Initialise", "text", pre_init)
self._make_init_script(builder_object, "PostIocInitialise", "text", post_init)

return pre_init, post_init

Expand All @@ -317,10 +328,16 @@ def make_yaml_tree(self):

for name, builder_class in self.builder_classes.items():
one_def, builder_object = self._make_builder_object(name, builder_class)
self.def_args[name] = [arg["name"] for arg in one_def["args"]]

yaml_defs.append(one_def)
builder_objects.append(builder_object)
one_def["databases"] = self._extract_substitutions()
pre_init, post_init = self._call_initialise(builder_object)

databases = self._extract_substitutions(name)
if len(databases) > 0:
one_def["databases"] = databases
pre_init, post_init = self._call_initialise(builder_object, name)

if len(pre_init) > 0:
one_def["pre_init"] = pre_init
if len(post_init) > 0:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ select = [
"I001", # isort
]
[tool.ruff.per-file-ignores]
"dls_builder_conversion/builder2ibek.support.py" = ["E402"]
"builder2ibek.support.py" = ["E402"]

0 comments on commit a43a165

Please sign in to comment.