Skip to content

Commit b5364d4

Browse files
committed
allow expression in the inputBinding.position
1 parent 2d7cde3 commit b5364d4

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

cwltool/builder.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def bind_input(self,
195195
discover_secondaryFiles, # type: bool
196196
lead_pos=None, # type: Optional[Union[int, List[int]]]
197197
tail_pos=None, # type: Optional[List[int]]
198+
cwl_version=None # type: Optional[Text]
198199
): # type: (...) -> List[MutableMapping[Text, Any]]
199200

200201
if tail_pos is None:
@@ -211,7 +212,12 @@ def bind_input(self,
211212

212213
bp = list(aslist(lead_pos))
213214
if "position" in binding:
214-
bp.extend(aslist(binding["position"]))
215+
position = binding["position"]
216+
if isinstance(position, str) and cwl_version != "v1.0":
217+
binding['position'] = self.do_eval(position, context=datum)
218+
bp.append(binding['position'])
219+
else:
220+
bp.extend(aslist(binding['position']))
215221
else:
216222
bp.append(0)
217223
bp.extend(aslist(tail_pos))

cwltool/process.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,13 @@ def inc(d): # type: (List[int]) -> None
703703
tmpdir,
704704
stagedir)
705705

706+
cwl_version = self.metadata.get(
707+
"http://commonwl.org/cwltool#original_cwlVersion", None)
708+
706709
bindings.extend(builder.bind_input(
707710
self.inputs_record_schema, job,
708-
discover_secondaryFiles=getdefault(runtime_context.toplevel, False)))
711+
discover_secondaryFiles=getdefault(runtime_context.toplevel, False),
712+
cwl_version=cwl_version))
709713

710714
if self.tool.get("baseCommand"):
711715
for index, command in enumerate(aslist(self.tool["baseCommand"])):
@@ -722,7 +726,12 @@ def inc(d): # type: (List[int]) -> None
722726
if isinstance(arg, MutableMapping):
723727
arg = copy.deepcopy(arg)
724728
if arg.get("position"):
725-
arg["position"] = [arg["position"], i]
729+
position = arg.get("position")
730+
if isinstance(position, str) and cwl_version != "v1.0":
731+
position = builder.do_eval(position)
732+
if position is None:
733+
position = 0
734+
arg["position"] = [position, i]
726735
else:
727736
arg["position"] = [0, i]
728737
bindings.append(arg)

0 commit comments

Comments
 (0)