summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2025-11-24 00:57:12 +0000
committerArun Isaac2025-11-24 01:33:27 +0000
commit124c5c51c24b0eacba891da9c6a2e4bc9eb1937a (patch)
treeaef236cbb49a7591bddac49f888851dd0627428c
parentd22f48630c08ef79fe25c580126a8d9bd373c522 (diff)
downloadravanan-124c5c51c24b0eacba891da9c6a2e4bc9eb1937a.tar.gz
ravanan-124c5c51c24b0eacba891da9c6a2e4bc9eb1937a.tar.lz
ravanan-124c5c51c24b0eacba891da9c6a2e4bc9eb1937a.zip
reader: Resolve YAML inputs file type ambiguities.
Resolve YAML inputs file type ambiguities by reading them along with
the workflow file and using the workflow input types to guide their
type coercion.
-rw-r--r--Makefile3
-rwxr-xr-xbin/ravanan7
-rw-r--r--ravanan/reader.scm28
-rw-r--r--test-data/inputs-with-type-ambiguities.yaml5
-rw-r--r--test-data/workflow-for-inputs-with-type-ambiguities.cwl11
-rw-r--r--tests/reader.scm16
6 files changed, 61 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index f4669d1..b37072e 100644
--- a/Makefile
+++ b/Makefile
@@ -44,8 +44,9 @@ sources = $(filter-out $(config_file), \
 objects = $(sources:.scm=.go) $(config_file:.scm=.go)
 scripts = $(wildcard bin/*)
 tests = $(wildcard tests/*.scm) $(wildcard tests/work/*.scm)
+test_data = $(wildcard test-data/*)
 distribute_files = $(sources) $(config_file_template) $(scripts) \
-                   $(tests) pre-inst-env guix.scm \
+                   $(tests) $(test_data) pre-inst-env guix.scm \
                    .guix/ravanan-package.scm Makefile \
                    COPYING README.md
 
diff --git a/bin/ravanan b/bin/ravanan
index c8d37e9..2cb05e2 100755
--- a/bin/ravanan
+++ b/bin/ravanan
@@ -24,6 +24,7 @@ exec guile --no-auto-compile -e main -s "$0" "$@"
              (rnrs io ports)
              (srfi srfi-26)
              (srfi srfi-37)
+             (srfi srfi-71)
              (ice-9 filesystem)
              (ice-9 match)
              (web uri)
@@ -259,6 +260,8 @@ files that have the token in the @verbatim{SLURM_JWT=token} format."
                    (store (if (file-name-absolute? (assq-ref args 'store))
                               (assq-ref args 'store)
                               (canonicalize-path (assq-ref args 'store))))
+                   (workflow inputs (read-workflow+inputs workflow-file
+                                                          inputs-file))
                    (outputs (guard (c ((manifest-file-error? c)
                                        ;; Steps may provide their own
                                        ;; SoftwareRequirement. So, at this
@@ -288,8 +291,8 @@ files that have the token in the @verbatim{SLURM_JWT=token} format."
                                                    (assq-ref args 'guix-channels-file))
                                                   #:modules '((guile)
                                                               (guix channels))))
-                                            (read-workflow workflow-file)
-                                            (read-inputs inputs-file)
+                                            workflow
+                                            inputs
                                             (case (assq-ref args 'batch-system)
                                               ((single-machine)
                                                (or (assq-ref args 'scratch)
diff --git a/ravanan/reader.scm b/ravanan/reader.scm
index b8687b0..c30aa9f 100644
--- a/ravanan/reader.scm
+++ b/ravanan/reader.scm
@@ -31,8 +31,7 @@
   #:use-module (ravanan work ui)
   #:use-module (ravanan work utils)
   #:use-module (ravanan work vectors)
-  #:export (read-workflow
-            read-inputs
+  #:export (read-workflow+inputs
             coerce-type))
 
 (define-condition-type &type-coercion-violation &violation
@@ -300,8 +299,10 @@ array of array of @code{File}s, etc. Else, return @code{#f}"
     (canonicalize-file-value input))
    (else input)))
 
-(define (read-inputs inputs-file)
-  "Read @var{inputs-file} resolving file paths if any."
+(define (read-inputs inputs-file types)
+  "Read @var{inputs-file} resolving file paths if any. If @var{inputs-file} is an
+YAML file, coerce inputs to @var{types}. @var{types} is an association list
+mapping input identifiers to CWL types."
   (guard (c ((and (who-condition? c)
                   (memq (condition-who c)
                         '(read-json-file read-yaml-file))
@@ -327,7 +328,24 @@ array of array of @code{File}s, etc. Else, return @code{#f}"
                (if (string=? (file-name-extension inputs-path)
                              ".json")
                    (read-json-file (basename inputs-path))
-                   (read-yaml-file (basename inputs-path)))))))))
+                   (map (match-lambda
+                          ((input-id . input)
+                           (cons input-id
+                                 (cond
+                                  ((assoc-ref types input-id)
+                                   => (cut coerce-type input <>))
+                                  (else input)))))
+                        (read-yaml-file (basename inputs-path))))))))))
+
+(define (read-workflow+inputs workflow-file inputs-file)
+  (let ((workflow-cwl (read-workflow workflow-file)))
+    (values workflow-cwl
+            (read-inputs inputs-file
+                         (vector-map->list (lambda (formal-input)
+                                             (cons (assoc-ref formal-input "id")
+                                                   (formal-parameter-type
+                                                    (assoc-ref formal-input "type"))))
+                                           (assoc-ref workflow-cwl "inputs"))))))
 
 (define (coerce-type val type)
   "Coerce @var{val} to CWL @var{type}."
diff --git a/test-data/inputs-with-type-ambiguities.yaml b/test-data/inputs-with-type-ambiguities.yaml
new file mode 100644
index 0000000..119b72f
--- /dev/null
+++ b/test-data/inputs-with-type-ambiguities.yaml
@@ -0,0 +1,5 @@
+number: 13
+flag: true
+reverseflag: false
+foo: bar
+arr: [1, 2, 3]
diff --git a/test-data/workflow-for-inputs-with-type-ambiguities.cwl b/test-data/workflow-for-inputs-with-type-ambiguities.cwl
new file mode 100644
index 0000000..4e33148
--- /dev/null
+++ b/test-data/workflow-for-inputs-with-type-ambiguities.cwl
@@ -0,0 +1,11 @@
+class: Workflow
+inputs:
+  number: int
+  flag: boolean
+  reverseflag: boolean
+  foo: string
+  arr:
+    type:
+      type: array
+      items: int
+outputs: []
diff --git a/tests/reader.scm b/tests/reader.scm
index 8ac18ec..77d6034 100644
--- a/tests/reader.scm
+++ b/tests/reader.scm
@@ -16,7 +16,8 @@
 ;;; You should have received a copy of the GNU General Public License
 ;;; along with ravanan.  If not, see <https://www.gnu.org/licenses/>.
 
-(use-modules (srfi srfi-64)
+(use-modules (srfi srfi-26)
+             (srfi srfi-64)
              (ice-9 filesystem)
              (ice-9 match)
              (web uri)
@@ -217,4 +218,17 @@
           (normalize-input '(("class" . "File")
                              ("path" . "foo")))))))))
 
+(test-equal "Read YAML inputs file with type ambiguities"
+  '(("number" . 13)
+    ("flag" . #t)
+    ("reverseflag" . #f)
+    ("foo" . "bar")
+    ("arr" . #(1 2 3)))
+  (call-with-values
+      (cut read-workflow+inputs
+           "test-data/workflow-for-inputs-with-type-ambiguities.cwl"
+           "test-data/inputs-with-type-ambiguities.yaml")
+    (lambda (workflow inputs)
+      inputs)))
+
 (test-end "reader")