Skip to content

Commit

Permalink
feature: emit nullable path in tuples
Browse files Browse the repository at this point in the history
use nullable instead of allowNull

Signed-off-by: Jorge Aguilera <jorge.aguilera@seqera.io>
  • Loading branch information
jorgeaguileraseqera committed Jun 22, 2022
1 parent 67a91bd commit ae6f219
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions docs/process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -632,11 +632,11 @@ section::


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

process foo {
input:
path x, stageAs: 'data.txt', allowNull:true from '/some/data/file.txt'
path x, stageAs: 'data.txt', nullable:true from '/some/data/file.txt'

"""
[[ -f data.txt ]] your_command --in data.txt || other_command
Expand Down Expand Up @@ -1082,7 +1082,7 @@ followLinks When ``true`` target files are return in place of any matching s
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)
maxDepth Maximum number of directory levels to visit (default: `no limit`)
includeInputs When ``true`` any input files matching an output file glob pattern are included.
allowNull When ``true`` emit a NullablePath instead to abort the process
nullable When ``true`` emit a NullablePath instead to abort the process
============== =====================

.. warning::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ class TaskProcessor {
def path = param.glob ? splitter.strip(filePattern) : filePattern
def file = workDir.resolve(path)
def exists = param.followLinks ? file.exists() : file.exists(LinkOption.NOFOLLOW_LINKS)
if( !exists && param.allowNull){
if( !exists && param.nullable){
file = new NullablePath(path)
exists = true
}
Expand Down Expand Up @@ -1691,9 +1691,9 @@ class TaskProcessor {
return new FileHolder(source, result)
}

protected Path normalizeToPath( obj, boolean allowNullable=false ) {
protected Path normalizeToPath( obj, boolean nullable=false ) {

if( obj instanceof NullablePath && !allowNullable)
if( obj instanceof NullablePath && !nullable)
throw new ProcessUnrecoverableException("Path value cannot be null")

if( obj instanceof Path )
Expand All @@ -1718,7 +1718,7 @@ class TaskProcessor {
}

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

Collection allItems = obj instanceof Collection ? obj : [obj]
def len = allItems.size()
Expand All @@ -1728,7 +1728,7 @@ class TaskProcessor {
for( def item : allItems ) {

if( item instanceof Path || coerceToPath ) {
def path = normalizeToPath(item, allowNullable)
def path = normalizeToPath(item, nullable)
def target = executor.isForeignFile(path) ? batch.addToForeign(path) : path
def holder = new FileHolder(target)
files << holder
Expand Down Expand Up @@ -1942,7 +1942,7 @@ class TaskProcessor {
final param = entry.getKey()
final val = entry.getValue()
final fileParam = param as FileInParam
final normalized = normalizeInputToFiles(val, count, fileParam.isPathQualifier(), batch, fileParam.allowNull)
final normalized = normalizeInputToFiles(val, count, fileParam.isPathQualifier(), batch, fileParam.nullable)
final resolved = expandWildcards( fileParam.getFilePattern(ctx), normalized )
ctx.put( param.name, singleItemOrList(resolved, task.type) )
count += resolved.size()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FileInParam extends BaseInParam implements PathQualifier {

private boolean pathQualifier

private boolean allowNull
private boolean nullable

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

Expand Down Expand Up @@ -156,12 +156,12 @@ class FileInParam extends BaseInParam implements PathQualifier {
return this
}

FileInParam setAllowNull(boolean value) {
this.allowNull = value
FileInParam setNullable(boolean value) {
this.nullable = value
return this
}

boolean isAllowNull() {
return allowNull
boolean isNullable() {
return nullable
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class FileOutParam extends BaseOutParam implements OutParam, OptionalParam, Path
/**
* When true, if file doesn't exist, emit a Nullable instead an exception
*/
boolean allowNull = false
boolean nullable = false

boolean glob = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import test.MockScriptRunner
@IgnoreIf({System.getenv('NXF_INPUTNULLABLE')})
class InputNullablePathTest extends Dsl2Spec {

def 'should fails if allowNull is allowed as output but expected as input'() {
def 'should fails if nullable is allowed as output but expected as input'() {
given:
def session = new Session( executor: 'nope' ) {
@Override
Expand All @@ -34,7 +34,7 @@ class InputNullablePathTest extends Dsl2Spec {
input:
val id
output:
path("output.txt", allowNull:true)
path("output.txt", nullable:true)
exec:
println id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import test.Dsl2Spec
@IgnoreIf({System.getenv('NXF_INPUTNULLABLE')})
class OutputNullablePathTest extends Dsl2Spec {

def 'should fails if allowNull output is not set'() {
def 'should fails if nullable output is not set'() {
given:
def error = false
def session = new Session( executor: 'nope' ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ class ParamsOutTest extends Specification {
glob: false,
optional: false,
includeInputs: false,
allowNull: true
nullable: true
path y,
maxDepth:5,
Expand Down Expand Up @@ -1182,7 +1182,7 @@ class ParamsOutTest extends Specification {
!out0.getGlob()
!out0.getOptional()
!out0.getIncludeInputs()
out0.isAllowNull()
out0.isNullable()

and:
out1.getMaxDepth() == 5
Expand All @@ -1193,7 +1193,7 @@ class ParamsOutTest extends Specification {
out1.getGlob()
out1.getOptional()
out1.getIncludeInputs()
!out1.isAllowNull()
!out1.isNullable()
}

def 'should set file options' () {
Expand Down
2 changes: 1 addition & 1 deletion tests/input-nullablepath-fails.nf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ process test_process1 {
input:
val id
output:
path("output.txt", allowNull:true)
path("output.txt", nullable:true)
exec:
println id
}
Expand Down

0 comments on commit ae6f219

Please sign in to comment.