diff --git a/nipoppy_cli/nipoppy/workflows/pipeline.py b/nipoppy_cli/nipoppy/workflows/pipeline.py index cb033bbd..d4c04799 100644 --- a/nipoppy_cli/nipoppy/workflows/pipeline.py +++ b/nipoppy_cli/nipoppy/workflows/pipeline.py @@ -357,12 +357,6 @@ def run_main(self, **kwargs): f": {exception}" ) - def run_cleanup(self, **kwargs): - """Run pipeline cleanup.""" - if self.dpath_pipeline_work.exists(): - self.rm(self.dpath_pipeline_work) - return super().run_cleanup(**kwargs) - @abstractmethod def get_participants_sessions_to_run( self, participant_id: Optional[str], session_id: Optional[str] diff --git a/nipoppy_cli/nipoppy/workflows/runner.py b/nipoppy_cli/nipoppy/workflows/runner.py index e207ddc7..5e032645 100644 --- a/nipoppy_cli/nipoppy/workflows/runner.py +++ b/nipoppy_cli/nipoppy/workflows/runner.py @@ -208,6 +208,7 @@ def run_single(self, participant_id: str, session_id: str): def run_cleanup(self, **kwargs): """Run pipeline runner cleanup.""" - if self.dpath_pipeline_bids_db.exists(): - self.rm(self.dpath_pipeline_bids_db) + for dpath in [self.dpath_pipeline_bids_db, self.dpath_pipeline_work]: + if dpath.exists(): + self.rm(dpath) return super().run_cleanup(**kwargs) diff --git a/nipoppy_cli/tests/test_workflow_runner.py b/nipoppy_cli/tests/test_workflow_runner.py index aa06bf7d..3444f231 100644 --- a/nipoppy_cli/tests/test_workflow_runner.py +++ b/nipoppy_cli/tests/test_workflow_runner.py @@ -83,6 +83,23 @@ def test_run_setup(config: Config, tmp_path: Path): assert runner.dpath_pipeline_work.exists() +def test_run_cleanup(tmp_path: Path): + runner = PipelineRunner( + dpath_root=tmp_path / "my_dataset", + pipeline_name="dummy_pipeline", + pipeline_version="1.0.0", + ) + dpaths = [ + runner.dpath_pipeline_bids_db, + runner.dpath_pipeline_work, + ] + for dpath in dpaths: + dpath.mkdir(parents=True) + runner.run_cleanup() + for dpath in dpaths: + assert not dpath.exists() + + @pytest.mark.parametrize("simulate", [True, False]) def test_launch_boutiques_run(simulate, config: Config, tmp_path: Path): runner = PipelineRunner( diff --git a/nipoppy_cli/tests/test_workflow_tracker.py b/nipoppy_cli/tests/test_workflow_tracker.py index d8efcf10..0d4fe5bf 100644 --- a/nipoppy_cli/tests/test_workflow_tracker.py +++ b/nipoppy_cli/tests/test_workflow_tracker.py @@ -232,3 +232,14 @@ def test_run_cleanup(tracker: PipelineTracker, bagel: Bagel): assert tracker.layout.fpath_imaging_bagel.exists() assert Bagel.load(tracker.layout.fpath_imaging_bagel).equals(bagel) + + +def test_run_no_create_work_directory(tracker: PipelineTracker): + tracker.run() + assert not tracker.dpath_pipeline_work.exists() + + +def test_run_no_rm_work_directory(tracker: PipelineTracker): + tracker.dpath_pipeline_work.mkdir(parents=True) + tracker.run() + assert tracker.dpath_pipeline_work.exists()