Skip to content

Commit

Permalink
Add enabled property to output dsl (#5008) [ci fast]
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso authored May 19, 2024
1 parent eb97831 commit 284415b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class PublishOp {
}

protected void onComplete(nope) {
if( indexOpts && indexRecords.size() > 0 ) {
if( indexOpts && indexRecords.size() > 0 && publisher.enabled ) {
log.trace "Saving records to index file: ${indexRecords}"
new CsvWriter(header: indexOpts.header, sep: indexOpts.sep).apply(indexRecords, indexOpts.path)
session.notifyFilePublish(indexOpts.path)
Expand Down
14 changes: 10 additions & 4 deletions modules/nextflow/src/main/groovy/nextflow/script/OutputDsl.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package nextflow.script

import java.nio.file.Path
import java.nio.file.Paths

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
Expand All @@ -27,7 +26,6 @@ import nextflow.extension.CH
import nextflow.extension.MixOp
import nextflow.extension.PublishOp
import nextflow.file.FileHelper

/**
* Implements the DSL for publishing workflow outputs
*
Expand Down Expand Up @@ -83,6 +81,10 @@ class OutputDsl {
setDefault('tags', value)
}

void enabled( boolean value ) {
setDefault('enabled', value)
}

private void setDefault(String name, Object value) {
if( defaults.containsKey(name) )
throw new ScriptRuntimeException("Default `${name}` option cannot be defined more than once in the workflow publish definition")
Expand Down Expand Up @@ -203,14 +205,18 @@ class OutputDsl {
setOption('tags', value)
}

void enabled( boolean value ) {
setOption('enabled', value)
}

private void setOption(String name, Object value) {
if( opts.containsKey(name) )
throw new ScriptRuntimeException("Publish option `${name}` cannot be defined more than once for a given target")
opts[name] = value
}

Map getOptions() {
opts
return opts
}

}
Expand Down Expand Up @@ -246,7 +252,7 @@ class OutputDsl {
}

Map getOptions() {
opts
return opts
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,60 @@ class OutputDslTest extends Specification {
root?.deleteDir()
}

def 'should set options' () {
when:
def dsl1 = new OutputDsl()
then:
dsl1.@defaults == [:]

when:
def dsl2 = new OutputDsl()
and:
dsl2.contentType('simple/text')
dsl2.ignoreErrors(true)
dsl2.mode('someMode')
dsl2.overwrite(true)
dsl2.storageClass('someClass')
dsl2.tags([foo:'1',bar:'2'])
dsl2.enabled(true)
then:
dsl2.@defaults == [
contentType:'simple/text',
ignoreErrors: true,
mode: 'someMode',
overwrite: true,
storageClass: 'someClass',
tags: [foo:'1',bar:'2'],
enabled: true
]
}

def 'should set target dsl' () {
when:
def dsl1 = new OutputDsl.TargetDsl()
then:
dsl1.getOptions() == [:]

when:
def dsl2 = new OutputDsl.TargetDsl()
and:
dsl2.contentType('simple/text')
dsl2.ignoreErrors(true)
dsl2.mode('someMode')
dsl2.overwrite(true)
dsl2.storageClass('someClass')
dsl2.tags([foo:'1',bar:'2'])
dsl2.enabled(true)
then:
dsl2.getOptions() == [
contentType:'simple/text',
ignoreErrors: true,
mode: 'someMode',
overwrite: true,
storageClass: 'someClass',
tags: [foo:'1',bar:'2'],
enabled: true
]
}

}

0 comments on commit 284415b

Please sign in to comment.