Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] only validates files that end in jsonld or with no extensions #40

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions reproschema/tests/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file should be ingored during validation.
27 changes: 13 additions & 14 deletions reproschema/validate.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down