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 fallback command for micromamba #4302

Merged
merged 15 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
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 @@ -285,7 +285,8 @@ class CondaCache {
def cmd
if( isYamlFilePath(condaEnv) ) {
final target = isYamlUriPath(condaEnv) ? condaEnv : Escape.path(makeAbsolute(condaEnv))
cmd = "${binaryName} env create --prefix ${Escape.path(prefixPath)} --file ${target}"
final yesOpt = binaryName == 'micromamba' ? '--yes ' : ''
cmd = "${binaryName} env create ${yesOpt}--prefix ${Escape.path(prefixPath)} --file ${target}"
}
else if( isTextFilePath(condaEnv) ) {
cmd = "${binaryName} create ${opts}--yes --quiet --prefix ${Escape.path(prefixPath)} --file ${Escape.path(makeAbsolute(condaEnv))}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,13 @@ class BashWrapperBuilder {
private String getCondaActivateSnippet() {
if( !condaEnv )
return null
def result = "# conda environment\n"
result += 'source $(conda info --json | awk \'/conda_prefix/ { gsub(/"|,/, "", $2); print $2 }\')'
result += "/bin/activate ${Escape.path(condaEnv)}\n"
return result
def command = 'source $(conda info --json | awk \'/conda_prefix/ { gsub(/"|,/, "", $2); print $2 }\')/bin/activate'
if( condaConfig && condaConfig.useMicromamba() )
command = 'eval "$(micromamba shell hook --shell bash)" && micromamba activate'
return """\
# conda environment
${command} ${Escape.path(condaEnv)}
""".stripIndent()
}

private String getSpackActivateSnippet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package nextflow.processor

import nextflow.conda.CondaConfig

import java.nio.file.Path

import groovy.transform.CompileStatic
Expand Down Expand Up @@ -48,6 +50,8 @@ class TaskBean implements Serializable, Cloneable {

Path condaEnv

CondaConfig condaConfig

Path spackEnv

List<String> moduleNames
Expand Down Expand Up @@ -131,6 +135,7 @@ class TaskBean implements Serializable, Cloneable {
this.environment = task.getEnvironment()

this.condaEnv = task.getCondaEnv()
this.condaConfig = task.getCondaConfig()
this.spackEnv = task.getSpackEnv()
this.moduleNames = task.config.getModule()
this.shell = task.config.getShell() ?: BashWrapperBuilder.BASH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package nextflow.processor

import nextflow.conda.CondaConfig

import java.nio.file.FileSystems
import java.nio.file.NoSuchFileException
import java.nio.file.Path
Expand Down Expand Up @@ -967,5 +969,9 @@ class TaskRun implements Cloneable {
TaskBean toTaskBean() {
return new TaskBean(this)
}

CondaConfig getCondaConfig() {
return processor.session.getCondaConfig()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package nextflow.executor

import nextflow.conda.CondaConfig

import java.nio.file.FileSystemException
import java.nio.file.Files
import java.nio.file.Path
Expand Down Expand Up @@ -775,13 +777,20 @@ class BashWrapperBuilderTest extends Specification {

when:
def CONDA = Paths.get('/some/conda/env/foo')
binding = newBashWrapperBuilder(condaEnv: CONDA).makeBinding()
def config = new CondaConfig(['useMicromamba': MICROMAMBA])
binding = newBashWrapperBuilder(condaEnv: CONDA, condaConfig: config).makeBinding()
then:
binding.conda_activate == '''\
binding.conda_activate == RESULT
where:
MICROMAMBA | RESULT
false | '''\
# conda environment
source $(conda info --json | awk '/conda_prefix/ { gsub(/"|,/, "", $2); print $2 }')/bin/activate /some/conda/env/foo
source $(conda info --json | awk \'/conda_prefix/ { gsub(/"|,/, "", $2); print $2 }\')/bin/activate /some/conda/env/foo
'''.stripIndent()
true | '''\
# conda environment
eval "$(micromamba shell hook --shell bash)" && micromamba activate /some/conda/env/foo
'''.stripIndent()

}

def 'should create spack activate snippet' () {
Expand Down