Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 14 additions & 0 deletions cubids/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ def _is_file(path, parser):


def _parse_validate():
"""Create the parser for the "cubids validate" command.

Returns:
-------
parser : argparse.ArgumentParser
The parser object for the "cubids validate" command.
"""
parser = argparse.ArgumentParser(
description="cubids-validate: Wrapper around the official BIDS Validator",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Expand Down Expand Up @@ -123,6 +130,13 @@ def _parse_validate():
nargs="+",
required=False,
)
parser.add_argument(
"--local-validator",
action="store_true",
default=False,
help="Lets user run a locally installed BIDS validator. Default is set to False ",
required=False,
)
return parser


Expand Down
28 changes: 23 additions & 5 deletions cubids/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,29 @@
logger = logging.getLogger("cubids-cli")


def build_validator_call(path, ignore_headers=False):
"""Build a subprocess command to the bids validator."""
# New schema BIDS validator doesn't have option to ignore subject consistency.
# Build the deno command to run the BIDS validator.
command = ["deno", "run", "-A", "jsr:@bids/validator", path, "--verbose", "--json"]
def build_validator_call(path, local_validator=False, ignore_headers=False):
"""Build a subprocess command to the bids validator.

Parameters
----------
path : :obj:`str`
Path to the BIDS dataset.
local_validator : :obj:`bool`
If provided, use the local bids-validator.
ignore_headers : :obj:`bool`
If provided, ignore NIfTI headers.

Returns
-------
command : :obj:`list`
List of strings to pass to subprocess.run().
"""


if local_validator:
command = ["bids-validator", path, "--verbose", "--json"]
else:
command = ["deno", "run", "-A", "jsr:@bids/validator", path, "--verbose", "--json"]

if ignore_headers:
command.append("--ignoreNiftiHeaders")
Expand Down
6 changes: 5 additions & 1 deletion cubids/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def validate(
container,
sequential,
sequential_subjects,
local_validator,
ignore_nifti_headers,
):
"""Run the bids validator.
Expand All @@ -55,6 +56,8 @@ def validate(
Run the validator sequentially.
sequential_subjects : :obj:`list` of :obj:`str`
Filter the sequential run to only include the listed subjects.
local_validator : :obj:`bool`
Use the local bids validator.
ignore_nifti_headers : :obj:`bool`
Ignore NIfTI headers when validating.
"""
Expand All @@ -75,6 +78,7 @@ def validate(
# run on full dataset
call = build_validator_call(
str(bids_dir),
local_validator,
ignore_nifti_headers,
)
ret = run_validator(call)
Expand Down Expand Up @@ -154,7 +158,7 @@ def validate(

# run the validator
nifti_head = ignore_nifti_headers
call = build_validator_call(tmpdirname, nifti_head)
call = build_validator_call(tmpdirname, local_validator, nifti_head)
ret = run_validator(call)
# parse output
if ret.returncode != 0:
Expand Down
Loading