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
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ requires = ["setuptools>=64", "setuptools_scm[toml]>=8"]
build-backend = "setuptools.build_meta"

[project]
scripts = { techui-builder = "techui_builder.__main__:app", generate-jsonmap = "techui_builder.generate_jsonmap:app" }

name = "techui-builder"
dynamic = ["version"]
description = "A package for building Phoebus GUIs"
Expand All @@ -16,6 +18,7 @@ authors = [
{ name = "Oliver Copping", email = "oliver.copping@diamond.ac.uk" },
{ name = "Adedamola Sode", email = "adedamola.sode@diamond.ac.uk" },
{ name = "Niamh Dougan", email = "niamh.dougan@diamond.ac.uk" },
{ name = "Thomas Kane", email = "thomas.kane@diamond.ac.uk" },
]
license-files = ["LICENSE"]
readme = "README.md"
Expand All @@ -30,8 +33,6 @@ dependencies = [
"softioc>=4.7.0",
"epicsdbbuilder>=1.5",
]
scripts = { techui-builder = "techui_builder.__main__:app" }

[dependency-groups]
dev = [
"copier",
Expand Down
37 changes: 31 additions & 6 deletions src/techui_builder/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
from techui_builder._logger import Logger
from techui_builder.autofill import Autofiller
from techui_builder.builder import Builder
from techui_builder.generate_jsonmap import JsonMapGenerator
from techui_builder.schema_generator import schema_generator

logger_ = logging.getLogger(__name__)

app = typer.Typer(
pretty_exceptions_show_locals=False,
context_settings={"allow_interspersed_args": True},
help="""
A script for building Phoebus GUIs.

Expand Down Expand Up @@ -112,10 +114,22 @@ def find_bob(bob_file: Path | None, synoptic_dir: Path):
# This is the default behaviour when no command provided
@app.callback(invoke_without_command=True)
def main(
filename: Annotated[Path, typer.Argument(help="The path to techui.yaml")],
filename: Annotated[
Path | None, typer.Argument(help="The path to techui.yaml")
] = None,
bobfile: Annotated[
Path | None,
typer.Argument(help="Override for template bob file location."),
typer.Option(
"--bob-file", "-b", help="Override for template bob file location."
),
] = None,
generate_json_map: Annotated[
str | None,
typer.Option(
"--generate-jsonmap",
"-j",
help="Generate json mapping for screens in synoptic/ from index.bob.",
),
] = None,
version: Annotated[
bool | None, typer.Option("--version", callback=version_callback)
Expand All @@ -141,6 +155,18 @@ def main(
) -> None:
"""Default function called from cmd line tool."""

if (generate_json_map is not None) and (filename is None):
if not generate_json_map.endswith(".bob"):
raise typer.BadParameter(
"Json map generation requires a bob file as input."
)
JsonMapGenerator(bob_path=Path(generate_json_map)).write_json_map()
logger_.info(f"Json map generated for (from {generate_json_map})")
return

if filename is None:
raise typer.BadParameter("Techui.yaml file must be provided as an argument.")

gui = Builder(techui=filename)

ixx_services_dir, synoptic_dir = find_dirs(filename, gui.conf.beamline.location)
Expand Down Expand Up @@ -176,10 +202,9 @@ def main(

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.location} (from index.bob)"
)
if generate_json_map is not None:
JsonMapGenerator(bob_path=bob_file).write_json_map()
logger_.info("Json map generated for (from index.bob)")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion src/techui_builder/autofill.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from lxml.etree import Element, SubElement, tostring
from lxml.objectify import ObjectifiedElement, fromstring

from techui_builder.builder import _get_action_group
from techui_builder.generate_jsonmap import _get_action_group
from techui_builder.models import Component
from techui_builder.utils import read_bob

Expand Down
Loading