-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvalidate.py
More file actions
76 lines (54 loc) · 2.14 KB
/
validate.py
File metadata and controls
76 lines (54 loc) · 2.14 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""Gateway for validation."""
import importlib
import os
import re
from argparse import ArgumentParser
from pathlib import Path
from libminipic.ci import print_success
from libminipic.exceptions import IncorrectFileMiniPICError, MissingFileMiniPICError
CMAKE_CACHE_FILENAME = "CMakeCache.txt"
THRESHOLD = 1e-10
def detect_setup(path: Path) -> str:
cmake_cache_file = path / CMAKE_CACHE_FILENAME
if not cmake_cache_file.exists():
raise MissingFileMiniPICError(f"Cannot find {cmake_cache_file}")
cmake_cache_content = cmake_cache_file.read_text()
matcher = re.findall(r"MINI_MINIPIC_SETUP:STRING=(.*)", cmake_cache_content)
if not matcher:
raise IncorrectFileMiniPICError(f"Cannot find setup in {cmake_cache_file}")
# return the first element, as we know there is at least one
return matcher[0].strip()
def validate_setup(path, setup=None, evaluate=True, threshold=THRESHOLD):
if not setup:
setup = detect_setup(path)
print(f"Autodetected setup: {setup}")
module = importlib.import_module(f"libminipic.validation.{setup}", None)
os.chdir(path)
if not os.path.isdir("diags"):
raise MissingFileMiniPICError(f"Directory diags is not in {path}")
print(evaluate, threshold)
module.validate(evaluate=evaluate, threshold=threshold)
print_success(f"Setup {setup} tested with success")
def validate():
parser = ArgumentParser(description="Run a validation script")
parser.add_argument(
"-s", "--setup", help="name of the setup to validate (default to autodetect)"
)
parser.add_argument(
"-p",
"--path",
help="path to the execution directory (default to current working directory)",
type=Path,
default=Path.cwd(),
)
parser.add_argument(
"--no-evaluate", help=f"do not perform the validation", action="store_true"
)
parser.add_argument(
"--threshold",
help=f"threshold for the validation (default to {THRESHOLD})",
default=THRESHOLD,
type=float,
)
args = parser.parse_args()
validate_setup(args.path, args.setup, not args.no_evaluate, args.threshold)