Skip to content

Commit b121fac

Browse files
feature: emit nullable path in tuples
use nullable instead of allowNull Signed-off-by: Jorge Aguilera <jorge.aguilera@seqera.io>
1 parent 4de7cf5 commit b121fac

8 files changed

Lines changed: 22 additions & 22 deletions

File tree

docs/process.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,11 @@ section::
632632

633633

634634
In the case an input `path` doesn't exist, the process will be aborted. If you want the process will be executed
635-
independently if the file exists or not, you can set the attribute `allowNull` as true:
635+
independently if the file exists or not, you can set the attribute `nullable` as true:
636636

637637
process foo {
638638
input:
639-
path x, stageAs: 'data.txt', allowNull:true from '/some/data/file.txt'
639+
path x, stageAs: 'data.txt', nullable:true from '/some/data/file.txt'
640640

641641
"""
642642
[[ -f data.txt ]] your_command --in data.txt || other_command
@@ -1082,7 +1082,7 @@ followLinks When ``true`` target files are return in place of any matching s
10821082
type Type of paths returned, either ``file``, ``dir`` or ``any`` (default: ``any``, or ``file`` if the specified file name pattern contains a `**` - double star - symbol)
10831083
maxDepth Maximum number of directory levels to visit (default: `no limit`)
10841084
includeInputs When ``true`` any input files matching an output file glob pattern are included.
1085-
allowNull When ``true`` emit a NullablePath instead to abort the process
1085+
nullable When ``true`` emit a NullablePath instead to abort the process
10861086
============== =====================
10871087

10881088
.. warning::

modules/nextflow/src/main/groovy/nextflow/processor/TaskProcessor.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ class TaskProcessor {
15051505
def path = param.glob ? splitter.strip(filePattern) : filePattern
15061506
def file = workDir.resolve(path)
15071507
def exists = param.followLinks ? file.exists() : file.exists(LinkOption.NOFOLLOW_LINKS)
1508-
if( !exists && param.allowNull){
1508+
if( !exists && param.nullable){
15091509
file = new NullablePath(path)
15101510
exists = true
15111511
}
@@ -1695,9 +1695,9 @@ class TaskProcessor {
16951695
return new FileHolder(source, result)
16961696
}
16971697

1698-
protected Path normalizeToPath( obj, boolean allowNullable=false ) {
1698+
protected Path normalizeToPath( obj, boolean nullable=false ) {
16991699

1700-
if( obj instanceof NullablePath && !allowNullable)
1700+
if( obj instanceof NullablePath && !nullable)
17011701
throw new ProcessUnrecoverableException("Path value cannot be null")
17021702

17031703
if( obj instanceof Path )
@@ -1722,7 +1722,7 @@ class TaskProcessor {
17221722
}
17231723

17241724
protected List<FileHolder> normalizeInputToFiles( Object obj, int count, boolean coerceToPath, FilePorter.Batch batch,
1725-
boolean allowNullable=false ) {
1725+
boolean nullable=false ) {
17261726

17271727
Collection allItems = obj instanceof Collection ? obj : [obj]
17281728
def len = allItems.size()
@@ -1732,7 +1732,7 @@ class TaskProcessor {
17321732
for( def item : allItems ) {
17331733

17341734
if( item instanceof Path || coerceToPath ) {
1735-
def path = normalizeToPath(item, allowNullable)
1735+
def path = normalizeToPath(item, nullable)
17361736
def target = executor.isForeignFile(path) ? batch.addToForeign(path) : path
17371737
def holder = new FileHolder(target)
17381738
files << holder
@@ -1946,7 +1946,7 @@ class TaskProcessor {
19461946
final param = entry.getKey()
19471947
final val = entry.getValue()
19481948
final fileParam = param as FileInParam
1949-
final normalized = normalizeInputToFiles(val, count, fileParam.isPathQualifier(), batch, fileParam.allowNull)
1949+
final normalized = normalizeInputToFiles(val, count, fileParam.isPathQualifier(), batch, fileParam.nullable)
19501950
final resolved = expandWildcards( fileParam.getFilePattern(ctx), normalized )
19511951
ctx.put( param.name, singleItemOrList(resolved, task.type) )
19521952
count += resolved.size()

modules/nextflow/src/main/groovy/nextflow/script/params/FileInParam.groovy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class FileInParam extends BaseInParam implements PathQualifier {
3535

3636
private boolean pathQualifier
3737

38-
private boolean allowNull
38+
private boolean nullable
3939

4040
@Override String getTypeName() { pathQualifier ? 'path' : 'file' }
4141

@@ -156,12 +156,12 @@ class FileInParam extends BaseInParam implements PathQualifier {
156156
return this
157157
}
158158

159-
FileInParam setAllowNull(boolean value) {
160-
this.allowNull = value
159+
FileInParam setNullable(boolean value) {
160+
this.nullable = value
161161
return this
162162
}
163163

164-
boolean isAllowNull() {
165-
return allowNull
164+
boolean isNullable() {
165+
return nullable
166166
}
167167
}

modules/nextflow/src/main/groovy/nextflow/script/params/FileOutParam.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class FileOutParam extends BaseOutParam implements OutParam, OptionalParam, Path
8484
/**
8585
* When true, if file doesn't exist, emit a Nullable instead an exception
8686
*/
87-
boolean allowNull = false
87+
boolean nullable = false
8888

8989
boolean glob = true
9090

modules/nextflow/src/test/groovy/nextflow/script/InputNullablePathTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import test.MockScriptRunner
1717
@IgnoreIf({System.getenv('NXF_INPUTNULLABLE')})
1818
class InputNullablePathTest extends Dsl2Spec {
1919

20-
def 'should fails if allowNull is allowed as output but expected as input'() {
20+
def 'should fails if nullable is allowed as output but expected as input'() {
2121
given:
2222
def session = new Session( executor: 'nope' ) {
2323
@Override
@@ -34,7 +34,7 @@ class InputNullablePathTest extends Dsl2Spec {
3434
input:
3535
val id
3636
output:
37-
path("output.txt", allowNull:true)
37+
path("output.txt", nullable:true)
3838
exec:
3939
println id
4040
}

modules/nextflow/src/test/groovy/nextflow/script/OutputNullablePathTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import test.Dsl2Spec
1212
@IgnoreIf({System.getenv('NXF_INPUTNULLABLE')})
1313
class OutputNullablePathTest extends Dsl2Spec {
1414

15-
def 'should fails if allowNull output is not set'() {
15+
def 'should fails if nullable output is not set'() {
1616
given:
1717
def error = false
1818
def session = new Session( executor: 'nope' ) {

modules/nextflow/src/test/groovy/nextflow/script/params/ParamsOutTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ class ParamsOutTest extends Specification {
11521152
glob: false,
11531153
optional: false,
11541154
includeInputs: false,
1155-
allowNull: true
1155+
nullable: true
11561156
11571157
path y,
11581158
maxDepth:5,
@@ -1182,7 +1182,7 @@ class ParamsOutTest extends Specification {
11821182
!out0.getGlob()
11831183
!out0.getOptional()
11841184
!out0.getIncludeInputs()
1185-
out0.isAllowNull()
1185+
out0.isNullable()
11861186

11871187
and:
11881188
out1.getMaxDepth() == 5
@@ -1193,7 +1193,7 @@ class ParamsOutTest extends Specification {
11931193
out1.getGlob()
11941194
out1.getOptional()
11951195
out1.getIncludeInputs()
1196-
!out1.isAllowNull()
1196+
!out1.isNullable()
11971197
}
11981198

11991199
def 'should set file options' () {

tests/input-nullablepath-fails.nf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ process test_process1 {
33
input:
44
val id
55
output:
6-
path("output.txt", allowNull:true)
6+
path("output.txt", nullable:true)
77
exec:
88
println id
99
}

0 commit comments

Comments
 (0)