Skip to content

Commit 064be75

Browse files
mr-cThomasHickman
andcommitted
Allow $imports in type fields
Brings in rabix/sbpack#67 + the packing tests that we didn't originally include when we brought in sbpack to cwl-utils Co-authored-by: Thomas Hickman <[email protected]>
1 parent 4e8edbf commit 064be75

20 files changed

+479
-0
lines changed

MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ include testdata/*.yaml
1313
include testdata/*.input
1414
include testdata/*.ttl
1515
include testdata/*.owl
16+
include testdata/*.js
17+
include testdata/remote-cwl/*.cwl
18+
include testdata/workflows/*.cwl
19+
include testdata/workflows/*.yaml
20+
include testdata/types/*.yml
1621
include testdata/checker_wf/*.cwl
1722
include cwl_utils/py.typed
1823
include docs/conf.py docs/Makefile docs/_static/favicon.ico docs/requirements.txt

cwl_utils/schemadef.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright (c) 2023 Genomics plc
23
# Copyright (c) 2021 Michael R. Crusoe
34
# Copyright (c) 2020 Seven Bridges
45
# See https://github.com/rabix/sbpack/blob/b8404a0859ffcbe1edae6d8f934e51847b003320/LICENSE
@@ -191,6 +192,12 @@ def _inline_type(
191192
return [_inline_type(_v, base_url, user_defined_types) for _v in v]
192193

193194
elif isinstance(v, dict):
195+
if v.get("$import") is not None:
196+
imported_type, import_base_url = utils.load_linked_file(
197+
base_url, v["$import"], is_import=True
198+
)
199+
return _inline_type(imported_type, import_base_url, user_defined_types)
200+
194201
_type = v.get("type")
195202
if _type is None:
196203
raise errors.MissingTypeName(

testdata/lib.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var foo = function(x) {
2+
return 2 * x
3+
}
4+
5+
var bar = function(n, x) {
6+
return `{n} engineers walk into a {x}`
7+
}

testdata/remote-cwl/tool1.cwl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# We have this tool to test both local and remote packing
2+
3+
class: CommandLineTool
4+
cwlVersion: v1.0
5+
inputs:
6+
in1:
7+
type: string
8+
inputBinding:
9+
position: 1
10+
valueFrom: A_$(inputs.in1)_B_${return inputs.in1}_C_$(inputs.in1)
11+
baseCommand: echo
12+
arguments:
13+
- valueFrom: $(runtime)
14+
outputs:
15+
out1:
16+
type: string
17+
outputBinding:
18+
glob: out.txt
19+
loadContents: true
20+
outputEval: $(self)_D_$(runtime)
21+
22+
stdout: out.txt
23+
requirements:
24+
InlineJavascriptRequirement:
25+
expressionLib:
26+
- $include: ../lib.js

testdata/remote-cwl/tool2.cwl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# We have this tool to test both local and remote packing
2+
3+
class: CommandLineTool
4+
cwlVersion: v1.0
5+
inputs:
6+
in1:
7+
type: ../types/testtypes.yml#my_boolean_array
8+
inputBinding:
9+
position: 1
10+
valueFrom: A_$(inputs.in1)_B_${return inputs.in1}_C_$(inputs.in1)
11+
baseCommand: echo
12+
arguments:
13+
- valueFrom: $(runtime)
14+
outputs:
15+
out1:
16+
type: string
17+
outputBinding:
18+
glob: out.txt
19+
loadContents: true
20+
outputEval: $(self)_D_$(runtime)
21+
22+
stdout: out.txt
23+
requirements:
24+
SchemaDefRequirement:
25+
types:
26+
- $import: ../types/testtypes.yml

testdata/remote-cwl/wf1.cwl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class: Workflow
2+
cwlVersion: v1.0
3+
inputs:
4+
- id: in1
5+
type: ../types/testtypes.yml#my_boolean_array
6+
7+
steps:
8+
s1:
9+
run: ./tool2.cwl
10+
in:
11+
in1: "#in1" # This should be normalized out
12+
out: [out1]
13+
s2:
14+
run: tool1.cwl
15+
in:
16+
in1: s1/out1
17+
out: [out1]
18+
19+
outputs:
20+
- id: out1
21+
type: string
22+
outputSource: "#s2/out1"
23+
24+
requirements:
25+
SchemaDefRequirement:
26+
types:
27+
- $import: ../types/testtypes.yml

testdata/types/array.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Contains arrays and intra-file type reference
2+
3+
# class: SchemaDefRequirement
4+
# types: ...
5+
# This form does not work with cwltool, even though it can be found here
6+
# https://github.com/NCI-GDC/gdc-dnaseq-cwl/blob/master/tools/readgroup_path.yml
7+
# Notably, that .yml file is never used, so likely they tried it, failed and
8+
# forgot to take it out
9+
10+
11+
- name: sample_meta2 #duplicate names are not fine across files
12+
type: record
13+
fields:
14+
- name: prop
15+
type: string
16+
17+
- name: study_meta
18+
type: array
19+
items: sample_meta2
20+
21+
# Apparently can't declare an array inside an array?
22+
# - name: study_meta_too
23+
# type: array
24+
# items: [string, sample_meta2, study_meta]
25+
26+
- name: study_meta_too
27+
type: record
28+
fields:
29+
meta1: sample_meta2
30+
meta2: study_meta

testdata/types/recursive.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Contains records and intra-file type reference
2+
# You can't have an enum in a user type
3+
4+
- name: sample_meta
5+
type: record
6+
fields:
7+
- name: sample
8+
type: ["null", string]
9+
- name: species
10+
type: string
11+
12+
- name: file_with_sample_meta
13+
type: record
14+
fields:
15+
- name: file
16+
type: File
17+
- name: meta
18+
type: sample_meta
19+
20+
- name: info_with_sample_meta
21+
type: record
22+
fields:
23+
comment:
24+
type: string
25+
meta:
26+
type: sample_meta

testdata/types/singletype.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# You can not use the dictionary format shown in
2+
# singletype2.yml. It has to be this
3+
4+
name: simple_record
5+
type: record
6+
fields:
7+
prop: string

testdata/types/singletype2.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# You can not use this dictionary format
2+
3+
simple_record2:
4+
type: record
5+
fields:
6+
prop: string

0 commit comments

Comments
 (0)