Skip to content

Commit f35a5c7

Browse files
committed
Fixes for FSaccess in provenance
1 parent c6fb488 commit f35a5c7

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

cwltool/executors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ def run_jobs(self,
159159
user_provenance=False,
160160
orcid=runtime_context.orcid,
161161
# single tool execution, so RO UUID = wf UUID = tool UUID
162-
run_uuid=runtime_context.research_obj.ro_uuid)
162+
run_uuid=runtime_context.research_obj.ro_uuid,
163+
fsaccess=runtime_context.make_fs_access(''))
163164
process.parent_wf = process.provenance_object
164165
jobiter = process.job(job_order_object, self.output_callback,
165166
runtime_context)

cwltool/provenance.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,14 @@ def __init__(self,
305305
host_provenance, # type: bool
306306
user_provenance, # type: bool
307307
orcid, # type: str
308-
run_uuid=None # type: Optional[uuid.UUID]
308+
run_uuid=None, # type: Optional[uuid.UUID],
309+
fsaccess=None # type: Optional[StdFsAccess]
309310
): # type: (...) -> None
310311
"""Initialize the provenance profile."""
312+
if not fsaccess:
313+
fsaccess = StdFsAccess('')
314+
self.fsaccess = fsaccess
315+
311316
self.orcid = orcid
312317
self.research_object = research_object
313318
self.folder = self.research_object.folder
@@ -504,8 +509,7 @@ def declare_file(self, value):
504509
if not entity and 'location' in value:
505510
location = str(value['location'])
506511
# If we made it here, we'll have to add it to the RO
507-
fsaccess = StdFsAccess("")
508-
with fsaccess.open(location, "rb") as fhandle:
512+
with self.fsaccess.open(location, "rb") as fhandle:
509513
relative_path = self.research_object.add_data_file(fhandle)
510514
# FIXME: This naively relies on add_data_file setting hash as filename
511515
checksum = PurePath(relative_path).name
@@ -592,8 +596,7 @@ def declare_directory(self, value): # type: (MutableMapping[Text, Any]) -> Prov
592596
is_empty = True
593597

594598
if "listing" not in value:
595-
fsaccess = StdFsAccess("")
596-
get_listing(fsaccess, value)
599+
get_listing(self.fsaccess, value)
597600
for entry in value.get("listing", []):
598601
is_empty = False
599602
# Declare child-artifacts
@@ -937,8 +940,9 @@ def finalize_prov_profile(self, name):
937940
class ResearchObject():
938941
"""CWLProv Research Object."""
939942

940-
def __init__(self, temp_prefix_ro="tmp", orcid='', full_name=''):
943+
def __init__(self, temp_prefix_ro="tmp", orcid='', full_name='', fsaccess=None):
941944
# type: (str, Text, Text) -> None
945+
# type: Optional[StdFsAccess]
942946
"""Initialize the ResearchObject."""
943947
self.temp_prefix = temp_prefix_ro
944948
self.orcid = '' if not orcid else _valid_orcid(orcid)
@@ -954,7 +958,7 @@ def __init__(self, temp_prefix_ro="tmp", orcid='', full_name=''):
954958
self._external_aggregates = [] # type: List[Dict[Text, Text]]
955959
self.annotations = [] # type: List[Dict[Text, Any]]
956960
self._content_types = {} # type: Dict[Text,str]
957-
961+
self.fsaccess = fsaccess
958962
# These should be replaced by generate_prov_doc when workflow/run IDs are known:
959963
self.engine_uuid = "urn:uuid:%s" % uuid.uuid4()
960964
self.ro_uuid = uuid.uuid4()
@@ -1553,8 +1557,7 @@ def _relativise_files(self, structure):
15531557
# Register in RO; but why was this not picked
15541558
# up by used_artefacts?
15551559
_logger.info("[provenance] Adding to RO %s", structure["location"])
1556-
fsaccess = StdFsAccess("")
1557-
with fsaccess.open(structure["location"], "rb") as fp:
1560+
with self.fsaccess.open(structure["location"], "rb") as fp:
15581561
relative_path = self.add_data_file(fp)
15591562
checksum = PurePosixPath(relative_path).name
15601563
structure["checksum"] = "%s$%s" % (SHA1, checksum)

cwltool/workflow.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,8 @@ def __init__(self,
522522
host_provenance=loadingContext.host_provenance,
523523
user_provenance=loadingContext.user_provenance,
524524
orcid=loadingContext.orcid,
525-
run_uuid=run_uuid) # inherit RO UUID for master wf run
525+
run_uuid=run_uuid,
526+
fsaccess=loadingContext.research_obj.fsaccess) # inherit RO UUID for master wf run
526527
# TODO: Is Workflow(..) only called when we are the master workflow?
527528
self.parent_wf = self.provenance_object
528529

0 commit comments

Comments
 (0)