Skip to content

Commit

Permalink
Fix Allow custom SCM file location #1657
Browse files Browse the repository at this point in the history
  • Loading branch information
pditommaso committed Aug 18, 2020
1 parent 30e453f commit 7c27f89
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions docs/sharing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======================

Expand Down Expand Up @@ -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
---------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ class K8sDriverLauncher {
}

protected Path getScmFile() {
ProviderConfig.SCM_FILE.toPath()
ProviderConfig.getScmConfigPath()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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<String,String> 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

Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -243,7 +261,7 @@ class ProviderConfig {
}

@PackageScope
static Map getFromFile(File file) {
static Map getFromFile(Path file) {
try {
parse(file.text)
}
Expand All @@ -254,7 +272,7 @@ class ProviderConfig {
}

static Map getDefault() {
def file = SCM_FILE
final file = getScmConfigPath()
return file.exists() ? getFromFile(file) : [:]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package nextflow.script

import java.nio.file.Files

import nextflow.scm.ProviderConfig
import spock.lang.Specification
import spock.lang.Unroll

Expand Down Expand Up @@ -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()
}
}

0 comments on commit 7c27f89

Please sign in to comment.