Skip to content

Commit 8f79061

Browse files
authored
Fix default imports in included configs (#6096)
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
1 parent f09ae8d commit 8f79061

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

modules/nextflow/src/main/groovy/nextflow/config/parser/v1/ConfigBase.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ import nextflow.SysEnv
2525
import nextflow.config.StripSecretsXform
2626
import nextflow.exception.IllegalConfigException
2727
import nextflow.file.FileHelper
28+
import nextflow.util.Duration
29+
import nextflow.util.MemoryUnit
2830
import org.codehaus.groovy.control.CompilerConfiguration
2931
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer
32+
import org.codehaus.groovy.control.customizers.ImportCustomizer
3033
import org.slf4j.Logger
3134
import org.slf4j.LoggerFactory
3235
/**
@@ -119,6 +122,11 @@ abstract class ConfigBase extends Script {
119122
if( renderClosureAsString )
120123
params.put('renderClosureAsString', true)
121124
config.addCompilationCustomizers(new ASTTransformationCustomizer(params, ConfigTransform))
125+
// -- add implicit types
126+
def importCustomizer = new ImportCustomizer()
127+
importCustomizer.addImports( Duration.name )
128+
importCustomizer.addImports( MemoryUnit.name )
129+
config.addCompilationCustomizers(importCustomizer)
122130

123131
// -- setup the grengine instance
124132
def engine = new Grengine(this.class.classLoader,config)

modules/nextflow/src/test/groovy/nextflow/config/parser/v1/ConfigParserV1Test.groovy

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,29 +510,40 @@ class ConfigParserV1Test extends Specification {
510510
}
511511

512512
def 'should handle extend mem and duration units' () {
513-
ConfigObject result
514-
def CONFIG = '''
513+
given:
514+
def folder = File.createTempDir()
515+
def configFile = new File(folder,'nextflow.config')
516+
517+
new File(folder,'extra.config').text = """
518+
mem4 = '8GB' as MemoryUnit
519+
time4 = '24h' as Duration
520+
"""
521+
522+
configFile.text = '''
515523
mem1 = 1.GB
516524
mem2 = 1_000_000.toMemory()
517525
mem3 = MemoryUnit.of(2_000)
518526
time1 = 2.hours
519527
time2 = 60_000.toDuration()
520528
time3 = Duration.of(120_000)
521529
flag = 10000 < 1.GB
522-
'''
530+
531+
includeConfig 'extra.config'
532+
'''
523533

524534
when:
525-
result = new ConfigParserV1()
526-
.parse(CONFIG)
535+
def result = new ConfigParserV1().parse(configFile)
527536
then:
528537
result.mem1 instanceof MemoryUnit
529538
result.mem1 == MemoryUnit.of('1 GB')
530539
result.mem2 == MemoryUnit.of(1_000_000)
531540
result.mem3 == MemoryUnit.of(2_000)
541+
result.mem4 == MemoryUnit.of('8 GB')
532542
result.time1 instanceof Duration
533543
result.time1 == Duration.of('2 hours')
534544
result.time2 == Duration.of(60_000)
535545
result.time3 == Duration.of(120_000)
546+
result.time4 == Duration.of('24h')
536547
result.flag == true
537548
}
538549

modules/nextflow/src/test/groovy/nextflow/config/parser/v2/ConfigParserV2Test.groovy

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,29 +456,40 @@ class ConfigParserV2Test extends Specification {
456456
}
457457

458458
def 'should handle extend mem and duration units' () {
459-
ConfigObject result
460-
def CONFIG = '''
459+
given:
460+
def folder = File.createTempDir()
461+
def configFile = new File(folder,'nextflow.config')
462+
463+
new File(folder,'extra.config').text = """
464+
mem4 = '8GB' as MemoryUnit
465+
time4 = '24h' as Duration
466+
"""
467+
468+
configFile.text = '''
461469
mem1 = 1.GB
462470
mem2 = 1_000_000.toMemory()
463471
mem3 = MemoryUnit.of(2_000)
464472
time1 = 2.hours
465473
time2 = 60_000.toDuration()
466474
time3 = Duration.of(120_000)
467475
flag = 10000 < 1.GB
476+
477+
includeConfig 'extra.config'
468478
'''
469479

470480
when:
471-
result = new ConfigParserV2()
472-
.parse(CONFIG)
481+
def result = new ConfigParserV2().parse(configFile)
473482
then:
474483
result.mem1 instanceof MemoryUnit
475484
result.mem1 == MemoryUnit.of('1 GB')
476485
result.mem2 == MemoryUnit.of(1_000_000)
477486
result.mem3 == MemoryUnit.of(2_000)
487+
result.mem4 == MemoryUnit.of('8 GB')
478488
result.time1 instanceof Duration
479489
result.time1 == Duration.of('2 hours')
480490
result.time2 == Duration.of(60_000)
481491
result.time3 == Duration.of(120_000)
492+
result.time4 == Duration.of('24h')
482493
result.flag == true
483494
}
484495

0 commit comments

Comments
 (0)