forked from hed-standard/hed-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_schemas.py
More file actions
52 lines (37 loc) · 1.57 KB
/
validate_schemas.py
File metadata and controls
52 lines (37 loc) · 1.57 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
"""CLI script to validate HED schema files for compliance and format consistency."""
import sys
from hed.scripts.schema_script_util import validate_all_schemas, sort_base_schemas
from hed.errors import get_printable_issue_string
import argparse
def get_parser():
"""Create the argument parser for validate_schemas.
Returns:
argparse.ArgumentParser: The argument parser.
"""
parser = argparse.ArgumentParser(description="Validate schema files.")
parser.add_argument("schema_files", nargs="+", help="List of schema files to validate.")
parser.add_argument(
"--add-all-extensions", action="store_true", help="Always verify all versions of the same schema are equal."
)
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output.")
return parser
def main(arg_list=None):
"""Entry point: parse arguments and validate the specified schema files.
Parameters:
arg_list (list[str] or None): Argument list for testing; uses sys.argv if None.
Returns:
int: 0 if all schemas are valid, 1 if any issues are found.
"""
parser = get_parser()
args = parser.parse_args(arg_list)
schema_files = sort_base_schemas(args.schema_files, args.add_all_extensions)
issues = validate_all_schemas(schema_files)
if issues:
if args.verbose:
print(get_printable_issue_string(issues, title="Schema Validation Issues:"))
return 1
if args.verbose:
print("All schemas validated successfully.")
return 0
if __name__ == "__main__":
sys.exit(main())