Skip to content

Commit 4a1590e

Browse files
authored
Merge pull request #362 from pinin4fjords/fix/config-scope-noarg-constructor
Fix: Add no-arg constructors for v2 config parser scope registration
2 parents 29b8dfa + 5f61dd3 commit 4a1590e

8 files changed

Lines changed: 135 additions & 50 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# New
22
## Bug Fixes:
3+
- Eliminated `Unrecognized config option` warnings under Nextflow's v2 syntax parser by registering `CO2FootprintConfig` as an extension point and aligning the nested file-config scopes with the v2 `ConfigScope` discovery rules
34

45
## Misc:
56

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ nextflowPlugin {
107107
className = 'nextflow.co2footprint.CO2FootprintPlugin'
108108
extensionPoints = [
109109
'nextflow.co2footprint.CO2FootprintFactory',
110-
'nextflow.co2footprint.CO2FootprintExtension'
110+
'nextflow.co2footprint.CO2FootprintExtension',
111+
'nextflow.co2footprint.CO2FootprintConfig'
111112
]
112113

113114
}

src/main/nextflow/co2footprint/CO2FootprintConfig.groovy

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,66 +57,68 @@ class CO2FootprintConfig implements ConfigScope {
5757
private final String timestamp = TraceHelper.launchTimestampFmt()
5858
private final String executor
5959

60-
@ConfigOption(types=[Map])
6160
@Description('Configuration for the trace file.')
6261
final TraceFileConfig trace
6362

64-
@ConfigOption(types=[Map])
6563
@Description('Configuration for the summary file.')
6664
final SummaryFileConfig summary
6765

68-
@ConfigOption(types=[Map])
6966
@Description('Configuration for the report file.')
7067
final ReportFileConfig report
7168

72-
@ConfigOption(types=[Map])
7369
@Description('Configuration for the provenance data/machine-readable file.')
7470
final ProvenanceFileConfig provenance
7571

76-
@ConfigOption(types=[GString])
72+
@ConfigOption
7773
@Description('Location GeoCode from Electricity maps.')
7874
final String location
7975

8076
@ConfigOption(types=[Number, BigDecimal])
8177
@Description('Location-based carbon intensity (CI).')
8278
final CiRecord ci
8379

84-
@ConfigOption(types=[Number])
80+
@ConfigOption
8581
@Description('Market-based carbon intensity (CI).')
8682
final BigDecimal ciMarket
8783

88-
@ConfigOption(types=[GString])
84+
@ConfigOption
8985
@Description('Electricity-maps API token.')
9086
final String emApiKey
9187

92-
@ConfigOption(types=[Number])
88+
@ConfigOption
9389
@Description('Power usage effectiveness (PUE) of the data centre.')
9490
BigDecimal pue
9591

96-
@ConfigOption(types=[Number])
92+
@ConfigOption
9793
@Description('Power draw of memory [W per GB].')
9894
final BigDecimal powerdrawMem
9995

10096
@ConfigOption
10197
@Description('Turns off pattern matching of CPU names.')
10298
final Boolean ignoreCpuModel
10399

104-
@ConfigOption(types=[Number])
100+
@ConfigOption
105101
@Description('Default powerdraw of the CPU.')
106102
final BigDecimal powerdrawCpuDefault
107103

108-
@ConfigOption(types=[String, GString])
104+
@ConfigOption
109105
@Description('Path to a custom CPU TDP file.')
110106
final Path customCpuTdpFile
111107

112-
@ConfigOption(types=[GString])
108+
@ConfigOption
113109
@Description('Type of computer on which the workflow is run [\'local\', \'compute cluster\', \'\'].')
114110
String machineType
115111

116112
@ConfigOption
117113
@Description('A power model function that takes the parameter `coreUsage`.')
118114
final Closure<Number> cpuPowerModel
119115

116+
/**
117+
* No-arg constructor required by Nextflow's v2 config parser to
118+
* discover and validate config options at parse time.
119+
*/
120+
CO2FootprintConfig() {}
121+
120122
/**
121123
* Loads configuration from a map and sets up defaults and fallbacks.
122124
* Also sets up CPU and CI data sources and assigns machine type and PUE.

src/main/nextflow/co2footprint/Config/BaseFileConfig.groovy

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ package nextflow.co2footprint.Config
22

33
import groovy.util.logging.Slf4j
44
import nextflow.co2footprint.CO2FootprintConfig
5-
import nextflow.config.spec.ConfigOption
6-
import nextflow.script.dsl.Description
7-
85
import java.nio.file.Path
96

107
/**
@@ -18,36 +15,51 @@ import java.nio.file.Path
1815
class BaseFileConfig {
1916
final String name
2017
final String ending
21-
22-
@ConfigOption(types=[String, GString])
23-
@Description('Path to the file.')
24-
final Path file
25-
26-
@ConfigOption
27-
@Description('Whether to enable the file creation.')
28-
final Boolean enabled
29-
30-
@ConfigOption
31-
@Description('Whether to overwrite a file if it already exists.')
32-
final Boolean overwrite
18+
final boolean defaultEnabled
3319

3420
protected final LinkedHashSet<String> usedKeys = [] as LinkedHashSet<String>
3521

22+
3623
/**
3724
* Parses a file-based sub-configuration for nf-co2footprint and sets up defaults and fallbacks.
3825
*
39-
* @param fileConfigMap User-provided configuration options
40-
* @param timestamp Timestamp for generating default filenames
4126
* @param subConfigName Name of the configuration scope
4227
* @param fileEnding Output file extension (default: txt)
43-
* @param defaultEnabled Whether to enable the file by default (default: true)
4428
*/
45-
BaseFileConfig(Map<String, Object> fileConfigMap, String timestamp, String subConfigName, String fileEnding='txt', boolean defaultEnabled=true){
29+
BaseFileConfig(String subConfigName, String fileEnding, boolean defaultEnabled=true){
4630
this.name = subConfigName
4731
this.ending = fileEnding ?: 'txt'
32+
this.defaultEnabled = defaultEnabled
33+
}
4834

49-
file = Path.of(CO2FootprintConfig.getCollect('file', fileConfigMap, usedKeys) as String ?: "co2footprint_${name}_${timestamp}.${ending}")
50-
enabled = fileConfigMap.containsKey('enabled') ? CO2FootprintConfig.getCollect('enabled', fileConfigMap, usedKeys) : defaultEnabled
51-
overwrite = fileConfigMap.containsKey('overwrite') ? CO2FootprintConfig.getCollect('overwrite', fileConfigMap, usedKeys) : true
35+
/**
36+
* Define a file path from the given config map and timestamp, as well as predefined variables.
37+
*
38+
* @param fileConfig The general config of this file.
39+
* @param timestamp A timestamp string.
40+
* @return The path to the file.
41+
*/
42+
protected Path defineFile(Map<String, Object> fileConfig, String timestamp) {
43+
return Path.of(CO2FootprintConfig.getCollect('file', fileConfig, usedKeys) as String ?: "co2footprint_${name}_${timestamp}.${ending}")
44+
}
45+
46+
/**
47+
* Define whether the construction of this file is enabled.
48+
*
49+
* @param fileConfig The general config of this file.
50+
* @return Whether or not to write the file.
51+
*/
52+
protected boolean defineEnabled(Map<String, Object> fileConfig) {
53+
return fileConfig.containsKey('enabled') ? CO2FootprintConfig.getCollect('enabled', fileConfig, usedKeys) : defaultEnabled
54+
}
55+
56+
/**
57+
* Define whether an existing file should be overwritten.
58+
*
59+
* @param fileConfig The general config of this file.
60+
* @return Whether or not to overwrite the file.
61+
*/
62+
protected boolean defineOverwrite(Map<String, Object> fileConfig) {
63+
return fileConfig.containsKey('overwrite') ? CO2FootprintConfig.getCollect('overwrite', fileConfig, usedKeys) : true
5264
}
5365
}

src/main/nextflow/co2footprint/Config/ProvenanceFileConfig.groovy

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,35 @@ package nextflow.co2footprint.Config
33
import nextflow.co2footprint.CO2FootprintConfig
44
import nextflow.config.spec.ConfigOption
55
import nextflow.config.spec.ConfigScope
6-
import nextflow.config.spec.ScopeName
76
import nextflow.script.dsl.Description
87

9-
@ScopeName('co2footprint.provenance')
8+
import java.nio.file.Path
9+
1010
@Description('The `co2footprint.provenance` scope allows you to configure the data/machine-actionable file of the `nf-co2footprint` plugin.')
1111
class ProvenanceFileConfig extends BaseFileConfig implements ConfigScope {
1212

13+
@ConfigOption
14+
@Description('Path to the file.')
15+
final Path file
16+
17+
@ConfigOption
18+
@Description('Whether to enable the file creation.')
19+
final Boolean enabled
20+
21+
@ConfigOption
22+
@Description('Whether to overwrite a file if it already exists.')
23+
final Boolean overwrite
24+
1325
@ConfigOption
1426
@Description('Whether only emission metrics should be reported in the provenance file.')
1527
final boolean emissionMetricsOnly
1628

1729
ProvenanceFileConfig(Map provenanceFileConfig, String timestamp=null) {
18-
super(provenanceFileConfig, timestamp, 'provenance', 'json', false)
30+
super('provenance', 'json', false)
31+
32+
file = defineFile(provenanceFileConfig, timestamp)
33+
enabled = defineEnabled(provenanceFileConfig)
34+
overwrite = defineOverwrite(provenanceFileConfig)
1935

2036
emissionMetricsOnly = provenanceFileConfig.containsKey('emissionMetricsOnly') ?
2137
CO2FootprintConfig.getCollect('emissionMetricsOnly', provenanceFileConfig, usedKeys) as boolean :

src/main/nextflow/co2footprint/Config/ReportFileConfig.groovy

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,36 @@ package nextflow.co2footprint.Config
33
import nextflow.co2footprint.CO2FootprintConfig
44
import nextflow.config.spec.ConfigOption
55
import nextflow.config.spec.ConfigScope
6-
import nextflow.config.spec.ScopeName
76
import nextflow.script.dsl.Description
87

9-
@ScopeName('co2footprint.report')
8+
import java.nio.file.Path
9+
1010
@Description('The `co2footprint.report` scope allows you to configure the report file of the `nf-co2footprint` plugin.')
11-
class ReportFileConfig extends BaseFileConfig implements ConfigScope{
11+
class ReportFileConfig extends BaseFileConfig implements ConfigScope {
12+
13+
@ConfigOption
14+
@Description('Path to the file.')
15+
final Path file
16+
17+
@ConfigOption
18+
@Description('Whether to enable the file creation.')
19+
final Boolean enabled
20+
21+
@ConfigOption
22+
@Description('Whether to overwrite a file if it already exists.')
23+
final Boolean overwrite
1224

1325
@ConfigOption
1426
@Description('The number of maximum tasks that is displayed in the report.')
1527
final Integer maxTasks
1628

1729
ReportFileConfig(Map reportFileConfig, String timestamp=null) {
18-
super(reportFileConfig, timestamp, 'report', 'html')
30+
super('report', 'html')
31+
32+
file = defineFile(reportFileConfig, timestamp)
33+
enabled = defineEnabled(reportFileConfig)
34+
overwrite = defineOverwrite(reportFileConfig)
35+
1936
maxTasks = reportFileConfig.containsKey('maxTasks') ?
2037
CO2FootprintConfig.getCollect('maxTasks', reportFileConfig, usedKeys) as Integer :
2138
10_000

src/main/nextflow/co2footprint/Config/SummaryFileConfig.groovy

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
package nextflow.co2footprint.Config
22

33
import nextflow.co2footprint.CO2FootprintConfig
4+
import nextflow.config.spec.ConfigOption
45
import nextflow.config.spec.ConfigScope
5-
import nextflow.config.spec.ScopeName
66
import nextflow.script.dsl.Description
77

8-
@ScopeName('co2footprint.summary')
8+
import java.nio.file.Path
9+
910
@Description('The `co2footprint.summary` scope allows you to configure the summary file of the `nf-co2footprint` plugin.')
10-
class SummaryFileConfig extends BaseFileConfig implements ConfigScope{
11+
class SummaryFileConfig extends BaseFileConfig implements ConfigScope {
12+
13+
@ConfigOption
14+
@Description('Path to the file.')
15+
final Path file
16+
17+
@ConfigOption
18+
@Description('Whether to enable the file creation.')
19+
final Boolean enabled
20+
21+
@ConfigOption
22+
@Description('Whether to overwrite a file if it already exists.')
23+
final Boolean overwrite
24+
1125
SummaryFileConfig(Map summaryFileConfig, String timestamp=null) {
12-
super(summaryFileConfig, timestamp, 'summary', 'txt')
26+
super('summary', 'txt')
27+
28+
file = defineFile(summaryFileConfig, timestamp)
29+
enabled = defineEnabled(summaryFileConfig)
30+
overwrite = defineOverwrite(summaryFileConfig)
1331

1432
CO2FootprintConfig.checkKeyUsage(summaryFileConfig, usedKeys)
1533
}

src/main/nextflow/co2footprint/Config/TraceFileConfig.groovy

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
package nextflow.co2footprint.Config
22

33
import nextflow.co2footprint.CO2FootprintConfig
4+
import nextflow.config.spec.ConfigOption
45
import nextflow.config.spec.ConfigScope
5-
import nextflow.config.spec.ScopeName
66
import nextflow.script.dsl.Description
77

8-
@ScopeName('co2footprint.trace')
8+
import java.nio.file.Path
9+
910
@Description('The `co2footprint.trace` scope allows you to configure the trace file of the `nf-co2footprint` plugin.')
10-
class TraceFileConfig extends BaseFileConfig implements ConfigScope{
11+
class TraceFileConfig extends BaseFileConfig implements ConfigScope {
12+
13+
@ConfigOption
14+
@Description('Path to the file.')
15+
final Path file
16+
17+
@ConfigOption
18+
@Description('Whether to enable the file creation.')
19+
final Boolean enabled
20+
21+
@ConfigOption
22+
@Description('Whether to overwrite a file if it already exists.')
23+
final Boolean overwrite
24+
1125
TraceFileConfig(Map traceFileConfig, String timestamp=null) {
12-
super(traceFileConfig, timestamp, 'trace', 'txt')
26+
super('trace', 'txt')
27+
28+
file = defineFile(traceFileConfig, timestamp)
29+
enabled = defineEnabled(traceFileConfig)
30+
overwrite = defineOverwrite(traceFileConfig)
1331

1432
CO2FootprintConfig.checkKeyUsage(traceFileConfig, usedKeys)
1533
}

0 commit comments

Comments
 (0)