19109: test/fix for related bug, finding secondary files with expressions
authorPeter Amstutz <peter.amstutz@curii.com>
Wed, 11 May 2022 19:42:28 +0000 (15:42 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Wed, 11 May 2022 19:42:28 +0000 (15:42 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

sdk/cwl/arvados_cwl/runner.py
sdk/cwl/tests/19109-upload-secondary.cwl
sdk/cwl/tests/19109-upload-secondary.yml
sdk/cwl/tests/19109-upload-secondary/file2.txt [new file with mode: 0644]
sdk/cwl/tests/19109-upload-secondary/file2.txt.tbi [new file with mode: 0644]

index f2517f919990f2de670d9d291e5d7ac94edf0765..995b23c080c361f5ac387b9ea47e128946fb79e2 100644 (file)
@@ -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)
 
index cf5855ab19356c64670e9e5dd04ae77a0d0d0ffb..933496b6a5dd70ceb76e836f40088dee51a138f4 100644 (file)
@@ -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]
index c97850019ba8a06017b7c051b2db5f25327214d4..af4147ae9ad1dcf3856f5b4c96aa79085504028f 100644 (file)
@@ -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 (file)
index 0000000..637a09b
--- /dev/null
@@ -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 (file)
index 0000000..4d5e625
--- /dev/null
@@ -0,0 +1 @@
+mango
\ No newline at end of file