Skip to content
Open
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
17 changes: 16 additions & 1 deletion src/techui_builder/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Interface for ``python -m techui_builder``."""

import logging
from typing import Annotated

import typer

from techui_builder._logger import log_level
from techui_builder._version import __version__
from techui_builder.generate_jsonmap import app as generate_jsonmap_app
from techui_builder.main_app import app as main_app
Expand Down Expand Up @@ -54,8 +56,21 @@ def _(
is_eager=True,
help="Show version of techui-builder and exit",
),
loglevel: Annotated[
str,
typer.Option(
"--log-level",
"-l",
help="Set log level to INFO, DEBUG, WARNING, ERROR or CRITICAL",
case_sensitive=False,
callback=log_level,
),
] = "INFO",
Comment thread
adedamola-sode marked this conversation as resolved.
):
"""Boilerplate callback function to allow for --version CLI option"""
"""
Boilerplate callback function to allow for --version
and global --log-level CLI options
"""
pass


Expand Down
15 changes: 0 additions & 15 deletions src/techui_builder/generate_jsonmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@
from lxml import etree, objectify
from lxml.objectify import ObjectifiedElement

from techui_builder._logger import Logger
from techui_builder.models import TechUi

logger_ = logging.getLogger(__name__)


def log_level(level: str):
Logger(level)


app = typer.Typer(
pretty_exceptions_show_locals=False,
context_settings={"allow_interspersed_args": True},
Expand Down Expand Up @@ -474,16 +469,6 @@ def generate_jsonmap(
Path,
typer.Argument(help="Top level bobfile to generate json mapping from."),
],
loglevel: Annotated[
str,
typer.Option(
"--log-level",
"-l",
help="Set log level to INFO, DEBUG, WARNING, ERROR or CRITICAL",
case_sensitive=False,
callback=log_level,
),
] = "INFO",
) -> None:
"""Default function called from cmd line tool."""
jg = JsonMapGenerator(bob_path=bob_path)
Expand Down
11 changes: 0 additions & 11 deletions src/techui_builder/main_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import typer

from techui_builder._logger import log_level
from techui_builder.autofill import Autofiller
from techui_builder.builder import Builder

Expand Down Expand Up @@ -76,16 +75,6 @@ def main(
Path | None,
typer.Argument(help="Override for template bob file location."),
] = None,
loglevel: Annotated[
str,
typer.Option(
"--log-level",
"-l",
help="Set log level to INFO, DEBUG, WARNING, ERROR or CRITICAL",
case_sensitive=False,
callback=log_level,
),
] = "INFO",
) -> None:
"""Default function called from cmd line tool."""

Expand Down
29 changes: 1 addition & 28 deletions src/techui_builder/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import logging
import re
from typing import Annotated, Any, Literal
from typing import Annotated, Any

from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
StringConstraints,
computed_field,
field_validator,
model_validator,
Expand Down Expand Up @@ -235,31 +233,6 @@ class TechUi(BaseModel):
techui-support mapping models
"""

BobPath = Annotated[
str, StringConstraints(pattern=r"^(?:[A-Za-z0-9_.-]+/)*[A-Za-z0-9_.-]+\.bob$")
]
# Must contain at least one $(NAME) macro
MacroString = Annotated[
str,
StringConstraints(pattern=r"^[A-Za-z0-9_:\-./\s\$\(\)]+$"),
]
Comment thread
adedamola-sode marked this conversation as resolved.
ScreenType = Literal["embedded", "related"]


class GuiComponentEntry(BaseModel):
file: BobPath
prefix: MacroString
suffix: MacroString | None = None
type: ScreenType
model_config = ConfigDict(extra="forbid")


GuiComponentUnion = list[GuiComponentEntry] | GuiComponentEntry


class GuiComponents(RootModel[dict[str, GuiComponentUnion]]):
pass


class Entity(BaseModel):
"""One table of IOC variables extracted from an ioc.yaml file"""
Expand Down
4 changes: 2 additions & 2 deletions src/techui_builder/schema_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import typer

from techui_builder.models import (
GuiComponents,
TechUi,
TechUiSupport,
)

SCHEMAS_DIR = Path("schemas")
Expand All @@ -31,5 +31,5 @@ def schema_generator() -> None:
write_json_schema("techui", tu)

# ibek_mapping
tu_support = GuiComponents.model_json_schema()
tu_support = TechUiSupport.model_json_schema()
write_json_schema("techui.support", tu_support)
2 changes: 1 addition & 1 deletion src/techui_builder/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

app = typer.Typer(
help="""
A script for generating status PVs for a techui.yaml file.
Generate status PVs for a techui.yaml file.
""",
context_settings={"allow_interspersed_args": True},
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from typer.testing import CliRunner

from techui_builder.__main__ import app
from techui_builder._logger import log_level
from techui_builder.generate_jsonmap import app as generate_jsonmap_app

# from techui_builder.main_app import app as main_app
from techui_builder.main_app import (
default_bobfile,
find_bob,
find_dirs,
log_level,
main,
)
from techui_builder.schema_generator import app as schema_app
Expand Down
7 changes: 0 additions & 7 deletions tests/test_generate_jsonmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,11 @@
_get_nav_tabs, # type: ignore
_serialise_json_map,
app,
log_level,
)

runner = CliRunner()


@patch("techui_builder.generate_jsonmap.Logger")
def test_log_level(mock_logger):
log_level("INFO")
mock_logger.assert_called_once()


def test_write_json_map_no_synoptic(json_map_generator):
with pytest.raises(FileNotFoundError):
json_map_generator.bob_path = Path("Synoptic")
Expand Down
29 changes: 11 additions & 18 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from techui_builder.models import (
Beamline,
Component,
GuiComponentEntry,
GuiComponents,
SupportEntity,
)


Expand All @@ -29,9 +28,11 @@ def component() -> Component:


@pytest.fixture
def gui_components() -> GuiComponentEntry:
return GuiComponentEntry(
file="digitelMpc/digitelMpcIonp.bob", prefix="$(P)", type="embedded"
def support_entity() -> SupportEntity:
return SupportEntity(
prefix="{{ P }}",
macros=["P"],
screens=[{"file": "digitelMpc/digitelMpcIonp.bob", "type": "embedded"}],
)


Expand Down Expand Up @@ -67,16 +68,8 @@ def test_component_bad_prefix():
Component(prefix="Test 2", label="BAD_PREFIX")


def test_gui_component_entry(gui_components: GuiComponentEntry):
assert gui_components.file == "digitelMpc/digitelMpcIonp.bob"
assert gui_components.prefix == "$(P)"
assert gui_components.type == "embedded"


def test_gui_components_object(gui_components: GuiComponentEntry):
gc = GuiComponents({"digitelMpc.digitelMpcIonp": [gui_components]})
entry = gc.root["digitelMpc.digitelMpcIonp"][0] # type: ignore
assert entry.file == "digitelMpc/digitelMpcIonp.bob"

assert entry.prefix == "$(P)"
assert entry.type == "embedded"
def test_gui_component_entry(support_entity: SupportEntity):
assert support_entity.prefix == "{{ P }}"
assert support_entity.macros == ["P"]
assert support_entity.screens[0]["file"] == "digitelMpc/digitelMpcIonp.bob"
assert support_entity.screens[0]["type"] == "embedded"