-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate_manifests_image_tools.py
55 lines (47 loc) · 1.53 KB
/
validate_manifests_image_tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Script to validate image tools manifests."""
# pylint: disable=W0718, W1203
import logging
from pathlib import Path
import typer
from polus.tools.plugins._plugins.manifests import validate_manifest
app = typer.Typer(help="Validate image tools manifests.")
fhandler = logging.FileHandler("validate_manifests_image_tools.log")
fformat = logging.Formatter(
"%(asctime)s - %(levelname)s - %(message)s", datefmt="%m/%d/%Y %I:%M:%S %p"
)
fhandler.setFormatter(fformat)
fhandler.setLevel("INFO")
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
datefmt="%m/%d/%Y %I:%M:%S %p",
)
logger = logging.getLogger("validate_image_tools")
logger.addHandler(fhandler)
@app.command()
def main(
repo: Path = typer.Option(
None,
"--repo",
"-r",
help="Path to the image-tools repository.",
)
) -> None:
"""Validate image-tools manifests."""
local_manifests = list(repo.rglob("*plugin.json"))
ignore_list = ["cookiecutter", ".env"]
local_manifests = [
x for x in local_manifests if not any(ig in str(x) for ig in ignore_list)
]
n = len(local_manifests)
n_bad = 0
logger.info(f"Found {n} manifests in {repo}")
for manifest in local_manifests:
try:
validate_manifest(manifest)
except BaseException:
n_bad += 1
logger.error(f"Invalid {manifest}: ", exc_info=True)
logger.info(f"{n-n_bad}/{n} manifests are valid. See logs for more info.")
if __name__ == "__main__":
app()