Skip to content

Commit

Permalink
Merge pull request #202 from epics-containers/check-deps
Browse files Browse the repository at this point in the history
Add dependancy check
  • Loading branch information
gilesknap authored Apr 3, 2024
2 parents 4505f85 + 06f305d commit ec2a4b1
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/ibek/support_cmds/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,37 @@ def do_dependencies():
RELEASE_SH.write_text(shell_text)


def check_deps(deps: list[str]) -> None:
"""
Check if specified dependencies have been supplied
"""
for dependency in deps:

# Check if UCASE module name exist in RELEASE
with open(RELEASE) as file:
release_file = file.read()
if dependency.upper() in release_file:
pass
else:
raise Exception(f"{dependency.upper()} not in {RELEASE}")

# Check if folder with the module name exist in /epics/support
support_dir = SUPPORT / dependency
if Path.exists(support_dir):

# Check if contains at least one of db, dbd or lib
res = [Path.exists(support_dir / _dir) for _dir in ["db", "dbd", "lib"]]
if any(res):
pass
else:
raise Exception(f"db, dbd or lib directory not found in {support_dir}")

else:
raise Exception(f"{dependency} directory not in {SUPPORT}")

print(f"SUCCESS: {dependency} checked")


def add_macro(macro: str, value: str, file: Path, replace: bool = True):
"""
add or replace a macro in a RELEASE or CONFIG file
Expand Down
11 changes: 11 additions & 0 deletions src/ibek/support_cmds/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from ibek.support import Support
from ibek.support_cmds.checks import (
add_macro,
check_deps,
do_dependencies,
verify_release_includes_local,
)
Expand Down Expand Up @@ -266,6 +267,16 @@ def add_to_config_site(
add_text_once(config_site, text)


@support_cli.command()
def check_dependencies(
deps: List[str] = typer.Argument(help="list of dependencies to check"),
):
"""
Check if specified dependencies have been supplied
"""
check_deps(deps)


@support_cli.command(
context_settings={"allow_extra_args": True, "ignore_unknown_options": True}
)
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# This must be above the following imports so that it takes effect before
# `globals.EPICS_ROOT` is imported (or anything built on top of it)
os.environ["EPICS_ROOT"] = str(Path(__file__).parent / "samples" / "epics")
os.environ["SUPPORT"] = str(Path(__file__).parent / "samples" / "epics" / "support")

# The `noqa`s on these imports are necessary because of the above
from ibek.__main__ import cli # noqa: E402
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions tests/samples/epics/support/configure/RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Global configure/RELEASE file for epics-containers IOCs

SUPPORT=/epics/support
-include $(TOP)/configure/SUPPORT.$(EPICS_HOST_ARCH)
-include $(TOP)/configure/EPICS_BASE
-include $(TOP)/configure/EPICS_BASE.$(EPICS_HOST_ARCH)

# Paths to modules built in epics-base container
EPICS_BASE=/epics/epics-base

# Additional Support Modules for individual IOCs will be added below this line
ADSIMDETECTOR=/epics/support/ADSimDetector
13 changes: 13 additions & 0 deletions tests/test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from pathlib import Path

import pytest

from ibek.support_cmds.checks import check_deps
from ibek.support_cmds.files import symlink_files


Expand All @@ -20,3 +23,13 @@ def test_symlink_pvi(tmp_path: Path, samples: Path):
symlink_files(samples / "support", "*.pvi.device.yaml", tmp_path)

assert [f.name for f in tmp_path.iterdir()] == ["simple.pvi.device.yaml"]


def test_check_dependancies():

# Check Passes vs test data
check_deps(["ADSimDetector"])

# Check fails
with pytest.raises(Exception):
check_deps(["FakeDetector"])

0 comments on commit ec2a4b1

Please sign in to comment.