Skip to content

Commit 4e9189a

Browse files
committed
Make DSL2 default syntax
1 parent 814a260 commit 4e9189a

File tree

106 files changed

+221
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+221
-176
lines changed

docs/basic.rst

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,18 @@ and ultimately the pipeline execution flow itself, is implicitly defined by thes
2828

2929
A Nextflow script looks like this::
3030

31+
// Declare syntax version
32+
nextflow.enable.dsl=2
3133
// Script parameters
3234
params.query = "/some/data/sample.fa"
3335
params.db = "/some/path/pdb"
3436

35-
db = file(params.db)
36-
query_ch = Channel.fromPath(params.query)
37-
3837
process blastSearch {
39-
input:
40-
file query from query_ch
41-
42-
output:
43-
file "top_hits.txt" into top_hits_ch
38+
input:
39+
path query
40+
path db
41+
output:
42+
path "top_hits.txt"
4443

4544
"""
4645
blastp -db $db -query $query -outfmt 6 > blast_result
@@ -49,18 +48,21 @@ A Nextflow script looks like this::
4948
}
5049

5150
process extractTopHits {
52-
input:
53-
file top_hits from top_hits_ch
51+
input:
52+
path top_hits
5453

55-
output:
56-
file "sequences.txt" into sequences_ch
54+
output:
55+
path "sequences.txt"
5756

5857
"""
5958
blastdbcmd -db $db -entry_batch $top_hits > sequences.txt
6059
"""
6160
}
6261

63-
62+
workflow {
63+
def query_ch = Channel.fromPath(params.query)
64+
blastSearch(query_ch, params.db) | extractTopHits | view
65+
}
6466

6567
The above example defines two processes. Their execution order is not determined by the fact that the ``blastSearch``
6668
process comes before ``extractTopHits`` in the script (it could also be written the other way around).

docs/config.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ NXF_ANSI_SUMMARY Enables/disables ANSI completion summary: `true|
965965
NXF_SCM_FILE Defines the path location of the SCM config file (requires version ``20.10.0`` or later).
966966
NXF_PARAMS_FILE Defines the path location of the pipeline parameters file (requires version ``20.10.0`` or later).
967967
NXF_DISABLE_JOBS_CANCELLATION Disables the cancellation of child jobs on workflow execution termination (requires ``21.12.0-edge`` or later).
968+
NXF_DEFAULT_DSL Defines the DSL version version that should be used in not specified otherwise in the script of config file (default: ``2``, requires version ``22.03.0-edge`` or later)
968969
JAVA_HOME Defines the path location of the Java VM installation used to run Nextflow.
969970
JAVA_CMD Defines the path location of the Java binary command used to launch Nextflow.
970971
HTTP_PROXY Defines the HTTP proxy server. As of version ``21.06.0-edge``, proxy authentication is supported providing the credentials in the proxy URL e.g. ``http://user:[email protected]:port``.

docs/dsl2.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ your workflow script::
1212

1313
nextflow.enable.dsl=2
1414

15+
.. tip::
16+
As of version ``22.03.0-edge`` Nextflow defaults to DSL 2 if no version version is specified explicitly.
17+
You can restore the previous behavior setting in into your environment the following variable::
18+
19+
export NXF_DEFAULT_DSL=1
20+
21+
22+
.. note::
23+
As of version ``22.03.0-edge`` the DSL version specification (either 1 or 2) can also be specified in
24+
the Nextflow configuration file using the same notation shown above.
1525

1626
Function
1727
========

docs/getstarted.rst

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,34 +87,33 @@ Your first script
8787
Copy the following example into your favourite text editor and save it to a file named ``tutorial.nf`` ::
8888

8989
#!/usr/bin/env nextflow
90+
nextflow.enable.dsl=2
9091

9192
params.str = 'Hello world!'
9293

9394
process splitLetters {
95+
output:
96+
path 'chunk_*'
9497

95-
output:
96-
file 'chunk_*' into letters
97-
98-
"""
98+
"""
9999
printf '${params.str}' | split -b 6 - chunk_
100-
"""
100+
"""
101101
}
102102

103-
104103
process convertToUpper {
104+
input:
105+
file x
106+
output:
107+
stdout
105108

106-
input:
107-
file x from letters.flatten()
108-
109-
output:
110-
stdout result
111-
112-
"""
109+
"""
113110
cat $x | tr '[a-z]' '[A-Z]'
114-
"""
111+
"""
115112
}
116113

117-
result.view { it.trim() }
114+
workflow {
115+
splitLetters | flatten | convertToUpper | view { it.trim() }
116+
}
118117

119118

120119
This script defines two processes. The first splits a string into 6-character chunks, writing each one to a file with the prefix ``chunk_``,

modules/nextflow/src/main/groovy/nextflow/NextflowMeta.groovy

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import static nextflow.extension.Bolts.DATETIME_FORMAT
1919
@EqualsAndHashCode
2020
class NextflowMeta {
2121

22-
private static final Pattern DSL2_DECLARATION = ~/(?m)^\s*(nextflow\.(preview|enable)\.dsl\s*=\s*2)\s*;?\s*$/
22+
private static final Pattern DSL_DECLARATION = ~/(?m)^\s*(nextflow\.(preview|enable)\.dsl\s*=\s*(\d))\s*;?\s*$/
2323

2424
private static boolean ignoreWarnDsl2 = System.getenv('NXF_IGNORE_WARN_DSL2')=='true'
2525

@@ -28,6 +28,7 @@ class NextflowMeta {
2828
abstract boolean strict
2929
}
3030

31+
@Deprecated
3132
@Slf4j
3233
static class Preview implements Flags {
3334
volatile float dsl
@@ -62,6 +63,7 @@ class NextflowMeta {
6263
*/
6364
final String timestamp
6465

66+
@Deprecated
6567
final Preview preview = new Preview()
6668

6769
final Features enable = new Features()
@@ -107,38 +109,41 @@ class NextflowMeta {
107109
}
108110

109111
boolean isDsl2() {
110-
preview.dsl == 2 || enable.dsl == 2
112+
enable.dsl == 2
111113
}
112114

113115
boolean isDsl2Final() {
114116
enable.dsl == 2
115117
}
116118

117-
void enableDsl2(boolean preview=false) {
118-
if( preview )
119-
this.preview.dsl = 2
120-
else
121-
this.enable.dsl = 2
119+
void enableDsl2() {
120+
this.enable.dsl = 2
122121
}
123122

124123
void disableDsl2() {
125124
enable.dsl = 1
126-
preview.dsl = 1
127125
}
128126

129127
boolean isStrictModeEnabled() {
130-
preview.strict || enable.strict
128+
return enable.strict
131129
}
132130

133131
void checkDsl2Mode(String script) {
134-
final matcher = DSL2_DECLARATION.matcher(script)
132+
final matcher = DSL_DECLARATION.matcher(script)
135133
final mode = matcher.find() ? matcher.group(2) : null
136134
if( !mode )
137135
return
138-
if( mode == 'enable' )
139-
enableDsl2()
136+
final ver = matcher.group(3)
137+
if( mode == 'enable' ) {
138+
if( ver=='2' )
139+
enableDsl2()
140+
else if( ver=='1' )
141+
disableDsl2()
142+
else
143+
throw new IllegalArgumentException("Unknown nextflow DSL version: ${ver}")
144+
}
140145
else if( mode == 'preview' )
141-
enableDsl2(true)
146+
throw new IllegalArgumentException("Preview nextflow mode 'preview' is not supported anymore -- Please use `nextflow.enable.dsl=2` instead")
142147
else
143148
throw new IllegalArgumentException("Unknown nextflow mode=${matcher.group(1)}")
144149
}

modules/nextflow/src/main/groovy/nextflow/cli/CmdRun.groovy

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import nextflow.Const
3434
import nextflow.NF
3535
import nextflow.NextflowMeta
3636
import nextflow.config.ConfigBuilder
37+
import nextflow.config.ConfigMap
3738
import nextflow.exception.AbortOperationException
3839
import nextflow.file.FileHelper
3940
import nextflow.plugin.Plugins
@@ -221,6 +222,9 @@ class CmdRun extends CmdBase implements HubOptions {
221222
@Parameter(names=['-entry'], description = 'Entry workflow name to be executed', arity = 1)
222223
String entryName
223224

225+
@Parameter(names=['-dsl1'], description = 'Execute the workflow using DSL1 syntax')
226+
boolean dsl1
227+
224228
@Parameter(names=['-dsl2'], description = 'Execute the workflow using DSL2 syntax')
225229
boolean dsl2
226230

@@ -269,9 +273,9 @@ class CmdRun extends CmdBase implements HubOptions {
269273
if( offline && latest )
270274
throw new AbortOperationException("Command line options `-latest` and `-offline` cannot be specified at the same time")
271275

272-
if( dsl2 )
273-
NextflowMeta.instance.enableDsl2()
274-
276+
if( dsl1 && dsl2 )
277+
throw new AbortOperationException("Command line options `-dsl1` and `-dsl2` cannot be specified at the same time")
278+
275279
checkRunName()
276280

277281
log.info "N E X T F L O W ~ version ${Const.APP_VER}"
@@ -286,6 +290,9 @@ class CmdRun extends CmdBase implements HubOptions {
286290
.setBaseDir(scriptFile.parent)
287291
final config = builder .build()
288292

293+
// check DSL syntax in the config
294+
launchInfo(config, scriptFile)
295+
289296
// -- load plugins
290297
final cfg = plugins ? [plugins: plugins.tokenize(',')] : config
291298
Plugins.setup( cfg )
@@ -327,6 +334,31 @@ class CmdRun extends CmdBase implements HubOptions {
327334
runner.execute(scriptArgs, this.entryName)
328335
}
329336

337+
protected void launchInfo(ConfigMap config, ScriptFile scriptFile) {
338+
// -- try determine DSL version from config file
339+
final DSL2 = '2'
340+
final DSL1 = '1'
341+
final defaultDsl = env.get('NXF_DEFAULT_DSL') ?: DSL2
342+
final dsl = config.navigate('nextflow.enable.dsl', defaultDsl) as String
343+
if( dsl=='2' )
344+
NextflowMeta.instance.enableDsl2()
345+
else if( dsl=='1' )
346+
NextflowMeta.instance.disableDsl2()
347+
else
348+
throw new AbortOperationException("Invalid Nextflow DSL value: $dsl")
349+
350+
// -- script can still override the DSL version
351+
NextflowMeta.instance.checkDsl2Mode(scriptFile.main.text)
352+
353+
// -- show launch info
354+
final ver = NF.dsl2 ? DSL2 : DSL1
355+
if( scriptFile.repository )
356+
log.info "Launching `$scriptFile.repository` [$runName] DSL${ver} - revision: ${scriptFile.revisionInfo}"
357+
else
358+
log.info "Launching `$scriptFile.source` [$runName] DSL${ver} - revision: ${scriptFile.getScriptId()?.substring(0,10)}"
359+
360+
}
361+
330362
protected void checkRunName() {
331363
if( runName == 'last' )
332364
throw new AbortOperationException("Not a valid run name: `last`")
@@ -405,9 +437,7 @@ class CmdRun extends CmdBase implements HubOptions {
405437
if( script.exists() ) {
406438
if( revision )
407439
throw new AbortOperationException("Revision option cannot be used running a script")
408-
def result = new ScriptFile(script)
409-
log.info "Launching `$script` [$runName] - revision: ${result.getScriptId()?.substring(0,10)}"
410-
return result
440+
return new ScriptFile(script)
411441
}
412442

413443
/*
@@ -431,7 +461,6 @@ class CmdRun extends CmdBase implements HubOptions {
431461
manager.checkout(revision)
432462
manager.updateModules()
433463
final scriptFile = manager.getScriptFile(mainScript)
434-
log.info "Launching `$repo` [$runName] - revision: ${scriptFile.revisionInfo}"
435464
if( checkForUpdate && !offline )
436465
manager.checkRemoteStatus(scriptFile.revisionInfo)
437466
// return the script file

modules/nextflow/src/main/groovy/nextflow/config/ConfigBuilder.groovy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,16 @@ class ConfigBuilder {
665665
config.tower.endpoint = cmdRun.withTower
666666
}
667667

668+
// -- nextflow setting
669+
if( cmdRun.dsl1 || cmdRun.dsl2 ) {
670+
if( config.nextflow !instanceof Map )
671+
config.nextflow = [:]
672+
if( cmdRun.dsl1 )
673+
config.nextflow.enable.dsl = 1
674+
if( cmdRun.dsl2 )
675+
config.nextflow.enable.dsl = 2
676+
}
677+
668678
// -- add the command line parameters to the 'taskConfig' object
669679
if( cmdRun.hasParams() )
670680
config.params = mergeMaps( (Map)config.params, cmdRun.parsedParams(configVars()), NF.strictMode )

modules/nextflow/src/main/groovy/nextflow/script/ScriptFile.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ import nextflow.util.CacheHelper
3333
@ToString(includeNames = true)
3434
class ScriptFile {
3535

36+
/**
37+
* Pipeline source file as specified by the user (it may be a relative path
38+
*/
39+
Path source
40+
3641
/**
3742
* Pipeline main script file
3843
*/
@@ -86,6 +91,7 @@ class ScriptFile {
8691

8792
ScriptFile( Path file ) {
8893
assert file
94+
source = file
8995
main = file.complete()
9096
localPath = main.parent
9197
}

modules/nextflow/src/main/groovy/nextflow/script/ScriptParser.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ class ScriptParser {
168168
ScriptParser parse(String scriptText, GroovyShell interpreter) {
169169
final String clazzName = computeClassName(scriptText)
170170
try {
171-
NextflowMeta.instance.checkDsl2Mode(scriptText)
172171
script = (BaseScript)interpreter.parse(scriptText, clazzName)
173172
final meta = ScriptMeta.get(script)
174173
meta.setScriptPath(scriptPath)

modules/nextflow/src/test/groovy/nextflow/NextflowMetaTest.groovy

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,13 @@ class NextflowMetaTest extends Specification {
5050
where:
5151
DSL2 | FINAL | SCRIPT
5252
false | false | 'hello'
53-
false | false | 'nextflow.preview.dsl=1'
54-
and:
55-
true | false | 'nextflow.preview.dsl=2'
56-
true | false | 'nextflow.preview.dsl = 2'
57-
true | false | 'nextflow.preview.dsl = 2;'
58-
true | false | '#!/bin/env nextflow\nnextflow.preview.dsl=2\nprintln foo'
53+
false | false | 'nextflow.enable.dsl=1'
5954
and:
6055
true | true | 'nextflow.enable.dsl=2'
6156
true | true | 'nextflow.enable.dsl = 2'
6257
true | true | 'nextflow.enable.dsl = 2;'
6358
true | true | '#!/bin/env nextflow\nnextflow.enable.dsl=2\nprintln foo'
59+
and:
60+
false | false | 'nextflow.enable.dsl = 1'
6461
}
6562
}

0 commit comments

Comments
 (0)