From 51cd40f10365d589a51c53e3511745a6f4f64fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20M=C2=AA=20Fern=C3=A1ndez?= Date: Sun, 8 Dec 2024 23:08:26 +0100 Subject: [PATCH] Fixed several path handling issues in several parts of RO-Crate generation. --- wfexs_backend/__main__.py | 8 ++++++-- wfexs_backend/ro_crate.py | 26 +++++++++++++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/wfexs_backend/__main__.py b/wfexs_backend/__main__.py index b781409..ef5d9fa 100644 --- a/wfexs_backend/__main__.py +++ b/wfexs_backend/__main__.py @@ -1061,7 +1061,9 @@ def processStagedWorkdirCommand( ) expanded_licences = wB.curate_licence_list(op_licences) wfInstance.createStageResearchObject( - filename=args.staged_workdir_command_args[1], + filename=pathlib.Path( + args.staged_workdir_command_args[1] + ), payloads=doMaterializedROCrate, licences=expanded_licences, resolved_orcids=resolved_orcids, @@ -1078,7 +1080,9 @@ def processStagedWorkdirCommand( ) expanded_licences = wB.curate_licence_list(op_licences) wfInstance.createResultsResearchObject( - filename=args.staged_workdir_command_args[1], + filename=pathlib.Path( + args.staged_workdir_command_args[1] + ), payloads=doMaterializedROCrate, licences=expanded_licences, resolved_orcids=resolved_orcids, diff --git a/wfexs_backend/ro_crate.py b/wfexs_backend/ro_crate.py index 07197b5..c41ea6a 100644 --- a/wfexs_backend/ro_crate.py +++ b/wfexs_backend/ro_crate.py @@ -2631,19 +2631,26 @@ def addWorkflowExecution( crate_meta_outputs: "MutableSequence[rocrate.model.entity.Entity]" = [] if stagedExec.diagram is not None: # This is the original diagram, in DOT format (for now) - abs_diagram = os.path.join(self.work_dir, stagedExec.diagram) + abs_diagram = ( + stagedExec.diagram + if stagedExec.diagram.is_absolute() + else (self.work_dir / stagedExec.diagram).resolve() + ) + rel_diagram = stagedExec.diagram.relative_to(self.work_dir) dot_file = WorkflowDiagram( self.crate, - source=os.path.join(self.work_dir, stagedExec.diagram), - dest_path=stagedExec.diagram, + source=abs_diagram, + dest_path=rel_diagram, fetch_remote=False, validate_url=False, properties={ - "contentSize": str(os.stat(abs_diagram).st_size), + "contentSize": str(abs_diagram.stat().st_size), "sha256": ComputeDigestFromFile( abs_diagram, "sha256", repMethod=hexDigest ), - "encodingFormat": magic.from_file(abs_diagram, mime=True), + "encodingFormat": magic.from_file( + abs_diagram.as_posix(), mime=True + ), }, ) self.crate.add(dot_file) @@ -2663,7 +2670,12 @@ def addWorkflowExecution( os.close(png_dot_handle) with tempfile.NamedTemporaryFile() as d_err: - dot_cmd = [self.dot_binary, "-Tpng", "-o" + png_dot_path, abs_diagram] + dot_cmd = [ + self.dot_binary, + "-Tpng", + "-o" + png_dot_path, + abs_diagram.as_posix(), + ] diagram_dot_path_for_rocrate = stagedExec.diagram.relative_to( self.work_dir @@ -2687,7 +2699,7 @@ def addWorkflowExecution( png_dot_file = WorkflowDiagram( self.crate, source=png_dot_path, - dest_path=stagedExec.diagram.as_posix() + ".png", + dest_path=rel_diagram.as_posix() + ".png", fetch_remote=False, validate_url=False, properties={