Skip to content

Commit 943826d

Browse files
Remi-Gauyibeichan
andauthored
ENH: only validates files that end in jsonld or with no extensions (#40)
Co-authored-by: Yibei Chen <[email protected]>
1 parent 4236100 commit 943826d

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

reproschema/tests/data/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file should be ingored during validation.

reproschema/validate.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import os, json
1+
import os
2+
import json
3+
from pathlib import Path
24
from .utils import start_server, stop_server, lgr
35
from .jsonldutils import load_file, validate_data
46
from pathlib import Path
@@ -7,8 +9,6 @@
79
def validate_dir(directory, started=False, http_kwargs={}):
810
"""Validate a directory containing JSONLD documents against the ReproSchema pydantic model.
911
10-
.. warning:: This assumes every file in the directory can be read by a json parser.
11-
1212
Parameters
1313
----------
1414
directory: str
@@ -36,17 +36,16 @@ def validate_dir(directory, started=False, http_kwargs={}):
3636
else:
3737
if "port" not in http_kwargs:
3838
raise KeyError(f"HTTP server started, but port key is missing")
39-
for full_file_name in Path(directory).rglob("*"):
40-
# Skip files that should not be validated
41-
if full_file_name.name in [".DS_Store"]:
42-
continue
43-
# checking if the path is a file and if the file can be a jsonld file
44-
if full_file_name.is_file() and full_file_name.suffix in [
45-
"",
46-
"js",
47-
"json",
48-
"jsonld",
49-
]:
39+
40+
for root, _, files in os.walk(directory):
41+
for name in files:
42+
full_file_name = os.path.join(root, name)
43+
44+
if Path(full_file_name).suffix not in [".jsonld", "json", "js", ""]:
45+
lgr.info(f"Skipping file {full_file_name}")
46+
continue
47+
48+
lgr.debug(f"Validating file {full_file_name}")
5049
try:
5150
data = load_file(full_file_name, started=True, http_kwargs=http_kwargs)
5251
if len(data) == 0:

0 commit comments

Comments
 (0)