Skip to content

Commit d7cd45f

Browse files
authored
Merge pull request #1233 from illusional/secondary-rename
Allow specification of file object in sec expression
2 parents 6f78ea7 + ee8d2e2 commit d7cd45f

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

cwltool/builder.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -390,31 +390,56 @@ def _capture_files(f): # type: (Dict[str, str]) -> Dict[str, str]
390390
if not sfname:
391391
continue
392392
found = False
393+
394+
if isinstance(sfname, str):
395+
sf_location = (
396+
datum["location"][
397+
0 : datum["location"].rindex("/") + 1
398+
]
399+
+ sfname
400+
)
401+
sfbasename = sfname
402+
elif isinstance(sfname, MutableMapping):
403+
sf_location = sfname["location"]
404+
sfbasename = sfname["basename"]
405+
else:
406+
raise WorkflowException(
407+
"Expected secondaryFile expression to return type 'str' or 'MutableMapping', received '%s'"
408+
% (type(sfname))
409+
)
410+
393411
for d in datum["secondaryFiles"]:
394412
if not d.get("basename"):
395413
d["basename"] = d["location"][
396414
d["location"].rindex("/") + 1 :
397415
]
398-
if d["basename"] == sfname:
416+
if d["basename"] == sfbasename:
399417
found = True
418+
400419
if not found:
401-
sf_location = (
402-
datum["location"][
403-
0 : datum["location"].rindex("/") + 1
404-
]
405-
+ sfname
406-
)
420+
421+
def addsf(
422+
files: MutableSequence[MutableMapping[str, Any]],
423+
newsf: MutableMapping[str, Any],
424+
) -> None:
425+
for f in files:
426+
if f["location"] == newsf["location"]:
427+
f["basename"] = newsf["basename"]
428+
return
429+
files.append(newsf)
430+
407431
if isinstance(sfname, MutableMapping):
408-
datum["secondaryFiles"].append(sfname)
432+
addsf(datum["secondaryFiles"], sfname)
409433
elif discover_secondaryFiles and self.fs_access.exists(
410434
sf_location
411435
):
412-
datum["secondaryFiles"].append(
436+
addsf(
437+
datum["secondaryFiles"],
413438
{
414439
"location": sf_location,
415440
"basename": sfname,
416441
"class": "File",
417-
}
442+
},
418443
)
419444
elif sf_required:
420445
raise WorkflowException(

0 commit comments

Comments
 (0)