Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/t01-services/synoptic/techui.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/techui_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 14 additions & 14 deletions src/techui_builder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
@pytest.mark.parametrize(
"attr, expected",
[
("location", "t01"),
("domain", "bl01t"),
("location", "bl01t"),
("domain", "t01"),
("desc", "Test Beamline"),
],
)
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand All @@ -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"

Expand Down