From 621c73eb02c08aa0567d634988a1dc0b52db654d Mon Sep 17 00:00:00 2001 From: Leonardo Schwarz Date: Wed, 4 Sep 2024 14:56:12 +0200 Subject: [PATCH] create a zip file --- .../pipeline/store_outputs.py | 33 +++++++++++++++++++ .../workflow/snakemake_invoke.py | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/depiction_targeted_preproc/pipeline/store_outputs.py diff --git a/src/depiction_targeted_preproc/pipeline/store_outputs.py b/src/depiction_targeted_preproc/pipeline/store_outputs.py new file mode 100644 index 0000000..e9c4541 --- /dev/null +++ b/src/depiction_targeted_preproc/pipeline/store_outputs.py @@ -0,0 +1,33 @@ +from __future__ import annotations + +from pathlib import Path + +import yaml +from bfabric import Bfabric +from bfabric.entities import Workunit + + +def _get_outputs_spec(zip_file_path: Path, workunit: Workunit) -> dict[str, list[dict[str, str | int | bool]]]: + return { + "outputs": [ + { + "type": "bfabric_copy_resource", + "local_path": str(zip_file_path.absolute()), + "store_entry_path": zip_file_path.name, + "workunit_id": workunit.id, + "storage_id": workunit.application.storage.id, + } + ] + } + + +def write_outputs_spec(zip_file_path: Path, workunit: Workunit) -> None: + output_spec = _get_outputs_spec(zip_file_path=zip_file_path, workunit=workunit) + outputs_yaml = zip_file_path.parent / f"{zip_file_path.stem}_outputs_spec.yml" + with outputs_yaml.open("w") as file: + yaml.safe_dump(output_spec, file) + + +def store_outputs(client: Bfabric, zip_file_path: Path, workunit_id: int): + workunit = Workunit.find(id=workunit_id, client=client) + write_outputs_spec(zip_file_path=zip_file_path, workunit=workunit) diff --git a/src/depiction_targeted_preproc/workflow/snakemake_invoke.py b/src/depiction_targeted_preproc/workflow/snakemake_invoke.py index 857d450..74f05fa 100644 --- a/src/depiction_targeted_preproc/workflow/snakemake_invoke.py +++ b/src/depiction_targeted_preproc/workflow/snakemake_invoke.py @@ -80,7 +80,7 @@ def _invoke_subprocess(self, work_dir: Path, result_files: list[Path], extra_arg command = self.get_command_create_report( base_command=base_command, result_files=result_files, work_dir=work_dir ) - logger.info("Executing {command}", command=command) + logger.info("Executing {command}", command=self._args_to_shell_command(command)) subprocess.run( command, cwd=self.workflow_dir,