From 9e086bfb9497b047a2d11c6ede9346fb2916beeb Mon Sep 17 00:00:00 2001 From: Peter Van Dyken Date: Tue, 30 Apr 2024 20:36:31 -0400 Subject: [PATCH 1/2] Add converters to SnakeBidsApp strings being passed to the arguments in old apps were breaking. Convert now to Paths --- snakebids/app.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/snakebids/app.py b/snakebids/app.py index ec040edd..39a64fe8 100644 --- a/snakebids/app.py +++ b/snakebids/app.py @@ -12,6 +12,7 @@ bidsapp.app([plugins.SnakemakeBidsApp(...)]) """ + from __future__ import annotations import logging @@ -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 From ad0b495860f3cbcd4c69ebbac75b2e7dc0368980 Mon Sep 17 00:00:00 2001 From: Peter Van Dyken Date: Thu, 9 May 2024 12:43:08 -0400 Subject: [PATCH 2/2] Add test --- snakebids/tests/test_app.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/snakebids/tests/test_app.py b/snakebids/tests/test_app.py index 5e8f79c1..eb162b1f 100644 --- a/snakebids/tests/test_app.py +++ b/snakebids/tests/test_app.py @@ -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( @@ -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