24
24
from prov .model import PROV , PROV_LABEL , PROV_TYPE , PROV_VALUE , ProvDocument , ProvEntity
25
25
from schema_salad .sourceline import SourceLine
26
26
27
- from .errors import WorkflowException
28
- from .job import CommandLineJob , JobBase
29
- from .loghandler import _logger
30
- from .process import Process , shortname
27
+ from ..errors import WorkflowException
28
+ from ..job import CommandLineJob , JobBase
29
+ from ..loghandler import _logger
30
+ from ..process import Process , shortname
31
+ from ..stdfsaccess import StdFsAccess
32
+ from ..utils import CWLObjectType , JobsType , get_listing , posix_path , versionstring
33
+ from ..workflow_job import WorkflowJob
31
34
from .provenance_constants import (
32
35
ACCOUNT_UUID ,
33
36
CWLPROV ,
46
49
WFDESC ,
47
50
WFPROV ,
48
51
)
49
- from .stdfsaccess import StdFsAccess
50
- from .utils import CWLObjectType , JobsType , get_listing , posix_path , versionstring
51
- from .workflow_job import WorkflowJob
52
+ from .writablebagfile import create_job , write_bag_file # change this later
52
53
53
54
if TYPE_CHECKING :
54
- from .provenance import ResearchObject
55
+ from .ro import ResearchObject
55
56
56
57
57
58
def copy_job_order (job : Union [Process , JobsType ], job_order_object : CWLObjectType ) -> CWLObjectType :
@@ -114,10 +115,7 @@ def __init__(
114
115
115
116
def __str__ (self ) -> str :
116
117
"""Represent this Provenvance profile as a string."""
117
- return "ProvenanceProfile <{}> in <{}>" .format (
118
- self .workflow_run_uri ,
119
- self .research_object ,
120
- )
118
+ return f"ProvenanceProfile <{ self .workflow_run_uri } > in <{ self .research_object } >"
121
119
122
120
def generate_prov_doc (self ) -> Tuple [str , ProvDocument ]:
123
121
"""Add basic namespaces."""
@@ -140,7 +138,7 @@ def host_provenance(document: ProvDocument) -> None:
140
138
},
141
139
)
142
140
143
- self .cwltool_version = "cwltool %s" % versionstring ().split ()[- 1 ]
141
+ self .cwltool_version = f "cwltool { versionstring ().split ()[- 1 ]} "
144
142
self .document .add_namespace ("wfprov" , "http://purl.org/wf4ever/wfprov#" )
145
143
# document.add_namespace('prov', 'http://www.w3.org/ns/prov#')
146
144
self .document .add_namespace ("wfdesc" , "http://purl.org/wf4ever/wfdesc#" )
@@ -240,7 +238,7 @@ def evaluate(
240
238
self .prospective_prov (job )
241
239
customised_job = copy_job_order (job , job_order_object )
242
240
self .used_artefacts (customised_job , self .workflow_run_uri )
243
- research_obj . create_job (customised_job )
241
+ create_job (research_obj , customised_job )
244
242
elif hasattr (job , "workflow" ):
245
243
# record provenance of workflow executions
246
244
self .prospective_prov (job )
@@ -460,7 +458,7 @@ def declare_directory(self, value: CWLObjectType) -> ProvEntity:
460
458
ore_doc .add_bundle (dir_bundle )
461
459
ore_doc = ore_doc .flattened ()
462
460
ore_doc_path = str (PurePosixPath (METADATA , ore_doc_fn ))
463
- with self .research_object . write_bag_file ( ore_doc_path ) as provenance_file :
461
+ with write_bag_file ( self .research_object , ore_doc_path ) as provenance_file :
464
462
ore_doc .serialize (provenance_file , format = "rdf" , rdf_format = "turtle" )
465
463
self .research_object .add_annotation (dir_id , [ore_doc_fn ], ORE ["isDescribedBy" ].uri )
466
464
@@ -477,7 +475,7 @@ def declare_string(self, value: str) -> Tuple[ProvEntity, str]:
477
475
data_file = self .research_object .add_data_file (byte_s , content_type = TEXT_PLAIN )
478
476
checksum = PurePosixPath (data_file ).name
479
477
# FIXME: Don't naively assume add_data_file uses hash in filename!
480
- data_id = "data:%s" % PurePosixPath (data_file ).stem
478
+ data_id = f "data:{ PurePosixPath (data_file ).stem } "
481
479
entity = self .document .entity (
482
480
data_id , {PROV_TYPE : WFPROV ["Artifact" ], PROV_VALUE : str (value )}
483
481
)
@@ -509,7 +507,7 @@ def declare_artefact(self, value: Any) -> ProvEntity:
509
507
byte_s = BytesIO (value )
510
508
data_file = self .research_object .add_data_file (byte_s )
511
509
# FIXME: Don't naively assume add_data_file uses hash in filename!
512
- data_id = "data:%s" % PurePosixPath (data_file ).stem
510
+ data_id = f "data:{ PurePosixPath (data_file ).stem } "
513
511
return self .document .entity (
514
512
data_id ,
515
513
{PROV_TYPE : WFPROV ["Artifact" ], PROV_VALUE : str (value )},
@@ -654,7 +652,7 @@ def generate_output_prov(
654
652
# FIXME: Probably not "main" in nested workflows
655
653
role = self .wf_ns [f"main/{ name } /{ output } " ]
656
654
else :
657
- role = self .wf_ns ["main/%s" % output ]
655
+ role = self .wf_ns [f "main/{ output } " ]
658
656
659
657
if not process_run_id :
660
658
process_run_id = self .workflow_run_uri
@@ -738,38 +736,38 @@ def finalize_prov_profile(self, name: Optional[str]) -> List[QualifiedName]:
738
736
prov_ids = []
739
737
740
738
# https://www.w3.org/TR/prov-xml/
741
- with self .research_object . write_bag_file ( basename + ".xml" ) as provenance_file :
739
+ with write_bag_file ( self .research_object , basename + ".xml" ) as provenance_file :
742
740
self .document .serialize (provenance_file , format = "xml" , indent = 4 )
743
741
prov_ids .append (self .provenance_ns [filename + ".xml" ])
744
742
745
743
# https://www.w3.org/TR/prov-n/
746
- with self .research_object . write_bag_file ( basename + ".provn" ) as provenance_file :
744
+ with write_bag_file ( self .research_object , basename + ".provn" ) as provenance_file :
747
745
self .document .serialize (provenance_file , format = "provn" , indent = 2 )
748
746
prov_ids .append (self .provenance_ns [filename + ".provn" ])
749
747
750
748
# https://www.w3.org/Submission/prov-json/
751
- with self .research_object . write_bag_file ( basename + ".json" ) as provenance_file :
749
+ with write_bag_file ( self .research_object , basename + ".json" ) as provenance_file :
752
750
self .document .serialize (provenance_file , format = "json" , indent = 2 )
753
751
prov_ids .append (self .provenance_ns [filename + ".json" ])
754
752
755
753
# "rdf" aka https://www.w3.org/TR/prov-o/
756
754
# which can be serialized to ttl/nt/jsonld (and more!)
757
755
758
756
# https://www.w3.org/TR/turtle/
759
- with self .research_object . write_bag_file ( basename + ".ttl" ) as provenance_file :
757
+ with write_bag_file ( self .research_object , basename + ".ttl" ) as provenance_file :
760
758
self .document .serialize (provenance_file , format = "rdf" , rdf_format = "turtle" )
761
759
prov_ids .append (self .provenance_ns [filename + ".ttl" ])
762
760
763
761
# https://www.w3.org/TR/n-triples/
764
- with self .research_object . write_bag_file ( basename + ".nt" ) as provenance_file :
762
+ with write_bag_file ( self .research_object , basename + ".nt" ) as provenance_file :
765
763
self .document .serialize (provenance_file , format = "rdf" , rdf_format = "ntriples" )
766
764
prov_ids .append (self .provenance_ns [filename + ".nt" ])
767
765
768
766
# https://www.w3.org/TR/json-ld/
769
767
# TODO: Use a nice JSON-LD context
770
768
# see also https://eprints.soton.ac.uk/395985/
771
769
# 404 Not Found on https://provenance.ecs.soton.ac.uk/prov.jsonld :(
772
- with self .research_object . write_bag_file ( basename + ".jsonld" ) as provenance_file :
770
+ with write_bag_file ( self .research_object , basename + ".jsonld" ) as provenance_file :
773
771
self .document .serialize (provenance_file , format = "rdf" , rdf_format = "json-ld" )
774
772
prov_ids .append (self .provenance_ns [filename + ".jsonld" ])
775
773
0 commit comments