Skip to content

Commit

Permalink
fix docstrings and update validate logic
Browse files Browse the repository at this point in the history
- remove mention of uncommenting lines
- rephrased "Enable by default..." to "Boilerplate starts with the
validator plugin enabled..." in the overview doc
- focused docstring of validation using pybids in `generate_inputs()`
- updated boilerplate logic for performing pybids validation based on
plugin success
- instantiate validator plugin in boilerplate
- moved docstring under `__call__`
- replaced `__init__` with attr
  • Loading branch information
kaitj committed Jun 8, 2023
1 parent e01699e commit 2bde868
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 27 deletions.
4 changes: 2 additions & 2 deletions snakebids/core/input_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def generate_inputs( # noqa: PLR0913
the default behaviour
validate
If False, skips validation of BIDS directory. Otherwise use node.js
implementation of bids-validator, falling back on pybids validation.
If True performs validation of BIDS directory using pybids, otherwise
skips validation.
Returns
-------
Expand Down
26 changes: 14 additions & 12 deletions snakebids/plugins/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import subprocess
import tempfile

import attr

from snakebids.app import SnakeBidsApp
from snakebids.exceptions import SnakebidsPluginError

Expand All @@ -13,21 +15,21 @@ class InvalidBidsError(SnakebidsPluginError):
"""Error raised if an input BIDS dataset is invalid."""


@attr.define
class BidsValidator:
"""Perform BIDS validation of dataset, falling back to the pybids
version of validation if the node-version of bids-validator is
not found.
Parameters
----------
app
Snakebids application to be run
"""

def __init__(self, raise_invalid_bids: bool = True) -> None:
self.raise_invalid_bids = raise_invalid_bids
raise_invalid_bids: bool = attr.field(default=True)

def __call__(self, app: SnakeBidsApp) -> None:
"""Perform BIDS validation of dataset, falling back to the pybids
version of validation if the node-version of bids-validator is
not found. If the validation of the dataset fails, an InvalidBidsError
is raised.
Parameters
----------
app
Snakebids application to be run
"""
# Skip bids validation
if app.config["plugins.validator.skip"]:
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ parse_args:
# custom command-line parameters can then be added, these will get added to the config and also accessible to plugins
# below are examples for plugin and custom parameters (e.g. config['smoothing_fwhm'])
--skip_bids_validation:
help: 'Skip validation of BIDS dataset. BIDS validation is performed by
default using the bids-validator (if installed) or with the pybids
validator implementation (if bids-validator is not installed).
(default: %(default)s)'
help: 'Skip validation of BIDS dataset. BIDS validation is performed by
default using the bids-validator plugin (if installed/enabled) or with the pybids
validator implementation (if bids-validator is not installed/enabled).'
dest: "plugins.validator.skip"
action: "store_true"
default: False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@ inputs = generate_inputs(
derivatives=config.get("derivatives", None),
participant_label=config.get("participant_label", None),
exclude_participant_label=config.get("exclude_participant_label", None),
validate=config.get("plugins.validator.success", False),
validate=(
not config.get("plugins.validator.success") and
not config.get("plugins.validator.skip")
)
)

# If skip -> False and __ -> False
# If validate success -> False and True -> False
# If validate fail/None -> True and True -> True

# if bids-validator not run, pybids will run (assuming not InvalidBidsError)


#this adds constraints to the bids naming
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_parser():
def main():
app = SnakeBidsApp(
Path(__file__).resolve().parent.parent, # to get repository root
plugins=[BidsValidator],
plugins=[BidsValidator()],
)
app.run_snakemake()

Expand Down
4 changes: 2 additions & 2 deletions snakebids/tests/mock/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
},
"--skip_bids_validation": {
"help": "Skip validation of BIDS dataset. BIDS validation is performed by "
"default using the bids-validator (if installed) or with the pybids "
"validator implementation (if bids-validator is not installed). "
"default using the bids-validator plugin (if installed/enabled) or with the pybids "
"validator implementation (if bids-validator is not installed/enabled). "
"(default: %(default)s)",
"dest": "plugins.validator.skip",
"action": "store_true",
Expand Down
7 changes: 3 additions & 4 deletions snakebids/tests/mock/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ parse_args:
nargs: '+'

--skip_bids_validation:
help: 'Skip validation of BIDS dataset. BIDS validation is performed by
default using the bids-validator (if installed) or with the pybids
validator implementation (if bids-validator is not installed).
(default: %(default)s)'
help: 'Skip validation of BIDS dataset. BIDS validation is performed by
default using the bids-validator plugin (if installed/enabled) or with the pybids
validator implementation (if bids-validator is not installed/enabled).'
dest: "plugins.validator.skip"
action: "store_true"
default: False
Expand Down
2 changes: 1 addition & 1 deletion snakebids/tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_template_dry_runs_successfully(tmp_path: Path):
"path_bold": None,
"participant_label": None,
"exclude_participant_label": None,
"skip_bids_validation": True,
"plugins.validator.skip": True,
},
),
)
Expand Down

0 comments on commit 2bde868

Please sign in to comment.