Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom conda channels #3435

Merged
merged 2 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class CondaCache {

private Path configCacheDir0

private List<String> channels = Collections.emptyList()

@PackageScope String getCreateOptions() { createOptions }

@PackageScope Duration getCreateTimeout() { createTimeout }
Expand All @@ -74,6 +76,8 @@ class CondaCache {

@PackageScope Path getConfigCacheDir0() { configCacheDir0 }

@PackageScope List<String> getChannels() { channels }

@PackageScope String getBinaryName() {
if (useMamba)
return "mamba"
Expand Down Expand Up @@ -111,7 +115,9 @@ class CondaCache {

if( config.useMicromamba )
useMicromamba = config.useMicromamba as boolean


if( config.getChannels() )
channels = config.getChannels()
}

/**
Expand Down Expand Up @@ -278,7 +284,8 @@ class CondaCache {
}

else {
cmd = "${binaryName} create ${opts}--yes --quiet --prefix ${Escape.path(prefixPath)} $condaEnv"
final channelsOpt = channels.collect(it -> "-c $it ").join('')
cmd = "${binaryName} create ${opts}--yes --quiet --prefix ${Escape.path(prefixPath)} ${channelsOpt}$condaEnv"
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ package nextflow.conda
import groovy.transform.CompileStatic

/**
*
* Model Conda configuration
*
* @author Paolo Di Tommaso <paolo.ditommaso@gmail.com>
*/
@CompileStatic
Expand All @@ -42,4 +43,19 @@ class CondaConfig extends LinkedHashMap {
enabled = env.get('NXF_CONDA_ENABLED')
return enabled?.toString() == 'true'
}

List<String> getChannels() {
final value = get('channels')
if( !value ) {
return Collections.<String>emptyList()
}
if( value instanceof List ) {
return value
}
if( value instanceof CharSequence ) {
return value.tokenize(',').collect(it -> it.trim())
}

throw new IllegalArgumentException("Unexected conda.channels value: $value")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class CondaCacheTest extends Specification {
result == PREFIX
}

def 'should create conda env with options - using mamba' () {
def 'should create conda env with options - using mamba' () {
given:
def ENV = 'bwa=1.1.1'
def PREFIX = Paths.get('/foo/bar')
Expand All @@ -260,6 +260,23 @@ def 'should create conda env with options - using mamba' () {
result == PREFIX
}

def 'should create conda env with channels' () {
given:
def ENV = 'bwa=1.1.1'
def PREFIX = Paths.get('/foo/bar')
and:
def cache = Spy(new CondaCache(new CondaConfig([channels:['bioconda','defaults']])))

when:
def result = cache.createLocalCondaEnv0(ENV, PREFIX)
then:
1 * cache.isYamlFilePath(ENV)
1 * cache.isTextFilePath(ENV)
0 * cache.makeAbsolute(_)
1 * cache.runCommand("conda create --mkdir --yes --quiet --prefix /foo/bar -c bioconda -c defaults bwa=1.1.1") >> null
result == PREFIX
}

def 'should create a conda env with a yaml file' () {

given:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,23 @@ class CondaConfigTest extends Specification {
true | [enabled: true] | [NXF_CONDA_ENABLED: true]
}


@Unroll
def 'should check channels options'() {
given:
def conda = new CondaConfig(CONFIG, [:])
expect:
conda.getChannels() == EXPECTED

where:
EXPECTED | CONFIG
[] | [:]
['bioconda'] | [channels:'bioconda']
['bioconda'] | [channels:['bioconda']]
and:
['this','that','other'] | [channels:'this,that,other']
['this','that','other'] | [channels:'this, that ,other']
and:
['this','that','other'] | [channels:['this','that','other']]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class WaveClient {

private static Logger log = LoggerFactory.getLogger(WaveClient)

private static final List<String> DEFAULT_CONDA_CHANNELS = ['defaults', 'conda-forge']
pditommaso marked this conversation as resolved.
Show resolved Hide resolved

final private HttpClient httpClient

final private WaveConfig config
Expand All @@ -79,12 +81,15 @@ class WaveClient {

private CookieManager cookieManager

private List<String> condaChannels

WaveClient(Session session) {
this.session = session
this.config = new WaveConfig(session.config.wave as Map ?: Collections.emptyMap(), SysEnv.get())
this.fusion = new FusionConfig(session.config.fusion as Map ?: Collections.emptyMap(), SysEnv.get())
this.tower = new TowerConfig(session.config.tower as Map ?: Collections.emptyMap(), SysEnv.get())
this.endpoint = config.endpoint()
this.condaChannels = session.getCondaConfig()?.getChannels() ?: DEFAULT_CONDA_CHANNELS
log.debug "Wave server endpoint: ${endpoint}"
this.packer = new Packer()
// create cache
Expand Down Expand Up @@ -400,10 +405,11 @@ class WaveClient {
}

protected String condaRecipeToDockerFile(String recipe) {
def channelsOpts = condaChannels.collect(it -> "-c $it").join(' ')
def result = """\
FROM ${config.condaOpts().mambaImage}
RUN \\
micromamba install -y -n base -c defaults -c conda-forge \\
micromamba install -y -n base $channelsOpts \\
$recipe \\
&& micromamba clean -a -y
""".stripIndent()
Expand Down