Skip to content

Commit

Permalink
Add optional flag to validate_schemas script to validate all 3 types …
Browse files Browse the repository at this point in the history
…always
  • Loading branch information
IanCa committed Jul 26, 2024
1 parent bca157d commit fe9a4d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 7 additions & 1 deletion hed/scripts/script_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def add_extension(basename, extension):
return basename + extension


def sort_base_schemas(filenames):
def sort_base_schemas(filenames, add_all_extensions=False):
""" Sort and group the changed files based on basename
Example input: ["test_schema.mediawiki", "hedtsv/test_schema/test_schema_Tag.tsv", "other_schema.xml"]
Expand All @@ -78,6 +78,7 @@ def sort_base_schemas(filenames):
Parameters:
filenames(list or container): The changed filenames
add_all_extensions(bool): If True, always return all 3 filenames for any schemas found.
Returns:
sorted_files(dict): A dictionary where keys are the basename, and the values are a set of extensions modified
Expand Down Expand Up @@ -108,6 +109,11 @@ def sort_base_schemas(filenames):
else:
print(f"Ignoring file {file_path}")

if add_all_extensions:
for schema_name in schema_files:
for extension in all_extensions:
schema_files[schema_name].add(extension)

return schema_files


Expand Down
16 changes: 10 additions & 6 deletions hed/scripts/validate_schemas.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import sys
from hed.scripts.script_util import validate_all_schemas, sort_base_schemas
import argparse


def main(arg_list=None):
if not arg_list:
arg_list = sys.argv[1:]
def main():
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.')

schema_files = sort_base_schemas(arg_list)
args = parser.parse_args()

schema_files = sort_base_schemas(args.schema_files, args.add_all_extensions)
issues = validate_all_schemas(schema_files)

if issues:
return 1
return 0


if __name__ == "__main__":
exit(main())
sys.exit(main())

0 comments on commit fe9a4d3

Please sign in to comment.