@@ -525,11 +525,10 @@ def start_process(self, process_name, process_run_id=None):
525
525
return process_run_id
526
526
527
527
def declare_artefact (self , value ):
528
- # type: (Any) -> Optional[ ProvEntity]
528
+ # type: (Any) -> ProvEntity
529
529
'''
530
530
create data artefact entities for all file objects.
531
531
'''
532
-
533
532
if value is None :
534
533
# FIXME: If this can happen in CWL, we'll
535
534
# need a better way to represent this in PROV
@@ -545,15 +544,9 @@ def declare_artefact(self, value):
545
544
return self .document .entity (uuid .uuid4 ().urn ,
546
545
{ provM .PROV_VALUE : value })
547
546
548
- elif isinstance (value , (str , Text , bytes )):
549
- if type (value ) == bytes :
550
- # Leave as-is (Note: In Python2 this includes strings
551
- # which will be written with system encoding)
552
- byte_s = io .BytesIO (value )
553
- else :
554
- # Save as string in UTF-8
555
- byte_s = io .BytesIO (str (value ).encode (ENCODING ))
556
-
547
+ elif isinstance (value , Text ):
548
+ # Save as string in UTF-8
549
+ byte_s = io .BytesIO (str (value ).encode (ENCODING ))
557
550
data_file = self .research_object .add_data_file (byte_s )
558
551
# FIXME: Don't naively assume add_data_file uses hash in filename!
559
552
data_id = "data:%s" % posixpath .split (data_file )[1 ]
@@ -584,8 +577,8 @@ def declare_artefact(self, value):
584
577
{provM .PROV_TYPE : WFPROV ["Artifact" ]})
585
578
586
579
if 'content' in value :
587
- # Anonymous file, add content as bytes
588
- return declare_artefact (value ["content" ])
580
+ # Anonymous file, add content as string
581
+ return self . declare_artefact (value ["content" ])
589
582
590
583
elif value .get ("class" ) == "Directory" :
591
584
# Register any nested files/directories
@@ -644,7 +637,7 @@ def declare_artefact(self, value):
644
637
645
638
# Let's iterate and recurse
646
639
coll_attribs = [] # type ( tuple(Identifier, ProvEntity) )
647
- for (k ,v ) in cast ( Dict , value ) .items ():
640
+ for (k ,v ) in value .items ():
648
641
v_ent = self .declare_artefact (v )
649
642
self .document .membership (coll , v_ent )
650
643
m = self .document .entity (uuid .uuid4 ().urn )
@@ -694,7 +687,7 @@ def declare_artefact(self, value):
694
687
def used_artefacts (self ,
695
688
job_order , # type: Dict
696
689
process_run_id , # type: str
697
- name = None # type: Optional[ str]
690
+ name = None # type: str
698
691
): # type: (...) -> None
699
692
'''
700
693
adds used() for each data artefact
@@ -814,8 +807,8 @@ def prospective_prov(self, job):
814
807
"prov:label" : "Prospective provenance" })
815
808
# TODO: Declare roles/parameters as well
816
809
817
- def activity_has_provenance (self , activity , * prov_ids ):
818
- # type: (str, * List[Identifier]) -> None
810
+ def activity_has_provenance (self , activity , prov_ids ):
811
+ # type: (str, List[Identifier]) -> None
819
812
820
813
# Add http://www.w3.org/TR/prov-aq/ relations to nested PROV files
821
814
# NOTE: The below will only work if the corresponding metadata/provenance arcp URI
@@ -828,7 +821,7 @@ def activity_has_provenance(self, activity, *prov_ids):
828
821
self .research_object .add_annotation (activity , uris , PROV ["has_provenance" ].uri )
829
822
830
823
def finalize_prov_profile (self , name ):
831
- # type: (Optional[str ]) -> List[Identifier]
824
+ # type: (Optional[Text ]) -> List[Identifier]
832
825
'''
833
826
Transfer the provenance related files to RO
834
827
'''
@@ -1155,14 +1148,15 @@ def add_annotation(self, about, content, motivatedBy="oa:describing"):
1155
1148
content = [c .replace (curr , "" )
1156
1149
.replace (self .base_uri , "../" )
1157
1150
for c in content ]
1151
+ uri = uuid .uuid4 ().urn
1158
1152
ann = {
1159
- "uri" : uuid . uuid4 (). urn ,
1153
+ "uri" : uri ,
1160
1154
"about" : about ,
1161
1155
"content" : content ,
1162
1156
"oa:motivatedBy" : {"@id" : motivatedBy }
1163
1157
}
1164
1158
self .annotations .append (ann )
1165
- return ann [ " uri" ]
1159
+ return uri
1166
1160
1167
1161
def _ro_annotations (self ):
1168
1162
# type: () -> List[Dict]
@@ -1315,6 +1309,8 @@ def packed_workflow(self, packed): # type: (Text) -> None
1315
1309
_logger .info (u"[provenance] Added packed workflow: %s" , rel_path )
1316
1310
1317
1311
def has_data_file (self , sha1hash ):
1312
+ # type: (str) -> bool
1313
+ assert self .folder
1318
1314
folder = os .path .join (self .folder , DATA , sha1hash [0 :2 ])
1319
1315
return os .path .isfile (os .path .join (folder , sha1hash ))
1320
1316
0 commit comments