-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic support for configuring anaconda environments for commands
- Loading branch information
Showing
4 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/groovy/bpipe/processors/CondaEnvContainerWrapper.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package bpipe.processors | ||
|
||
import bpipe.Command | ||
import bpipe.CommandProcessor | ||
import bpipe.Config | ||
import bpipe.ResourceUnit | ||
import bpipe.Utils | ||
import groovy.transform.CompileStatic | ||
import groovy.util.logging.Log | ||
|
||
@Log | ||
class CondaEnvContainerWrapper implements CommandProcessor { | ||
|
||
@CompileStatic | ||
@Override | ||
public void transform(Command command, List<ResourceUnit> resources) { | ||
if(!command.processedConfig.containsKey('conda_env')) | ||
return | ||
|
||
String condaEnv = (String)command.processedConfig.conda_env | ||
|
||
Map<String,Object> config = (Map<String,Object>)command.processedConfig | ||
|
||
String shell = config.getOrDefault('shell', '/bin/bash') | ||
|
||
// Crude but works for most shell setups | ||
String shellType = shell.tokenize("/")[-1] | ||
|
||
String conda = Utils.resolveExe("conda", "conda") | ||
|
||
String prefix = | ||
""" | ||
$conda info --envs | ||
export SHELL="$shell"; eval "\$('$conda' 'shell.${shellType}' 'hook' 2> /dev/null)"; conda activate $condaEnv ; | ||
""".stripIndent() | ||
|
||
log.info "Configuring conda environment using command prefix: $prefix" | ||
|
||
command.command = prefix + command.command | ||
} | ||
} |