Skip to content

Commit 2c61c48

Browse files
author
Peter Amstutz
committed
Merge commit 'b0701278de2bab6c830df1e07ea481dd3335b18e' into inline-expressions
2 parents c464a11 + b070127 commit 2c61c48

14 files changed

+424
-55
lines changed

cwltool/schemas/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ and send a pull request!
7878

7979
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/common-workflow-language/common-workflow-language?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8080

81+
Your CWL Community Engineer, Michael R. Crusoe, publishes a blog about his work
82+
with weekly updates at http://mrc.commonwl.org.
83+
8184
### Code of Conduct
8285

8386
The CWL Project is dedicated to providing a harassment-free experience for

cwltool/schemas/draft-3/conformance_test_draft-3.yaml

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,153 @@
290290
tool: draft-3/schemadef-wf.cwl
291291
doc: |
292292
Test SchemaDefRequirement definition used in workflow parameter
293+
294+
- job: draft-3/empty.json
295+
output: {
296+
"t1": {
297+
"bar": {
298+
"b az": 2,
299+
"b\"az": null,
300+
"b'az": true,
301+
"baz": "zab1",
302+
"buz": [
303+
"a",
304+
"b",
305+
"c"
306+
]
307+
}
308+
},
309+
"t10": true,
310+
"t11": true,
311+
"t12": null,
312+
"t13": "-zab1",
313+
"t14": "-zab1",
314+
"t15": "-zab1",
315+
"t16": "-zab1",
316+
"t17": "zab1 zab1",
317+
"t18": "zab1 zab1",
318+
"t19": "zab1 zab1",
319+
"t2": {
320+
"b az": 2,
321+
"b\"az": null,
322+
"b'az": true,
323+
"baz": "zab1",
324+
"buz": [
325+
"a",
326+
"b",
327+
"c"
328+
]
329+
},
330+
"t20": "zab1 zab1",
331+
"t21": "2 2",
332+
"t22": "true true",
333+
"t23": "true true",
334+
"t24": "null null",
335+
"t25": "b",
336+
"t26": "b b",
337+
"t3": {
338+
"b az": 2,
339+
"b\"az": null,
340+
"b'az": true,
341+
"baz": "zab1",
342+
"buz": [
343+
"a",
344+
"b",
345+
"c"
346+
]
347+
},
348+
"t4": {
349+
"b az": 2,
350+
"b\"az": null,
351+
"b'az": true,
352+
"baz": "zab1",
353+
"buz": [
354+
"a",
355+
"b",
356+
"c"
357+
]
358+
},
359+
"t5": "zab1",
360+
"t6": "zab1",
361+
"t7": "zab1",
362+
"t8": "zab1",
363+
"t9": 2
364+
}
365+
tool: draft-3/params.cwl
366+
doc: |
367+
Test parameter evaluation, no support for JS expressions
368+
369+
- job: draft-3/empty.json
370+
output: {
371+
"t1": {
372+
"bar": {
373+
"b az": 2,
374+
"b\"az": null,
375+
"b'az": true,
376+
"baz": "zab1",
377+
"buz": [
378+
"a",
379+
"b",
380+
"c"
381+
]
382+
}
383+
},
384+
"t10": true,
385+
"t11": true,
386+
"t12": null,
387+
"t13": "-zab1",
388+
"t14": "-zab1",
389+
"t15": "-zab1",
390+
"t16": "-zab1",
391+
"t17": "zab1 zab1",
392+
"t18": "zab1 zab1",
393+
"t19": "zab1 zab1",
394+
"t2": {
395+
"b az": 2,
396+
"b\"az": null,
397+
"b'az": true,
398+
"baz": "zab1",
399+
"buz": [
400+
"a",
401+
"b",
402+
"c"
403+
]
404+
},
405+
"t20": "zab1 zab1",
406+
"t21": "2 2",
407+
"t22": "true true",
408+
"t23": "true true",
409+
"t24": "null null",
410+
"t25": "b",
411+
"t26": "b b",
412+
"t3": {
413+
"b az": 2,
414+
"b\"az": null,
415+
"b'az": true,
416+
"baz": "zab1",
417+
"buz": [
418+
"a",
419+
"b",
420+
"c"
421+
]
422+
},
423+
"t4": {
424+
"b az": 2,
425+
"b\"az": null,
426+
"b'az": true,
427+
"baz": "zab1",
428+
"buz": [
429+
"a",
430+
"b",
431+
"c"
432+
]
433+
},
434+
"t5": "zab1",
435+
"t6": "zab1",
436+
"t7": "zab1",
437+
"t8": "zab1",
438+
"t9": 2
439+
}
440+
tool: draft-3/params2.cwl
441+
doc: |
442+
Test parameter evaluation, with support for JS expressions

cwltool/schemas/draft-3/cwl-avro.yml

