diff --git a/reproschema/tests/data/README.md b/reproschema/tests/data/README.md new file mode 100644 index 0000000..05c3ffd --- /dev/null +++ b/reproschema/tests/data/README.md @@ -0,0 +1 @@ +This file should be ingored during validation. diff --git a/reproschema/validate.py b/reproschema/validate.py index 326038a..82c6b80 100644 --- a/reproschema/validate.py +++ b/reproschema/validate.py @@ -1,4 +1,6 @@ -import os, json +import os +import json +from pathlib import Path from .utils import start_server, stop_server, lgr from .jsonldutils import load_file, validate_data from pathlib import Path @@ -7,8 +9,6 @@ def validate_dir(directory, started=False, http_kwargs={}): """Validate a directory containing JSONLD documents against the ReproSchema pydantic model. - .. warning:: This assumes every file in the directory can be read by a json parser. - Parameters ---------- directory: str @@ -36,17 +36,16 @@ def validate_dir(directory, started=False, http_kwargs={}): else: if "port" not in http_kwargs: raise KeyError(f"HTTP server started, but port key is missing") - for full_file_name in Path(directory).rglob("*"): - # Skip files that should not be validated - if full_file_name.name in [".DS_Store"]: - continue - # checking if the path is a file and if the file can be a jsonld file - if full_file_name.is_file() and full_file_name.suffix in [ - "", - "js", - "json", - "jsonld", - ]: + + for root, _, files in os.walk(directory): + for name in files: + full_file_name = os.path.join(root, name) + + if Path(full_file_name).suffix not in [".jsonld", "json", "js", ""]: + lgr.info(f"Skipping file {full_file_name}") + continue + + lgr.debug(f"Validating file {full_file_name}") try: data = load_file(full_file_name, started=True, http_kwargs=http_kwargs) if len(data) == 0: