Skip to content

Commit

Permalink
Include standard ibek definitions in ioc generate-schema
Browse files Browse the repository at this point in the history
This PR has highlighted an issue that CI needs to know where
to find the ibek support YAML - but ibek already knows

Added --ibek-defs for use in CI to generate schema without
breaking each time we move the /epics/ibek-defs folder. This
is the default.

The regenerate_samples.sh script can use --no-ibek-defs to
only include the given support yaml definitions.
  • Loading branch information
gilesknap authored and GDYendell committed Nov 10, 2023
1 parent 5480797 commit e307124
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
23 changes: 21 additions & 2 deletions src/ibek/ioc_cmds/commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
import shutil
import subprocess
from pathlib import Path
Expand All @@ -9,16 +10,19 @@

from ibek.gen_scripts import ioc_create_model
from ibek.globals import (
IBEK_DEFS,
IOC_DBDS,
IOC_FOLDER,
IOC_LIBS,
SUPPORT_YAML_PATTERN,
TEMPLATES,
NaturalOrderGroup,
)
from ibek.ioc_cmds.docker import build_dockerfile

from .assets import extract_assets, get_ioc_source

log = logging.getLogger(__name__)
ioc_cli = typer.Typer(cls=NaturalOrderGroup)


Expand All @@ -44,18 +48,33 @@ def build_docker(
@ioc_cli.command()
def generate_schema(
definitions: List[Path] = typer.Argument(
...,
None, # Note: typer converts None to an empty list because the type is List
help="File paths to one or more support module YAML files",
),
output: Annotated[
Optional[Path],
typer.Option(help="The file path to the schema file to be written"),
] = None,
ibek_defs: bool = typer.Option(
True, help=f"Include definitions in {IBEK_DEFS} in generated schema"
),
):
"""
Create a json schema from a number of support_module.ibek.support.yaml
files
"""
if not (definitions or ibek_defs):
log.error("One or more `definitions` required with `--no-ibek-defs`")
raise typer.Exit(1)

if ibek_defs:
# this allows us to use the definitions inside the container
# which are in a known location after the container is built
definitions += IBEK_DEFS.glob(SUPPORT_YAML_PATTERN)

if not definitions:
log.error(f"No `definitions` given and none found in {IBEK_DEFS}")
raise typer.Exit(1)

ioc_model = ioc_create_model(definitions)
schema = json.dumps(ioc_model.model_json_schema(), indent=2)
Expand Down Expand Up @@ -96,7 +115,7 @@ def make_source_template(
help="Where to make the ioc folder. Defaults to under the "
"generic IOC source folder",
),
] = None
] = None,
):
"""
Create a new IOC boilerplate source tree in the given folder.
Expand Down
6 changes: 3 additions & 3 deletions tests/generate_samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ echo making the support yaml schema
ibek support generate-schema --output schemas/ibek.support.schema.json

echo making an ioc schema using object support yaml
ibek ioc generate-schema yaml/objects.ibek.support.yaml --output schemas/objects.ibek.ioc.schema.json
ibek ioc generate-schema --no-ibek-defs yaml/objects.ibek.support.yaml --output schemas/objects.ibek.ioc.schema.json

echo making an ioc schema using utils support yaml
ibek ioc generate-schema yaml/utils.ibek.support.yaml --output schemas/utils.ibek.ioc.schema.json
ibek ioc generate-schema --no-ibek-defs yaml/utils.ibek.support.yaml --output schemas/utils.ibek.ioc.schema.json

echo making an ioc schema using multiple support yaml files
ibek ioc generate-schema yaml/objects.ibek.support.yaml yaml/all.ibek.support.yaml --output schemas/multiple.ibek.ioc.schema.json
ibek ioc generate-schema --no-ibek-defs yaml/objects.ibek.support.yaml yaml/all.ibek.support.yaml --output schemas/multiple.ibek.ioc.schema.json

echo making ioc based on objects support yaml
ibek runtime generate yaml/objects.ibek.ioc.yaml yaml/objects.ibek.support.yaml --out outputs/objects.st.cmd --db-out outputs/objects.ioc.subst
Expand Down
8 changes: 7 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ def test_ioc_schema(tmp_path: Path, samples: Path):
yaml_path1 = samples / "yaml" / "objects.ibek.support.yaml"
yaml_path2 = samples / "yaml" / "all.ibek.support.yaml"
run_cli(
"ioc", "generate-schema", yaml_path1, yaml_path2, "--output", schema_combined
"ioc",
"generate-schema",
"--no-ibek-defs",
yaml_path1,
yaml_path2,
"--output",
schema_combined,
)

expected = json.loads(
Expand Down

0 comments on commit e307124

Please sign in to comment.