Skip to content

Commit

Permalink
Add variable NXF_CONFIG_FILE
Browse files Browse the repository at this point in the history
  • Loading branch information
pditommaso committed Sep 2, 2020
1 parent ed99fd4 commit d15edcb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Expand Up @@ -77,6 +77,8 @@ class ConfigBuilder {

Map<ConfigObject, String> emptyVariables = new LinkedHashMap<>(10)

Map<String,String> env = new HashMap<>(System.getenv())

List<String> warnings = new ArrayList<>(10);

{
Expand Down Expand Up @@ -205,6 +207,7 @@ class ConfigBuilder {

/**
* Config file in the pipeline base dir
* This config file name should be predictable, therefore cannot be overridden
*/
def base = null
if( baseDir && baseDir != currentDir ) {
Expand All @@ -217,8 +220,10 @@ class ConfigBuilder {

/**
* Local or user provided file
* Default config file name can be overridden with `NXF_CONFIG_FILE` env variable
*/
def local = currentDir.resolve('nextflow.config')
def configFileName = env.get('NXF_CONFIG_FILE') ?: 'nextflow.config'
def local = currentDir.resolve(configFileName)
if( local.exists() && local != base ) {
log.debug "Found config local: $local"
result << local
Expand Down
Expand Up @@ -280,6 +280,45 @@ class ConfigBuilderTest extends Specification {
folder?.deleteDir()
}
def 'should fetch the config path from env var' () {
given:
def folder = File.createTempDir()
def configMain = new File(folder,'my.config').absoluteFile
configMain.text = """
process.name = 'alpha'
params.one = 'a'
params.two = 'b'
"""
// relative path to current dir
when:
def config = new ConfigBuilder(env: [NXF_CONFIG_FILE: 'my.config']) .setCurrentDir(folder.toPath()) .build()
then:
config.params.one == 'a'
config.params.two == 'b'
config.process.name == 'alpha'
// absolute path
when:
config = new ConfigBuilder(env: [NXF_CONFIG_FILE: configMain.toString()]) .build()
then:
config.params.one == 'a'
config.params.two == 'b'
config.process.name == 'alpha'
// default should not find it
when:
config = new ConfigBuilder() .build()
then:
config.params == [:]
cleanup:
folder?.deleteDir()
}
def 'CLI params should overrides the ones in one or more profiles' () {
setup:
Expand Down

0 comments on commit d15edcb

Please sign in to comment.