diff --git a/example/t01-services/synoptic/techui.yaml b/example/t01-services/synoptic/techui.yaml index 74daf576..ffd9f59a 100644 --- a/example/t01-services/synoptic/techui.yaml +++ b/example/t01-services/synoptic/techui.yaml @@ -1,7 +1,7 @@ # create_gui example for Phoebus GuiBuilder beamline: - location: t01 - domain: bl01t + location: bl01t + domain: t01 desc: Test Beamline url: t01-opis.diamond.ac.uk diff --git a/src/techui_builder/builder.py b/src/techui_builder/builder.py index af9b7d0e..3f44b0ec 100644 --- a/src/techui_builder/builder.py +++ b/src/techui_builder/builder.py @@ -105,7 +105,7 @@ def _extract_services(self): """ # Loop over every dir in services, ignoring anything that isn't a service - for service in self._services_dir.glob(f"{self.conf.beamline.domain}-*-*-*"): + for service in self._services_dir.glob(f"{self.conf.beamline.location}-*-*-*"): service_name = service.name # If service doesn't exist, file open will fail throwing exception try: diff --git a/src/techui_builder/models.py b/src/techui_builder/models.py index 20130b4e..63909e13 100644 --- a/src/techui_builder/models.py +++ b/src/techui_builder/models.py @@ -50,40 +50,40 @@ r"(?:PP|NPP)?" + r"(?:[ ]+(?:MS|NMS|MSS|MSI))?$", re.VERBOSE, ) -_DOMAIN_RE = re.compile(r"^[a-zA-Z]{2}\d{2}[a-zA-Z]$") -_LOCATION_RE = re.compile(r"^[a-zA-Z]{1}\d{2}(-[0-9]{1})?$") +_LOCATION_RE = re.compile(r"^[a-zA-Z]{2}\d{2}[a-zA-Z]$") +_DOMAIN_RE = re.compile(r"^[a-zA-Z]{1}\d{2}(-[0-9]{1})?$") _OPIS_URL_RE = re.compile(r"^(https:\/\/)?([a-z0-9]{3}-(?:[0-9]-)?opis(?:.[a-z0-9]*)*)") class Beamline(BaseModel): """Global Beamline values read from `beamline:` table in techui.yaml""" - location: Annotated[str, Field(description="Short BL location e.g. b23, ixx-1")] - domain: Annotated[str, Field(description="Full BL domain e.g. bl23b")] + domain: Annotated[str, Field(description="Short BL location e.g. b23, ixx-1")] + location: Annotated[str, Field(description="Full BL domain e.g. bl23b")] desc: Annotated[str, Field(description="Description")] url: Annotated[str, Field(description="URL of ixx-opis")] model_config = ConfigDict(extra="forbid") - @field_validator("location") + @field_validator("domain") @classmethod - def normalize_location(cls, v: str) -> str: + def normalize_domain(cls, v: str) -> str: v = v.strip().lower() - if _LOCATION_RE.fullmatch(v): - # e.g. b23 -> bl23b + if _DOMAIN_RE.fullmatch(v): + # e.g. t01 return v - raise ValueError("Invalid beamline location.") + raise ValueError("Invalid beamline domain.") - @field_validator("domain") + @field_validator("location") @classmethod - def normalize_domain(cls, v: str) -> str: + def normalize_location(cls, v: str) -> str: v = v.strip().lower() - if _DOMAIN_RE.fullmatch(v): - # already long: bl23b + if _LOCATION_RE.fullmatch(v): + # already long: bl01t return v - raise ValueError("Invalid beamline domain.") + raise ValueError("Invalid beamline location.") @field_validator("url") @classmethod diff --git a/tests/test_builder.py b/tests/test_builder.py index eb4733dd..653bee05 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -8,8 +8,8 @@ @pytest.mark.parametrize( "attr, expected", [ - ("location", "t01"), - ("domain", "bl01t"), + ("location", "bl01t"), + ("domain", "t01"), ("desc", "Test Beamline"), ], ) @@ -152,7 +152,7 @@ def test_gb_extract_services_no_yaml_files(builder, caplog, tmp_path): builder._extract_entities = Mock() # overwrite to not see the bl01t service dirs - builder.conf.beamline.domain = "bl01z" + builder.conf.beamline.location = "bl01z" builder._services_dir = tmp_path # Temporary files to test against (tmp_path / "bl01z-ea-ioc-01").mkdir() @@ -171,7 +171,7 @@ def test_gb_extract_services_both_yaml_files(builder, caplog, tmp_path): builder._extract_entities = Mock() # overwrite to not see the bl01t service dirs - builder.conf.beamline.domain = "bl01z" + builder.conf.beamline.location = "bl01z" builder._services_dir = tmp_path # Temporary files to test against (tmp_path / "bl01z-ea-ioc-01").mkdir() diff --git a/tests/test_models.py b/tests/test_models.py index a31d73ff..7d6c080d 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -11,8 +11,8 @@ @pytest.fixture def beamline() -> Beamline: return Beamline( - location="t01", - domain="bl01t", + location="bl01t", + domain="t01", desc="Test Beamline", url="t01-opis.diamond.ac.uk", ) @@ -37,8 +37,8 @@ def gui_components() -> GuiComponentEntry: # @pytest.mark.parametrize("beamline,expected",[]) def test_beamline_object(beamline: Beamline): - assert beamline.location == "t01" - assert beamline.domain == "bl01t" + assert beamline.location == "bl01t" + assert beamline.domain == "t01" assert beamline.desc == "Test Beamline" assert beamline.url == "https://t01-opis.diamond.ac.uk"