Lines changed: 88 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,68 @@
323323
Process requirements are the primary mechanism for specifying extensions to
324324
the CWL core specification.
325325
326+
## Parameter references
327+
328+
Parameter references are denoted by the syntax `$(...)` and may be used in
329+
any field permitting the pseudo-type `Expression`, as specified by this
330+
document. Conforming implementations must support parameter
331+
references. Parameter references use the following subset of
332+
[Javascript/ECMAScript 5.1](http://www.ecma-international.org/ecma-262/5.1/) syntax:
333+
334+
symbol:: {Unicode alphanumeric}+
335+
singleq:: '[' ''' ( {character} - ''' | '\' ''' )* ''' ']'
336+
doubleq:: '[' '"' ( {character} - '"' | '\' '"' )* '"' ']'
337+
index:: '[' {decimal digit}+ ']'
338+
segment:: '.' {symbol} | {singleq} | {doubleq} | {index}
339+
parameter:: '$' '(' {symbol} {segment}* ')'
340+
341+
Use the following algorithm to resolve a parameter reference:
342+
343+
1. Match the leading symbol as key
344+
2. Look up the key in the parameter context (described below) to get the current value.
345+
It is an error if the key is not found in the parameter context.
346+
3. If there are no subsequent segments, terminate and return current value
347+
4. Else, match the next segment
348+
5. Extract the symbol, string, or index from the segment as key
349+
6. Look up the key in current value and assign as new current value. If
350+
the key is a symbol or string, the current value must be an object.
351+
If the key is an index, the current value must be an array or string.
352+
It is an error if the key does not match the required type, or the key is not found or out
353+
of range.
354+
7. Repeat steps 3-6
355+
356+
The root namspace is the parameter context. The following parameters must
357+
be provided:
358+
359+
* `inputs`: The input object to the current Process.
360+
* `self`: A context-specific value. The contextual values for 'self' are
361+
documented for specific fields elsewhere in this specification. If
362+
a contextual value of 'self' is not documented for a field, it
363+
must be 'null'.
364+
* `runtime`: An object containing configuration specific to the Process
365+
type. Values include `tmpdir`, `outdir`, and values associated with
366+
[ResourceRequirement](#resourcerequirement).
367+
Other fields under `runtime` are listed elsewhere in this document.
368+
369+
If the value of a field has no leading or trailing non-whitespace
370+
characters around a parameter reference, the effective value of the field
371+
becomes the value of the referenced parameter, preserving the return type.
372+
373+
If the value of a field has non-whitespace leading or trailing characters
374+
around an parameter reference, it is subject to string interpolation. The
375+
effective value of the field is a string containing the leading characters;
376+
followed by the string value of the parameter reference; followed by the
377+
trailing characters. The string value of the parameter reference is its
378+
textual JSON representation with the following rules:
379+
380+
* Leading and trailing quotes are stripped from strings
381+
* Objects entries are sorted by key
382+
383+
Multiple parameter references may appear in a single field. This case is
384+
must be treated as a string interpolation. After interpolating the first
385+
parameter reference, interpolation must be recursively applied to the
386+
trailing characters to yield the final string value.
387+
326388
## Expressions
327389
328390
An expression is a fragment of [Javascript/ECMAScript
@@ -334,62 +396,48 @@
334396
processes in that they are intended to modify the behavior of the workflow
335397
itself rather than perform the primary work of the workflow.
336398
337-
Expressions may be used in any field that allows expressions, as specified
338-
by this document.
399+
To declare the use of expressions, the document must include the process
400+
requirement `InlineJavascriptRequirement`. Expressions may be used in any
401+
field permitting the pseudo-type `Expression`, as specified by this
402+
document.
339403
340404
Expressions are denoted by the syntax `$(...)` or `${...}`. A code
341-
fragment wrapped in the `$(...)` syntax must be evaluated as a [ECMAScript
342-
expression](http://www.ecma-international.org/ecma-262/5.1/#sec-11). A
405+
fragment wrapped in the `$(...)` syntax must be evaluated as a
406+
[ECMAScript expression](http://www.ecma-international.org/ecma-262/5.1/#sec-11). A
343407
code fragment wrapped in the `${...}` syntax must be evaluated as a
344-
[EMACScript function
345-
body](http://www.ecma-international.org/ecma-262/5.1/#sec-13) for an
346-
anonymous, zero-argument function. Expressions must return a valid JSON
408+
[EMACScript function body](http://www.ecma-international.org/ecma-262/5.1/#sec-13)
409+
for an anonymous, zero-argument function. Expressions must return a valid JSON
347410
data type: one of null, string, number, boolean, array, object.
348411
Implementations must permit any syntatically valid Javascript and account
349-
for nesting of parenthesis or braces and the strings that may contain
412+
for nesting of parenthesis or braces and that strings that may contain
350413
parenthesis or braces when scanning for expressions.
351414
352-
If a field has no leading or trailing non-whitespace characters around an
353-
expression, the effective value of the field is the value returned by
354-
evaluating the expression, preserving the return type.
355-
356-
If a field has non-whitespace leading or trailing characters around an
357-
expression, it is subject to string interpolation. The effective value of
358-
the field is a string containing the leading characters followed by the
359-
value returned by evaluating the expression, followed by the trailing
360-
characters. The value returned by the expression is coerced to a string
361-
subject to the following rules:
362-
363-
* strings are included directly with no transformation
364-
* numbers are converted to decimal representation string
365-
* null is the string `(null)`
366-
* boolean "true" or "false" yield the strings "true" or "false"
367-
* arrays are serialized to JSON
368-
* objects are serialized to JSON
369-
370-
Multiple expressions may appear in a single field. This case is must be treated
371-
as a string interpolation.
372-
373-
Before executing the expression, the runtime must initialize the global
374-
object `inputs` containing a copy of the validated contents of the job
375-
object. The runtime must also initialize a global object `runtime`
376-
containing the values for `tmpdir`, `outdir`, and values associated with
377-
[ResourceRequirement](#resourcerequirement).
378-
379415
The runtime must include any code defined in the ["expressionLib" field of
380416
InlineJavascriptRequirement](#inlinejavascriptrequirement) prior to
381417
executing the actual expression.
382418
419+
Before executing the expression, the runtime must initialize as global
420+
variables the fields of the parameter context described above.
421+
422+
The effective value of the field after expression evaluation follows the
423+
same rules as parameter references discussed above. Multiple expressions
424+
may appear in a single field.
425+
383426
Expressions must be evaluated in an isolated context (a "sandbox") which
384427
permits no side effects to leak outside the context. Expressions also must
385-
be evaluated in [Javascript strict
386-
mode](http://www.ecma-international.org/ecma-262/5.1/#sec-4.2.2).
428+
be evaluated in [Javascript strict mode](http://www.ecma-international.org/ecma-262/5.1/#sec-4.2.2).
429+
430+
The order in which expressions are evaluated is undefined except where
431+
otherwise noted in this document.
387432
388-
The order in which expressions are evaluated is undefined.
433+
An implementation may choose to implement parameter references by
434+
evalutating as a Javascript expression. The results of evaluating
435+
parameter references must be identical whether implemented by Javascript
436+
evaluation or some other means.
389437
390438
Implementations may apply other limits, such as process isolation, timeouts,
391439
and operating system containers/jails to minimize the security risks associated
392-
with running untrusted code embedded in a tool description document.
440+
with running untrusted code embedded in a CWL document.
393441
394442
## Workflow graph
395443
@@ -719,15 +767,6 @@
719767
object.
720768
721769
722-
- name: StandardExpressionEngine
723-
type: enum
724-
doc: "Symbols for default CWL expression engines that may be used in the `engine` field."
725-
docParent: "#Expression"
726-
symbols:
727-
- "cwl:JsonPointer"
728-
- "cwl:JavascriptEngine"
729-
730-
731770
- type: enum
732771
name: Expression
733772
docAfter: "#ExpressionTool"
@@ -736,6 +775,7 @@
736775
symbols:
737776
- cwl:ExpressionPlaceholder
738777

778+
739779
- name: Binding
740780
type: record
741781
docParent: "#Parameter"

cwltool/schemas/draft-3/draft-3/bwa-mem-job.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
],
2424
"minimum_seed_length": 3,
2525
"allocatedResources": {
26-
"cpu": 4,
26+
"cores": 4,
2727
"mem": 5000
2828
}
2929
}

cwltool/schemas/draft-3/draft-3/cat1-tool.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: "Print the contents of a file to stdout using 'cat' running in a do
55
hints:
66
- class: DockerRequirement
77
dockerPull: debian:wheezy
8-
inputs: [
8+
inputs:
99
- id: file1
1010
type: File
1111
inputBinding: {position: 1}

cwltool/schemas/draft-3/draft-3/count-lines2-wf.cwl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env cwl-runner
22
class: Workflow
33
cwlVersion: "cwl:draft-3.dev2"
4+
requirements:
5+
- class: InlineJavascriptRequirement
46

57
inputs:
68
- { id: file1, type: File }
@@ -31,4 +33,9 @@ steps:
3133
- { id: parseInt_output }
3234
run:
3335
class: ExpressionTool
34-
expression: ${return {'parseInt_output': parseInt($job.parseInt_file1.contents)};}
36+
inputs:
37+
- { id: parseInt_file1, type: File, inputBinding: { loadContents: true } }
38+
outputs:
39+
- { id: parseInt_output, type: int }
40+
expression: >
41+
${return {'parseInt_output': parseInt(inputs.parseInt_file1.contents)};}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class: CommandLineTool
2+
cwlVersion: cwl:draft-3.dev2
3+
inputs:
4+
- id: bar
5+
type: Any
6+
default: {
7+
"baz": "zab1",
8+
"b az": 2,
9+
"b'az": true,
10+
'b"az': null,
11+
"buz": ['a', 'b', 'c']
12+
}
13+
14+
outputs: {"@import": params_inc.yml}
15+
16+
baseCommand: "true"

0 commit comments

Comments
 (0)