diff --git a/hed/scripts/script_util.py b/hed/scripts/script_util.py index 842b5e76..fdfe35f2 100644 --- a/hed/scripts/script_util.py +++ b/hed/scripts/script_util.py @@ -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"] @@ -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 @@ -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 diff --git a/hed/scripts/validate_schemas.py b/hed/scripts/validate_schemas.py index aaa09207..74e387ba 100644 --- a/hed/scripts/validate_schemas.py +++ b/hed/scripts/validate_schemas.py @@ -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()) \ No newline at end of file