From 58351d40678b58330385c007c068ef39d5653824 Mon Sep 17 00:00:00 2001 From: Ollie Copping Date: Thu, 18 Dec 2025 10:23:44 +0000 Subject: [PATCH 1/3] Pass beamline url through to Generator and use in IOC macro --- src/techui_builder/builder.py | 2 +- src/techui_builder/generate.py | 4 ++++ tests/conftest.py | 9 +++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/techui_builder/builder.py b/src/techui_builder/builder.py index 9dafd84..6338f0f 100644 --- a/src/techui_builder/builder.py +++ b/src/techui_builder/builder.py @@ -62,7 +62,7 @@ def setup(self): self.clean_files() - self.generator = Generator(synoptic_dir) + self.generator = Generator(synoptic_dir, self.conf.beamline.url) def clean_files(self): exclude = {"index.bob"} diff --git a/src/techui_builder/generate.py b/src/techui_builder/generate.py index 963038b..2795ab2 100644 --- a/src/techui_builder/generate.py +++ b/src/techui_builder/generate.py @@ -20,6 +20,7 @@ @dataclass class Generator: synoptic_dir: Path = field(repr=False) + beamline_url: str = field(repr=False) # These are global params for the class (not accessible by user) support_path: Path = field(init=False, repr=False) @@ -220,6 +221,9 @@ def _allocate_widget( new_widget.macro( f"{suffix_label}", suffix.removeprefix(":").removesuffix(":") ) + # TODO: Change this to pvi_button + if True: + new_widget.macro("IOC", f"{self.beamline_url}/{component.P.lower()}") # The only other option is for related displays else: diff --git a/tests/conftest.py b/tests/conftest.py index fe0a905..d68d62c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -60,7 +60,7 @@ def example_json_map(): def generator(): synoptic_dir = Path(__file__).parent.joinpath(Path("t01-services/synoptic")) - g = Generator(synoptic_dir) + g = Generator(synoptic_dir, "test_url") return g @@ -97,9 +97,10 @@ def example_embedded_widget(): height_element = SubElement(widget_element, "height") height_element.text = "120" file_element = SubElement(widget_element, "file") - file_element.text = ( - "example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob" - ) + file_element.text = "tests/test-files/motor_embed.bob" + macros_element = SubElement(widget_element, "macros") + macro_element_1 = SubElement(macros_element, "macro1") + macro_element_1.text = "test_macro_1" # ... which requires this horror widget_element = fromstring(tostring(widget_element)) From 888e9dc8a195e0085b0b5ebe8a9c9b9127150ef4 Mon Sep 17 00:00:00 2001 From: Ollie Copping Date: Thu, 18 Dec 2025 10:25:51 +0000 Subject: [PATCH 2/3] Update motor_embed.bob files to match techui-support --- .../synoptic/techui-support/bob/pmac/motor_embed.bob | 6 +++++- tests/test_files/motor-edited.bob | 2 +- tests/test_files/motor_embed.bob | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/example-synoptic/b23-services/synoptic/techui-support/bob/pmac/motor_embed.bob b/example-synoptic/b23-services/synoptic/techui-support/bob/pmac/motor_embed.bob index 1508bca..5c76313 100644 --- a/example-synoptic/b23-services/synoptic/techui-support/bob/pmac/motor_embed.bob +++ b/example-synoptic/b23-services/synoptic/techui-support/bob/pmac/motor_embed.bob @@ -76,7 +76,11 @@ OpenDisplay - ./MOTOR.bob + $(IOC)/pmacAxis.pvi.bob + + :$(M) +

$(P)

+
tab Open Display
diff --git a/tests/test_files/motor-edited.bob b/tests/test_files/motor-edited.bob index 93e1b4c..06900ea 100644 --- a/tests/test_files/motor-edited.bob +++ b/tests/test_files/motor-edited.bob @@ -12,7 +12,7 @@ X 205 120 - example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob + tests/test-files/motor_embed.bob

