diff --git a/docs/config.rst b/docs/config.rst index 42ff30ac2b..1879a0dafc 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -810,6 +810,7 @@ NXF_OFFLINE When ``true`` disables the project automatic downloa NXF_CLOUD_DRIVER Defines the default cloud driver to be used if not specified in the config file or as command line option, either ``aws`` or ``google``. NXF_ANSI_LOG Enables/disables ANSI console output (default ``true`` when ANSI terminal is detected). NXF_ANSI_SUMMARY Enables/disables ANSI completion summary: `true|false` (default: print summary if execution last more than 1 minute). +NXF_SCM_FILE Defines the path location of the SCM config file (requires version ``20.10.0`` or later). JAVA_HOME Defines the path location of the Java VM installation used to run Nextflow. JAVA_CMD Defines the path location of the Java binary command used to launch Nextflow. HTTP_PROXY Defines the HTTP proxy server diff --git a/docs/sharing.rst b/docs/sharing.rst index 85b42a9e91..ff91e142a7 100644 --- a/docs/sharing.rst +++ b/docs/sharing.rst @@ -160,6 +160,9 @@ Downloaded pipelines can be deleted by using the ``drop`` command, as shown belo nextflow drop nextflow-io/hello + +.. _sharing-scm-file: + SCM configuration file ======================= @@ -196,6 +199,9 @@ token Private API access token (used only when the specified platf The attributes marked with a * are only required when defining the configuration of a private SCM server. +.. tip:: + A custom location for the SCM file can be specified using the ``NXF_SCM_FILE`` environment variable (requires + version ``20.10.0`` or later). BitBucket credentials --------------------- diff --git a/modules/nextflow/src/main/groovy/nextflow/k8s/K8sDriverLauncher.groovy b/modules/nextflow/src/main/groovy/nextflow/k8s/K8sDriverLauncher.groovy index 503fa86141..7b3e175656 100644 --- a/modules/nextflow/src/main/groovy/nextflow/k8s/K8sDriverLauncher.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/k8s/K8sDriverLauncher.groovy @@ -497,7 +497,7 @@ class K8sDriverLauncher { } protected Path getScmFile() { - ProviderConfig.SCM_FILE.toPath() + ProviderConfig.getScmConfigPath() } /** diff --git a/modules/nextflow/src/main/groovy/nextflow/scm/AssetManager.groovy b/modules/nextflow/src/main/groovy/nextflow/scm/AssetManager.groovy index d41762b86a..5fa11663ac 100644 --- a/modules/nextflow/src/main/groovy/nextflow/scm/AssetManager.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/scm/AssetManager.groovy @@ -119,7 +119,7 @@ class AssetManager { * Build the asset manager internal data structure * * @param pipelineName A project name or a project repository Git URL - * @param config A {@link Map} holding the configuration properties defined in the {@link ProviderConfig#SCM_FILE} file + * @param config A {@link Map} holding the configuration properties defined in the {@link ProviderConfig#DEFAULT_SCM_FILE} file * @param cliOpts User credentials provided on the command line. See {@link HubOptions} trait * @return The {@link AssetManager} object itself */ diff --git a/modules/nextflow/src/main/groovy/nextflow/scm/ProviderConfig.groovy b/modules/nextflow/src/main/groovy/nextflow/scm/ProviderConfig.groovy index e38dd13d6e..7877ed1cc4 100644 --- a/modules/nextflow/src/main/groovy/nextflow/scm/ProviderConfig.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/scm/ProviderConfig.groovy @@ -16,12 +16,17 @@ */ package nextflow.scm + +import java.nio.file.Path + import groovy.transform.CompileStatic import groovy.transform.PackageScope import nextflow.Const import nextflow.config.ConfigParser import nextflow.exception.AbortOperationException import nextflow.exception.ConfigParseException +import nextflow.file.FileHelper + /** * Models a repository provider configuration attributes * @@ -31,7 +36,21 @@ import nextflow.exception.ConfigParseException class ProviderConfig { @PackageScope - static public File SCM_FILE = Const.APP_HOME_DIR.resolve('scm').toFile() + static Path DEFAULT_SCM_FILE = Const.APP_HOME_DIR.resolve('scm') + + @PackageScope + static Map env = new HashMap<>(System.getenv()) + + static Path getScmConfigPath() { + def cfg = env.get('NXF_SCM_FILE') + if( !cfg ) + return DEFAULT_SCM_FILE + // check and return it if valid + final path = FileHelper.asPath(cfg) + if( !path.exists() ) + throw new AbortOperationException("Missing SCM config file: $cfg - Check the env variable NXF_SCM_FILE") + return path + } private String name @@ -69,7 +88,7 @@ class ProviderConfig { attr.platform = 'file' if( !attr.platform ) { - throw new AbortOperationException("Missing `platform` attribute for `$name` scm provider configuration -- Check file: ${SCM_FILE}") + throw new AbortOperationException("Missing `platform` attribute for `$name` scm provider configuration -- Check file: ${getScmConfigPath().toUriString()}") } if( attr.auth ) { @@ -209,7 +228,6 @@ class ProviderConfig { @PackageScope static Map parse(String text) { def slurper = new ConfigParser() - def env = new HashMap( System.getenv() ) slurper.setBinding(env) return slurper.parse(text) } @@ -243,7 +261,7 @@ class ProviderConfig { } @PackageScope - static Map getFromFile(File file) { + static Map getFromFile(Path file) { try { parse(file.text) } @@ -254,7 +272,7 @@ class ProviderConfig { } static Map getDefault() { - def file = SCM_FILE + final file = getScmConfigPath() return file.exists() ? getFromFile(file) : [:] } diff --git a/modules/nextflow/src/test/groovy/nextflow/script/ProcessConfigTest.groovy b/modules/nextflow/src/test/groovy/nextflow/script/ProcessConfigTest.groovy index 1bb386739e..a8efdc18c2 100644 --- a/modules/nextflow/src/test/groovy/nextflow/script/ProcessConfigTest.groovy +++ b/modules/nextflow/src/test/groovy/nextflow/script/ProcessConfigTest.groovy @@ -17,6 +17,9 @@ package nextflow.script +import java.nio.file.Files + +import nextflow.scm.ProviderConfig import spock.lang.Specification import spock.lang.Unroll @@ -625,4 +628,29 @@ class ProcessConfigTest extends Specification { process.accelerator == [request: 1, limit:5] } + def 'should get default config path' () { + given: + ProviderConfig.env.remove('NXF_SCM_FILE') + + when: + def path = ProviderConfig.getScmConfigPath() + then: + path.toString() == "${System.getProperty('user.home')}/.nextflow/scm" + + } + + def 'should get custom config path' () { + given: + def cfg = Files.createTempFile('test','config') + ProviderConfig.env.NXF_SCM_FILE = cfg.toString() + + when: + def path = ProviderConfig.getScmConfigPath() + then: + path.toString() == cfg.toString() + + cleanup: + ProviderConfig.env.remove('NXF_SCM_FILE') + cfg.delete() + } }