From 58241cc5b82c39270b1d0425a0a1fec4aae8f45e Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Wed, 11 May 2022 15:42:28 -0400 Subject: [PATCH] 19109: test/fix for related bug, finding secondary files with expressions Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- sdk/cwl/arvados_cwl/runner.py | 19 +++++++++++++++--- sdk/cwl/tests/19109-upload-secondary.cwl | 20 +++++++++++++++++++ sdk/cwl/tests/19109-upload-secondary.yml | 3 +++ .../tests/19109-upload-secondary/file2.txt | 1 + .../19109-upload-secondary/file2.txt.tbi | 1 + 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 sdk/cwl/tests/19109-upload-secondary/file2.txt create mode 100644 sdk/cwl/tests/19109-upload-secondary/file2.txt.tbi diff --git a/sdk/cwl/arvados_cwl/runner.py b/sdk/cwl/arvados_cwl/runner.py index f2517f9199..995b23c080 100644 --- a/sdk/cwl/arvados_cwl/runner.py +++ b/sdk/cwl/arvados_cwl/runner.py @@ -177,9 +177,9 @@ def set_secondary(fsaccess, builder, inputschema, secondaryspec, primary, discov primary["secondaryFiles"] = secondaryspec for i, sf in enumerate(aslist(secondaryspec)): if builder.cwlVersion == "v1.0": - pattern = builder.do_eval(sf, context=primary) + pattern = sf else: - pattern = builder.do_eval(sf["pattern"], context=primary) + pattern = sf["pattern"] if pattern is None: continue if isinstance(pattern, list): @@ -216,7 +216,20 @@ def set_secondary(fsaccess, builder, inputschema, secondaryspec, primary, discov "Expression must return list, object, string or null") if pattern is not None: - sfpath = substitute(primary["location"], pattern) + if "${" in pattern or "$(" in pattern: + sfname = builder.do_eval(pattern, context=primary) + else: + sfname = substitute(primary["basename"], pattern) + + if sfname is None: + continue + + p_location = primary["location"] + if "/" in p_location: + sfpath = ( + p_location[0 : p_location.rindex("/") + 1] + + sfname + ) required = builder.do_eval(required, context=primary) diff --git a/sdk/cwl/tests/19109-upload-secondary.cwl b/sdk/cwl/tests/19109-upload-secondary.cwl index cf5855ab19..933496b6a5 100644 --- a/sdk/cwl/tests/19109-upload-secondary.cwl +++ b/sdk/cwl/tests/19109-upload-secondary.cwl @@ -4,19 +4,39 @@ cwlVersion: v1.2 class: Workflow + +requirements: + InlineJavascriptRequirement: {} + inputs: file1: type: File? secondaryFiles: - pattern: .tbi required: true + file2: + type: File + secondaryFiles: + - pattern: | + ${ + return self.basename + '.tbi'; + } + required: true outputs: out: type: File outputSource: cat/out + out2: + type: File + outputSource: cat2/out steps: cat: in: inp: file1 run: cat2.cwl out: [out] + cat2: + in: + inp: file2 + run: cat2.cwl + out: [out] diff --git a/sdk/cwl/tests/19109-upload-secondary.yml b/sdk/cwl/tests/19109-upload-secondary.yml index c97850019b..af4147ae9a 100644 --- a/sdk/cwl/tests/19109-upload-secondary.yml +++ b/sdk/cwl/tests/19109-upload-secondary.yml @@ -5,3 +5,6 @@ file1: class: File location: 19109-upload-secondary/file1.txt +file2: + class: File + location: 19109-upload-secondary/file2.txt diff --git a/sdk/cwl/tests/19109-upload-secondary/file2.txt b/sdk/cwl/tests/19109-upload-secondary/file2.txt new file mode 100644 index 0000000000..637a09b86a --- /dev/null +++ b/sdk/cwl/tests/19109-upload-secondary/file2.txt @@ -0,0 +1 @@ +banana diff --git a/sdk/cwl/tests/19109-upload-secondary/file2.txt.tbi b/sdk/cwl/tests/19109-upload-secondary/file2.txt.tbi new file mode 100644 index 0000000000..4d5e62525a --- /dev/null +++ b/sdk/cwl/tests/19109-upload-secondary/file2.txt.tbi @@ -0,0 +1 @@ +mango \ No newline at end of file -- 2.30.2