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:
short_dom: t01
long_dom: bl01t
location: t01
domain: bl01t
desc: Test Beamline
url: t01-opis.diamond.ac.uk

Expand Down
10 changes: 5 additions & 5 deletions src/techui_builder/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def main(
(
ixx_services.relative_to(cwd, walk_up=True)
for parent in abs_path.parents
for ixx_services in parent.glob(f"{gui.conf.beamline.short_dom}-services")
for ixx_services in parent.glob(f"{gui.conf.beamline.location}-services")
),
None,
)
Expand Down Expand Up @@ -148,7 +148,7 @@ def main(
logger_.debug(
f"""

Builder created for {gui.conf.beamline.short_dom}.
Builder created for {gui.conf.beamline.location}.
Services directory: {gui._services_dir}
Write directory: {gui._write_directory}
""", # noqa: SLF001
Expand All @@ -158,7 +158,7 @@ def main(
gui.create_screens()
gui.write_status_pvs()

logger_.info(f"Screens generated for {gui.conf.beamline.short_dom}.")
logger_.info(f"Screens generated for {gui.conf.beamline.location}.")

autofiller = Autofiller(bob_file)
autofiller.read_bob()
Expand All @@ -168,11 +168,11 @@ def main(

autofiller.write_bob(dest_bob)

logger_.info(f"Screens autofilled for {gui.conf.beamline.short_dom}.")
logger_.info(f"Screens autofilled for {gui.conf.beamline.location}.")

gui.write_json_map(synoptic=dest_bob, dest=gui._write_directory) # noqa: SLF001
logger_.info(
f"Json map generated for {gui.conf.beamline.short_dom} (from index.bob)"
f"Json map generated for {gui.conf.beamline.location} (from index.bob)"
)


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 @@ -155,7 +155,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.long_dom}-*-*-*"):
for service in self._services_dir.glob(f"{self.conf.beamline.domain}-*-*-*"):
# If service doesn't exist, file open will fail throwing exception
try:
self._extract_entities(ioc_yaml=service.joinpath("config/ioc.yaml"))
Expand Down
24 changes: 12 additions & 12 deletions src/techui_builder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,38 @@
r"(?:PP|NPP)?" + r"(?:[ ]+(?:MS|NMS|MSS|MSI))?$",
re.VERBOSE,
)
_LONG_DOM_RE = re.compile(r"^[a-zA-Z]{2}\d{2}[a-zA-Z]$")
_SHORT_DOM_RE = re.compile(r"^[a-zA-Z]{1}\d{2}(-[0-9]{1})?$")
_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})?$")
_OPIS_URL_RE = re.compile(r"^(https:\/\/)?([a-z0-9]{3}-(?:[0-9]-)?opis(?:.[a-z0-9]*)*)")


class Beamline(BaseModel):
short_dom: str = Field(description="Short BL domain e.g. b23, ixx-1")
long_dom: str = Field(description="Full BL domain e.g. bl23b")
location: str = Field(description="Short BL location e.g. b23, ixx-1")
domain: str = Field(description="Full BL domain e.g. bl23b")
desc: str = Field(description="Description")
model_config = ConfigDict(extra="forbid")
url: str = Field(description="URL of ixx-opis")

@field_validator("short_dom")
@field_validator("location")
@classmethod
def normalize_short_dom(cls, v: str) -> str:
def normalize_location(cls, v: str) -> str:
v = v.strip().lower()

if _SHORT_DOM_RE.fullmatch(v):
if _LOCATION_RE.fullmatch(v):
# e.g. b23 -> bl23b
return v

raise ValueError("Invalid short dom.")
raise ValueError("Invalid beamline location.")

@field_validator("long_dom")
@field_validator("domain")
@classmethod
def normalize_long_dom(cls, v: str) -> str:
def normalize_domain(cls, v: str) -> str:
v = v.strip().lower()
if _LONG_DOM_RE.fullmatch(v):
if _DOMAIN_RE.fullmatch(v):
# already long: bl23b
return v

raise ValueError("Invalid long dom.")
raise ValueError("Invalid beamline domain.")

@field_validator("url")
@classmethod
Expand Down
4 changes: 2 additions & 2 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
@pytest.mark.parametrize(
"attr, expected",
[
("short_dom", "t01"),
("long_dom", "bl01t"),
("location", "t01"),
("domain", "bl01t"),
("desc", "Test Beamline"),
],
)
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(
short_dom="t01",
long_dom="bl01t",
location="t01",
domain="bl01t",
desc="Test Beamline",
url="t01-opis.diamond.ac.uk",
)
Expand All @@ -34,8 +34,8 @@ def gui_components() -> GuiComponentEntry:

# @pytest.mark.parametrize("beamline,expected",[])
def test_beamline_object(beamline: Beamline):
assert beamline.short_dom == "t01"
assert beamline.long_dom == "bl01t"
assert beamline.location == "t01"
assert beamline.domain == "bl01t"
assert beamline.desc == "Test Beamline"
assert beamline.url == "https://t01-opis.diamond.ac.uk"

Expand Down