File tree Expand file tree Collapse file tree 3 files changed +39
-9
lines changed
main/groovy/nextflow/config/parser/v1
test/groovy/nextflow/config/parser Expand file tree Collapse file tree 3 files changed +39
-9
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,11 @@ import nextflow.SysEnv
25
25
import nextflow.config.StripSecretsXform
26
26
import nextflow.exception.IllegalConfigException
27
27
import nextflow.file.FileHelper
28
+ import nextflow.util.Duration
29
+ import nextflow.util.MemoryUnit
28
30
import org.codehaus.groovy.control.CompilerConfiguration
29
31
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer
32
+ import org.codehaus.groovy.control.customizers.ImportCustomizer
30
33
import org.slf4j.Logger
31
34
import org.slf4j.LoggerFactory
32
35
/**
@@ -119,6 +122,11 @@ abstract class ConfigBase extends Script {
119
122
if ( renderClosureAsString )
120
123
params. put(' renderClosureAsString' , true )
121
124
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)
122
130
123
131
// -- setup the grengine instance
124
132
def engine = new Grengine (this . class. classLoader,config)
Original file line number Diff line number Diff line change @@ -510,29 +510,40 @@ class ConfigParserV1Test extends Specification {
510
510
}
511
511
512
512
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 = '''
515
523
mem1 = 1.GB
516
524
mem2 = 1_000_000.toMemory()
517
525
mem3 = MemoryUnit.of(2_000)
518
526
time1 = 2.hours
519
527
time2 = 60_000.toDuration()
520
528
time3 = Duration.of(120_000)
521
529
flag = 10000 < 1.GB
522
- '''
530
+
531
+ includeConfig 'extra.config'
532
+ '''
523
533
524
534
when :
525
- result = new ConfigParserV1 ()
526
- .parse(CONFIG )
535
+ def result = new ConfigParserV1 (). parse(configFile)
527
536
then :
528
537
result. mem1 instanceof MemoryUnit
529
538
result. mem1 == MemoryUnit . of(' 1 GB' )
530
539
result. mem2 == MemoryUnit . of(1_000_000)
531
540
result. mem3 == MemoryUnit . of(2_000)
541
+ result. mem4 == MemoryUnit . of(' 8 GB' )
532
542
result. time1 instanceof Duration
533
543
result. time1 == Duration . of(' 2 hours' )
534
544
result. time2 == Duration . of(60_000)
535
545
result. time3 == Duration . of(120_000)
546
+ result. time4 == Duration . of(' 24h' )
536
547
result. flag == true
537
548
}
538
549
Original file line number Diff line number Diff line change @@ -456,29 +456,40 @@ class ConfigParserV2Test extends Specification {
456
456
}
457
457
458
458
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 = '''
461
469
mem1 = 1.GB
462
470
mem2 = 1_000_000.toMemory()
463
471
mem3 = MemoryUnit.of(2_000)
464
472
time1 = 2.hours
465
473
time2 = 60_000.toDuration()
466
474
time3 = Duration.of(120_000)
467
475
flag = 10000 < 1.GB
476
+
477
+ includeConfig 'extra.config'
468
478
'''
469
479
470
480
when :
471
- result = new ConfigParserV2 ()
472
- .parse(CONFIG )
481
+ def result = new ConfigParserV2 (). parse(configFile)
473
482
then :
474
483
result. mem1 instanceof MemoryUnit
475
484
result. mem1 == MemoryUnit . of(' 1 GB' )
476
485
result. mem2 == MemoryUnit . of(1_000_000)
477
486
result. mem3 == MemoryUnit . of(2_000)
487
+ result. mem4 == MemoryUnit . of(' 8 GB' )
478
488
result. time1 instanceof Duration
479
489
result. time1 == Duration . of(' 2 hours' )
480
490
result. time2 == Duration . of(60_000)
481
491
result. time3 == Duration . of(120_000)
492
+ result. time4 == Duration . of(' 24h' )
482
493
result. flag == true
483
494
}
484
495
You can’t perform that action at this time.
0 commit comments