Skip to content

Commit f99bcd3

Browse files
Replace output labels with label directive (#6035)
--------- Signed-off-by: Paolo Di Tommaso <[email protected]> Signed-off-by: Ben Sherman <[email protected]> Co-authored-by: Ben Sherman <[email protected]>
1 parent 375dc17 commit f99bcd3

File tree

4 files changed

+16
-57
lines changed

4 files changed

+16
-57
lines changed

docs/workflow.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -635,17 +635,14 @@ The following directives are available for each output in the output block:
635635
`header`
636636
: When `true`, the keys of the first record are used as the column names (default: `false`). Can also be a list of column names. Only used for CSV files.
637637

638-
`labels`
639-
: Specify labels to be applied to the index file as a list of strings.
640-
641638
`path`
642639
: The name of the index file relative to the base output directory (required). Can be a CSV, JSON, or YAML file.
643640

644641
`sep`
645642
: The character used to separate values (default: `','`). Only used for CSV files.
646643

647-
`labels`
648-
: Specify labels to be applied to every published file. Can be a list of strings or a closure that returns a list.
644+
`label`
645+
: Specify a label to be applied to every published file. Can be specified multiple times.
649646

650647
`path`
651648
: Specify the publish path relative to the output directory (default: `'.'`). Can be a path, a closure that defines a custom directory for each published value, or a closure that publishes individual files using the `>>` operator.

modules/nextflow/src/main/groovy/nextflow/extension/PublishOp.groovy

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ class PublishOp {
9999
overrides.saveAs = targetResolver
100100
else
101101
overrides.path = targetResolver
102-
overrides.labels = getLabels(publishOpts.labels, value)
103102

104103
final publisher = PublishDir.create(publishOpts + overrides)
105104

@@ -188,30 +187,6 @@ class PublishOp {
188187
}
189188
}
190189

191-
/**
192-
* Get or resolve the labels of a workflow output.
193-
*
194-
* @param labels List | Closure<List>
195-
* @param value
196-
*/
197-
protected static List<String> getLabels(labels, value) {
198-
if( labels == null )
199-
return []
200-
if( labels instanceof List<String> )
201-
return labels
202-
if( labels instanceof Closure ) {
203-
try {
204-
final result = labels.call(value)
205-
if( result instanceof List<String> )
206-
return result
207-
} catch (Throwable e) {
208-
log.warn("Exception while evaluating dynamic `labels` directive for value '$value' -- ${e.getMessage()}")
209-
return []
210-
}
211-
}
212-
throw new ScriptRuntimeException("Invalid output `labels` directive -- it should be either a List or a closure that returns a List")
213-
}
214-
215190
/**
216191
* Once all channel values have been published, publish the final
217192
* workflow output and index file (if enabled).
@@ -242,7 +217,7 @@ class PublishOp {
242217
else {
243218
log.warn "Invalid extension '${ext}' for index file '${indexPath}' -- should be CSV, JSON, or YAML"
244219
}
245-
session.notifyFilePublish(new FilePublishEvent(null, indexPath, indexOpts.labels))
220+
session.notifyFilePublish(new FilePublishEvent(null, indexPath, publishOpts.labels as List))
246221
}
247222

248223
log.trace "Publish operator complete"
@@ -369,16 +344,13 @@ class PublishOp {
369344
static class IndexOpts {
370345
Path path
371346
def /* boolean | List<String> */ header = false
372-
List<String> labels
373347
String sep = ','
374348

375349
IndexOpts(Path targetDir, Map opts) {
376350
this.path = targetDir.resolve(opts.path as String)
377351

378352
if( opts.header != null )
379353
this.header = opts.header
380-
if( opts.labels )
381-
this.labels = opts.labels as List<String>
382354
if( opts.sep )
383355
this.sep = opts.sep as String
384356
}

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,12 @@
1616

1717
package nextflow.script
1818

19-
import java.nio.file.Path
20-
2119
import groovy.transform.CompileStatic
2220
import groovy.util.logging.Slf4j
23-
import groovyx.gpars.dataflow.DataflowWriteChannel
2421
import nextflow.Session
2522
import nextflow.exception.ScriptRuntimeException
2623
import nextflow.extension.CH
27-
import nextflow.extension.MixOp
2824
import nextflow.extension.PublishOp
29-
import nextflow.file.FileHelper
3025
/**
3126
* Implements the DSL for publishing workflow outputs
3227
*
@@ -133,12 +128,13 @@ class OutputDsl {
133128
setOption('index', dsl.getOptions())
134129
}
135130

136-
void labels(List<String> value) {
137-
setOption('labels', value)
138-
}
139-
140-
void labels(Closure value) {
141-
setOption('labels', value)
131+
void label(CharSequence value) {
132+
final opts = getOptions()
133+
final current = opts.get('labels')
134+
if( current instanceof List )
135+
current.add(value)
136+
else
137+
opts.put('labels', [value])
142138
}
143139

144140
void mode(String value) {
@@ -194,10 +190,6 @@ class OutputDsl {
194190
setOption('header', value)
195191
}
196192

197-
void labels(List<String> value) {
198-
setOption('labels', value)
199-
}
200-
201193
void path(String value) {
202194
setOption('path', value)
203195
}

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class OutputDslTest extends Specification {
7171
}
7272
dsl.declare('bar') {
7373
path { v -> "${'barbar'}" }
74+
label 'foo'
75+
label 'bar'
7476
index {
7577
path 'index.csv'
7678
}
@@ -84,11 +86,11 @@ class OutputDslTest extends Specification {
8486
"${outputDir}/barbar/file2.txt"
8587
""".stripIndent()
8688
and:
87-
1 * session.notifyFilePublish(new FilePublishEvent(file1, outputDir.resolve('foo/file1.txt'), []))
88-
1 * session.notifyFilePublish(new FilePublishEvent(file2, outputDir.resolve('barbar/file2.txt'), []))
89+
1 * session.notifyFilePublish(new FilePublishEvent(file1, outputDir.resolve('foo/file1.txt'), null))
90+
1 * session.notifyFilePublish(new FilePublishEvent(file2, outputDir.resolve('barbar/file2.txt'), ['foo', 'bar']))
8991
1 * session.notifyWorkflowOutput(new WorkflowOutputEvent('foo', [outputDir.resolve('foo/file1.txt')], null))
9092
1 * session.notifyWorkflowOutput(new WorkflowOutputEvent('bar', [outputDir.resolve('barbar/file2.txt')], outputDir.resolve('index.csv')))
91-
1 * session.notifyFilePublish(new FilePublishEvent(null, outputDir.resolve('index.csv'), null))
93+
1 * session.notifyFilePublish(new FilePublishEvent(null, outputDir.resolve('index.csv'), ['foo', 'bar']))
9294

9395
cleanup:
9496
SysEnv.pop()
@@ -125,7 +127,7 @@ class OutputDslTest extends Specification {
125127
then:
126128
outputDir.resolve('file1.txt').text == 'Hello'
127129
and:
128-
1 * session.notifyFilePublish(new FilePublishEvent(file1, outputDir.resolve('file1.txt'), []))
130+
1 * session.notifyFilePublish(new FilePublishEvent(file1, outputDir.resolve('file1.txt'), null))
129131
1 * session.notifyWorkflowOutput(new WorkflowOutputEvent('foo', [outputDir.resolve('file1.txt')], null))
130132

131133
cleanup:
@@ -149,7 +151,6 @@ class OutputDslTest extends Specification {
149151
dsl2.overwrite(true)
150152
dsl2.storageClass('someClass')
151153
dsl2.tags([foo:'1',bar:'2'])
152-
dsl2.labels(['label'])
153154
then:
154155
dsl2.getOptions() == [
155156
contentType:'simple/text',
@@ -159,7 +160,6 @@ class OutputDslTest extends Specification {
159160
overwrite: true,
160161
storageClass: 'someClass',
161162
tags: [foo:'1',bar:'2'],
162-
labels: ['label']
163163
]
164164
}
165165

@@ -175,13 +175,11 @@ class OutputDslTest extends Specification {
175175
dsl2.header(true)
176176
dsl2.path('path')
177177
dsl2.sep(',')
178-
dsl2.labels(['label'])
179178
then:
180179
dsl2.getOptions() == [
181180
header: true,
182181
path: 'path',
183182
sep: ',',
184-
labels: ['label']
185183
]
186184
}
187185

0 commit comments

Comments
 (0)