Skip to content

Commit 328bf0f

Browse files
committed
Provenance: Fixed type declarations for my2/my3
1 parent c8eff52 commit 328bf0f

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

cwltool/job.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def _execute(self,
226226
if self.joborder and runtimeContext.research_obj:
227227
job_order = self.joborder
228228
assert runtimeContext.prov_obj
229+
assert runtimeContext.process_run_id
229230
runtimeContext.prov_obj.used_artefacts(
230231
job_order, runtimeContext.process_run_id, str(self.name))
231232
outputs = {} # type: Dict[Text,Text]

cwltool/provenance.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,10 @@ def start_process(self, process_name, process_run_id=None):
525525
return process_run_id
526526

527527
def declare_artefact(self, value):
528-
# type: (Any) -> Optional[ProvEntity]
528+
# type: (Any) -> ProvEntity
529529
'''
530530
create data artefact entities for all file objects.
531531
'''
532-
533532
if value is None:
534533
# FIXME: If this can happen in CWL, we'll
535534
# need a better way to represent this in PROV
@@ -545,15 +544,9 @@ def declare_artefact(self, value):
545544
return self.document.entity(uuid.uuid4().urn,
546545
{ provM.PROV_VALUE: value })
547546

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))
557550
data_file = self.research_object.add_data_file(byte_s)
558551
# FIXME: Don't naively assume add_data_file uses hash in filename!
559552
data_id = "data:%s" % posixpath.split(data_file)[1]
@@ -584,8 +577,8 @@ def declare_artefact(self, value):
584577
{provM.PROV_TYPE: WFPROV["Artifact"]})
585578

586579
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"])
589582

590583
elif value.get("class") == "Directory":
591584
# Register any nested files/directories
@@ -644,7 +637,7 @@ def declare_artefact(self, value):
644637

645638
# Let's iterate and recurse
646639
coll_attribs = [] # type ( tuple(Identifier, ProvEntity) )
647-
for (k,v) in cast(Dict, value).items():
640+
for (k,v) in value.items():
648641
v_ent = self.declare_artefact(v)
649642
self.document.membership(coll, v_ent)
650643
m = self.document.entity(uuid.uuid4().urn)
@@ -694,7 +687,7 @@ def declare_artefact(self, value):
694687
def used_artefacts(self,
695688
job_order, # type: Dict
696689
process_run_id, # type: str
697-
name=None # type: Optional[str]
690+
name=None # type: str
698691
): # type: (...) -> None
699692
'''
700693
adds used() for each data artefact
@@ -814,8 +807,8 @@ def prospective_prov(self, job):
814807
"prov:label": "Prospective provenance"})
815808
# TODO: Declare roles/parameters as well
816809

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
819812

820813
# Add http://www.w3.org/TR/prov-aq/ relations to nested PROV files
821814
# 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):
828821
self.research_object.add_annotation(activity, uris, PROV["has_provenance"].uri)
829822

830823
def finalize_prov_profile(self, name):
831-
# type: (Optional[str]) -> List[Identifier]
824+
# type: (Optional[Text]) -> List[Identifier]
832825
'''
833826
Transfer the provenance related files to RO
834827
'''
@@ -1155,14 +1148,15 @@ def add_annotation(self, about, content, motivatedBy="oa:describing"):
11551148
content = [c.replace(curr, "")
11561149
.replace(self.base_uri, "../")
11571150
for c in content]
1151+
uri = uuid.uuid4().urn
11581152
ann = {
1159-
"uri": uuid.uuid4().urn,
1153+
"uri": uri,
11601154
"about": about,
11611155
"content": content,
11621156
"oa:motivatedBy": {"@id": motivatedBy}
11631157
}
11641158
self.annotations.append(ann)
1165-
return ann["uri"]
1159+
return uri
11661160

11671161
def _ro_annotations(self):
11681162
# type: () -> List[Dict]
@@ -1315,6 +1309,8 @@ def packed_workflow(self, packed): # type: (Text) -> None
13151309
_logger.info(u"[provenance] Added packed workflow: %s", rel_path)
13161310

13171311
def has_data_file(self, sha1hash):
1312+
# type: (str) -> bool
1313+
assert self.folder
13181314
folder = os.path.join(self.folder, DATA, sha1hash[0:2])
13191315
return os.path.isfile(os.path.join(folder, sha1hash))
13201316

cwltool/workflow.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import six
1919
from six import string_types
2020
from six.moves import range
21+
from uuid import UUID # pylint: disable=unused-import
2122

2223
from . import command_line_tool, expression
2324
from .builder import CONTENT_LIMIT
@@ -257,7 +258,7 @@ def do_output_callback(self, final_output_callback):
257258
datetime.datetime.now())
258259
prov_ids = self.prov_obj.finalize_prov_profile(self.name)
259260
# Tell parent to associate our provenance files with our wf run
260-
self.parent_wf.activity_has_provenance(self.prov_obj.workflow_run_uri, *prov_ids)
261+
self.parent_wf.activity_has_provenance(self.prov_obj.workflow_run_uri, prov_ids)
261262

262263
_logger.info(u"[%s] completed %s", self.name, self.processStatus)
263264
if _logger.isEnabledFor(logging.DEBUG):
@@ -502,7 +503,7 @@ def __init__(self,
502503
toolpath_object, loadingContext)
503504
self.provenance_object = None # type: Optional[CreateProvProfile]
504505
if loadingContext.research_obj:
505-
run_uuid = None # type: Optional[uuid.UUID]
506+
run_uuid = None # type: Optional[UUID]
506507
is_master = not(loadingContext.prov_obj) # Not yet set
507508
if is_master:
508509
run_uuid = loadingContext.research_obj.ro_uuid

0 commit comments

Comments
 (0)