Skip to content

Commit 61fed30

Browse files
authored
Provide option to run locally installed bids-validator (#380)
* provide option to run local installation of bids validator * added detail in help section of parsing function of validate command, to --local-validator arg * added docstrings to edited functions * fixed linting issue
1 parent 6a7671d commit 61fed30

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

cubids/cli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ def _is_file(path, parser):
6363

6464

6565
def _parse_validate():
66+
"""Create the parser for the "cubids validate" command.
67+
68+
Returns:
69+
-------
70+
parser : argparse.ArgumentParser
71+
The parser object for the "cubids validate" command.
72+
"""
6673
parser = argparse.ArgumentParser(
6774
description="cubids-validate: Wrapper around the official BIDS Validator",
6875
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
@@ -123,6 +130,13 @@ def _parse_validate():
123130
nargs="+",
124131
required=False,
125132
)
133+
parser.add_argument(
134+
"--local-validator",
135+
action="store_true",
136+
default=False,
137+
help="Lets user run a locally installed BIDS validator. Default is set to False ",
138+
required=False,
139+
)
126140
return parser
127141

128142

cubids/validator.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,27 @@
1414
logger = logging.getLogger("cubids-cli")
1515

1616

17-
def build_validator_call(path, ignore_headers=False):
18-
"""Build a subprocess command to the bids validator."""
19-
# New schema BIDS validator doesn't have option to ignore subject consistency.
20-
# Build the deno command to run the BIDS validator.
21-
command = ["deno", "run", "-A", "jsr:@bids/validator", path, "--verbose", "--json"]
17+
def build_validator_call(path, local_validator=False, ignore_headers=False):
18+
"""Build a subprocess command to the bids validator.
19+
20+
Parameters
21+
----------
22+
path : :obj:`str`
23+
Path to the BIDS dataset.
24+
local_validator : :obj:`bool`
25+
If provided, use the local bids-validator.
26+
ignore_headers : :obj:`bool`
27+
If provided, ignore NIfTI headers.
28+
29+
Returns
30+
-------
31+
command : :obj:`list`
32+
List of strings to pass to subprocess.run().
33+
"""
34+
if local_validator:
35+
command = ["bids-validator", path, "--verbose", "--json"]
36+
else:
37+
command = ["deno", "run", "-A", "jsr:@bids/validator", path, "--verbose", "--json"]
2238

2339
if ignore_headers:
2440
command.append("--ignoreNiftiHeaders")

cubids/workflows.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def validate(
3939
container,
4040
sequential,
4141
sequential_subjects,
42+
local_validator,
4243
ignore_nifti_headers,
4344
):
4445
"""Run the bids validator.
@@ -55,6 +56,8 @@ def validate(
5556
Run the validator sequentially.
5657
sequential_subjects : :obj:`list` of :obj:`str`
5758
Filter the sequential run to only include the listed subjects.
59+
local_validator : :obj:`bool`
60+
Use the local bids validator.
5861
ignore_nifti_headers : :obj:`bool`
5962
Ignore NIfTI headers when validating.
6063
"""
@@ -75,6 +78,7 @@ def validate(
7578
# run on full dataset
7679
call = build_validator_call(
7780
str(bids_dir),
81+
local_validator,
7882
ignore_nifti_headers,
7983
)
8084
ret = run_validator(call)
@@ -154,7 +158,7 @@ def validate(
154158

155159
# run the validator
156160
nifti_head = ignore_nifti_headers
157-
call = build_validator_call(tmpdirname, nifti_head)
161+
call = build_validator_call(tmpdirname, local_validator, nifti_head)
158162
ret = run_validator(call)
159163
# parse output
160164
if ret.returncode != 0:

0 commit comments

Comments
 (0)