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

Add converters to SnakeBidsApp #421

Merged
merged 2 commits into from
May 9, 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
11 changes: 8 additions & 3 deletions snakebids/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
bidsapp.app([plugins.SnakemakeBidsApp(...)])

"""

from __future__ import annotations

import logging
Expand Down Expand Up @@ -69,12 +70,16 @@ class SnakeBidsApp:
DEPRECATED: no-op, use version plugin instead
"""

snakemake_dir: Path
snakemake_dir: Path = attrs.field(converter=Path)
plugins: list[Callable[[SnakeBidsApp], None | SnakeBidsApp]] = attrs.Factory(list)
skip_parse_args: bool = False
_parser: Any = attrs.field(default=None, alias="parser")
configfile_path: Path | None = None
snakefile_path: Path | None = None
configfile_path: Path | None = attrs.field(
default=None, converter=attrs.converters.optional(Path)
)
snakefile_path: Path | None = attrs.field(
default=None, converter=attrs.converters.optional(Path)
)
_config: Any = attrs.field(default=None, alias="config")
version: str | None = None
args: Any = None
Expand Down
19 changes: 18 additions & 1 deletion snakebids/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def test_arguments_carried_forward(mocker: MockerFixture):
from snakebids.app import sb_plugins
from snakebids.bidsapp import run

mocker.stopall()
mocker.patch.object(run, "_Runner")
snakemake = mocker.spy(sb_plugins, "SnakemakeBidsApp")
SnakeBidsApp(
Expand All @@ -55,6 +54,24 @@ def test_arguments_carried_forward(mocker: MockerFixture):
)


def test_str_converted_to_path(mocker: MockerFixture):
from snakebids.app import sb_plugins
from snakebids.bidsapp import run

mocker.patch.object(run, "_Runner")
snakemake = mocker.spy(sb_plugins, "SnakemakeBidsApp")
SnakeBidsApp(
"",
configfile_path="config",
snakefile_path="Snakefile",
).run_snakemake()
snakemake.assert_called_once_with(
snakemake_dir=Path(),
configfile_path=Path("config"),
snakefile_path=Path("Snakefile"),
)


def test_plugins_carried_forward(mocker: MockerFixture):
from snakebids.app import bidsapp
from snakebids.bidsapp import run
Expand Down