2424from prov .model import PROV , PROV_LABEL , PROV_TYPE , PROV_VALUE , ProvDocument , ProvEntity
2525from schema_salad .sourceline import SourceLine
2626
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
3134from .provenance_constants import (
3235 ACCOUNT_UUID ,
3336 CWLPROV ,
4649 WFDESC ,
4750 WFPROV ,
4851)
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
5253
5354if TYPE_CHECKING :
54- from .provenance import ResearchObject
55+ from .ro import ResearchObject
5556
5657
5758def copy_job_order (job : Union [Process , JobsType ], job_order_object : CWLObjectType ) -> CWLObjectType :
@@ -114,10 +115,7 @@ def __init__(
114115
115116 def __str__ (self ) -> str :
116117 """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 } >"
121119
122120 def generate_prov_doc (self ) -> Tuple [str , ProvDocument ]:
123121 """Add basic namespaces."""
@@ -140,7 +138,7 @@ def host_provenance(document: ProvDocument) -> None:
140138 },
141139 )
142140
143- self .cwltool_version = "cwltool %s" % versionstring ().split ()[- 1 ]
141+ self .cwltool_version = f "cwltool { versionstring ().split ()[- 1 ]} "
144142 self .document .add_namespace ("wfprov" , "http://purl.org/wf4ever/wfprov#" )
145143 # document.add_namespace('prov', 'http://www.w3.org/ns/prov#')
146144 self .document .add_namespace ("wfdesc" , "http://purl.org/wf4ever/wfdesc#" )
@@ -240,7 +238,7 @@ def evaluate(
240238 self .prospective_prov (job )
241239 customised_job = copy_job_order (job , job_order_object )
242240 self .used_artefacts (customised_job , self .workflow_run_uri )
243- research_obj . create_job (customised_job )
241+ create_job (research_obj , customised_job )
244242 elif hasattr (job , "workflow" ):
245243 # record provenance of workflow executions
246244 self .prospective_prov (job )
@@ -460,7 +458,7 @@ def declare_directory(self, value: CWLObjectType) -> ProvEntity:
460458 ore_doc .add_bundle (dir_bundle )
461459 ore_doc = ore_doc .flattened ()
462460 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 :
464462 ore_doc .serialize (provenance_file , format = "rdf" , rdf_format = "turtle" )
465463 self .research_object .add_annotation (dir_id , [ore_doc_fn ], ORE ["isDescribedBy" ].uri )
466464
@@ -477,7 +475,7 @@ def declare_string(self, value: str) -> Tuple[ProvEntity, str]:
477475 data_file = self .research_object .add_data_file (byte_s , content_type = TEXT_PLAIN )
478476 checksum = PurePosixPath (data_file ).name
479477 # 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 } "
481479 entity = self .document .entity (
482480 data_id , {PROV_TYPE : WFPROV ["Artifact" ], PROV_VALUE : str (value )}
483481 )
@@ -509,7 +507,7 @@ def declare_artefact(self, value: Any) -> ProvEntity:
509507 byte_s = BytesIO (value )
510508 data_file = self .research_object .add_data_file (byte_s )
511509 # 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 } "
513511 return self .document .entity (
514512 data_id ,
515513 {PROV_TYPE : WFPROV ["Artifact" ], PROV_VALUE : str (value )},
@@ -654,7 +652,7 @@ def generate_output_prov(
654652 # FIXME: Probably not "main" in nested workflows
655653 role = self .wf_ns [f"main/{ name } /{ output } " ]
656654 else :
657- role = self .wf_ns ["main/%s" % output ]
655+ role = self .wf_ns [f "main/{ output } " ]
658656
659657 if not process_run_id :
660658 process_run_id = self .workflow_run_uri
@@ -738,38 +736,38 @@ def finalize_prov_profile(self, name: Optional[str]) -> List[QualifiedName]:
738736 prov_ids = []
739737
740738 # 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 :
742740 self .document .serialize (provenance_file , format = "xml" , indent = 4 )
743741 prov_ids .append (self .provenance_ns [filename + ".xml" ])
744742
745743 # 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 :
747745 self .document .serialize (provenance_file , format = "provn" , indent = 2 )
748746 prov_ids .append (self .provenance_ns [filename + ".provn" ])
749747
750748 # 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 :
752750 self .document .serialize (provenance_file , format = "json" , indent = 2 )
753751 prov_ids .append (self .provenance_ns [filename + ".json" ])
754752
755753 # "rdf" aka https://www.w3.org/TR/prov-o/
756754 # which can be serialized to ttl/nt/jsonld (and more!)
757755
758756 # 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 :
760758 self .document .serialize (provenance_file , format = "rdf" , rdf_format = "turtle" )
761759 prov_ids .append (self .provenance_ns [filename + ".ttl" ])
762760
763761 # 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 :
765763 self .document .serialize (provenance_file , format = "rdf" , rdf_format = "ntriples" )
766764 prov_ids .append (self .provenance_ns [filename + ".nt" ])
767765
768766 # https://www.w3.org/TR/json-ld/
769767 # TODO: Use a nice JSON-LD context
770768 # see also https://eprints.soton.ac.uk/395985/
771769 # 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 :
773771 self .document .serialize (provenance_file , format = "rdf" , rdf_format = "json-ld" )
774772 prov_ids .append (self .provenance_ns [filename + ".jsonld" ])
775773
0 commit comments