BL01T-MO-MOTOR-01

X diff --git a/tests/test_files/motor_embed.bob b/tests/test_files/motor_embed.bob index 1508bca..5c76313 100644 --- a/tests/test_files/motor_embed.bob +++ b/tests/test_files/motor_embed.bob @@ -76,7 +76,11 @@ OpenDisplay - ./MOTOR.bob + $(IOC)/pmacAxis.pvi.bob + + :$(M) +

$(P)

+
tab Open Display
From c4db30060efd6900006bebaf0dc26bee7744c686 Mon Sep 17 00:00:00 2001 From: Ollie Copping Date: Thu, 18 Dec 2025 10:26:29 +0000 Subject: [PATCH 3/3] Add functionality to validating macros --- src/techui_builder/validator.py | 40 +++++++++++++++++++++++++++++++++ tests/test_files/widget.xml | 1 + tests/test_validator.py | 3 ++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/techui_builder/validator.py b/src/techui_builder/validator.py index 5261326..280883c 100644 --- a/src/techui_builder/validator.py +++ b/src/techui_builder/validator.py @@ -4,6 +4,7 @@ from pathlib import Path from lxml import etree +from lxml.objectify import ObjectifiedElement from phoebusgen.widget.widgets import ActionButton, EmbeddedDisplay from techui_builder.utils import read_bob @@ -74,4 +75,43 @@ def validate_bob( f"{pwidget.get_element_value('file')} != {file_widget.file}" ) + self._validate_macros(pwidget, file_widget) + LOGGER.info(f"{screen_name}.bob has been validated successfully") + + def _validate_macros( + self, pwidget: EmbeddedDisplay | ActionButton, file_widget: ObjectifiedElement + ): + pmacros_element = pwidget.find_element("macros") + # Annoyingly iterating over this also includes the element tag\ + # so it needs ignoring, hence the '!= "macros"' + pmacros = { + macro.tag: macro.text for macro in pmacros_element if macro.tag != "macros" + } + pmacros_keys = set(pmacros.keys()) + + fmacros = file_widget.macros.getchildren() + fmacros_keys = {str(macro.tag) for macro in fmacros} + + # Checks if there is any difference in expected macros + diff_expected_macros = pmacros_keys - fmacros_keys + if diff_expected_macros: + LOGGER.error( + f"Expected macros {diff_expected_macros} missing from \ +{file_widget.name}." + ) + + # ---------- This is how we could overwrite macros in the future ---------- + + # for expected_macro in diff_expected_macros: + # macro_element = Element(expected_macro) + # # Get the macro value from generated pwidget macros + # macro_element.text = pmacros[expected_macro] + # print(pmacros[expected_macro]) + + # # Convert xml.etree.Element to ObjectifiedElement + # new_macro = fromstring(tostring(macro_element)) + + # file_widget.macros.append(new_macro) + + # write_bob("") diff --git a/tests/test_files/widget.xml b/tests/test_files/widget.xml index 56ef39e..ddda161 100644 --- a/tests/test_files/widget.xml +++ b/tests/test_files/widget.xml @@ -9,5 +9,6 @@

BL23B-DI-MOD-02

CAM + test_url/bl23b-di-mod-02
diff --git a/tests/test_validator.py b/tests/test_validator.py index 3936c43..08cd74e 100644 --- a/tests/test_validator.py +++ b/tests/test_validator.py @@ -49,11 +49,12 @@ def test_validator_validate_bob(validator, example_embedded_widget): validator.validate = {"motor-edited": Path("tests/test_files/motor-edited.bob")} test_pwidget = EmbeddedDisplay( "motor", - "example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob", + "tests/test-files/motor_embed.bob", 0, 0, 205, 120, ) + test_pwidget.macro("macro1", "test_macro_1") validator.validate_bob("motor-edited", "motor", [test_pwidget])