From d4743b95fb94045a8dc077faf021400959864089 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Tue, 14 May 2024 03:29:40 +0200 Subject: [PATCH] only validates files that end in jsonld or with no extensions --- reproschema/tests/data/README.md | 1 + reproschema/validate.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 reproschema/tests/data/README.md 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 64b612e..940adc2 100644 --- a/reproschema/validate.py +++ b/reproschema/validate.py @@ -1,4 +1,5 @@ import os +from pathlib import Path from .utils import start_server, stop_server, lgr from .jsonldutils import load_file, validate_data @@ -6,8 +7,6 @@ def validate_dir(directory, shape_file, started=False, http_kwargs={}): """Validate a directory containing JSONLD documents - .. warning:: This assumes every file in the directory can be read by a json parser. - Parameters ---------- directory: str @@ -34,9 +33,17 @@ def validate_dir(directory, shape_file, started=False, http_kwargs={}): else: if "port" not in http_kwargs: raise KeyError(f"HTTP server started, but port key is missing") - for root, dirs, files in os.walk(directory): + + 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", ""]: + 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: