Skip to content

Commit

Permalink
Try fixing bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Feb 10, 2025
1 parent f144803 commit b5388f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 12 additions & 1 deletion cubids/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
logger = logging.getLogger("cubids-cli")


def build_validator_call(path, local_validator=False, ignore_headers=False):
def build_validator_call(path, local_validator=False, ignore_headers=False, schema=None):
"""Build a subprocess command to the bids validator.
Parameters
Expand All @@ -29,12 +29,16 @@ def build_validator_call(path, local_validator=False, ignore_headers=False):
If provided, use the local bids-validator.
ignore_headers : :obj:`bool`
If provided, ignore NIfTI headers.
schema : :obj:`pathlib.Path` or None
Path to the BIDS schema file.
Returns
-------
command : :obj:`list`
List of strings to pass to subprocess.run().
"""
import importlib.resources

if local_validator:
command = ["bids-validator", path, "--verbose", "--json"]
else:
Expand All @@ -43,6 +47,13 @@ def build_validator_call(path, local_validator=False, ignore_headers=False):
if ignore_headers:
command.append("--ignoreNiftiHeaders")

if schema is None:
schema = str(importlib.resources.files("cubids") / "data/schema.json")
else:
schema = str(schema.resolve())

command += ["--schema", schema]

return command


Expand Down
12 changes: 9 additions & 3 deletions cubids/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def validate(
sequential_subjects,
local_validator,
ignore_nifti_headers,
schema,
):
"""Run the bids validator.
Expand All @@ -56,6 +57,8 @@ def validate(
Use the local bids validator.
ignore_nifti_headers : :obj:`bool`
Ignore NIfTI headers when validating.
schema : :obj:`pathlib.Path` or None
Path to the BIDS schema file.
"""
# check status of output_prefix, absolute or relative?
abs_path_output = True
Expand All @@ -75,6 +78,7 @@ def validate(
str(bids_dir),
local_validator,
ignore_nifti_headers,
schema=schema,
)
ret = run_validator(call)

Expand Down Expand Up @@ -148,7 +152,7 @@ def validate(

# run the validator
nifti_head = ignore_nifti_headers
call = build_validator_call(tmpdirname, local_validator, nifti_head)
call = build_validator_call(tmpdirname, local_validator, nifti_head, schema=schema)
ret = run_validator(call)
# parse output
if ret.returncode != 0:
Expand Down Expand Up @@ -197,7 +201,7 @@ def validate(
return parsed


def bids_version(bids_dir, write=False):
def bids_version(bids_dir, write=False, schema=None):
"""Get BIDS validator and schema version.
Parameters
Expand All @@ -206,6 +210,8 @@ def bids_version(bids_dir, write=False):
Path to the BIDS directory.
write : :obj:`bool`
If True, write to dataset_description.json. If False, print to terminal.
schema : :obj:`pathlib.Path` or None
Path to the BIDS schema file.
"""
# Need to run validator to get output with schema version
# Copy code from `validate --sequential`
Expand Down Expand Up @@ -253,7 +259,7 @@ def bids_version(bids_dir, write=False):
shutil.copy2(fi, output)

# run the validator
call = build_validator_call(tmpdirname)
call = build_validator_call(tmpdirname, schema=schema)
ret = run_validator(call)

# Get BIDS validator and schema version
Expand Down

0 comments on commit b5388f2

Please sign in to comment.