-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] Assemble can use conda-lock to create the environment (#35)
* [feat] Assemble can use conda-lock to create the environment Miscellaneous: * [test] add more unit tests * [ci] add conda to github actions * [ci] add conda caching * [feat] move Process (previously used only by Solve) to it's own class * [feat] refactor BuildWriter to support building conda environments using both `conda env create` and `conda-lock` * [test] add a unit test for Solve; I could not get this to work on github actions, so it works locally only
- Loading branch information
Showing
13 changed files
with
529 additions
and
187 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
4 changes: 2 additions & 2 deletions
4
tools/src/com/github/condaincubator/condaenvbuilder/CondaEnvironmentBuilderDef.scala
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
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
73 changes: 73 additions & 0 deletions
73
tools/src/com/github/condaincubator/condaenvbuilder/io/CondaBuildWriter.scala
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,73 @@ | ||
package com.github.condaincubator.condaenvbuilder.io | ||
|
||
import com.fulcrumgenomics.commons.CommonsDef.{DirPath, FilePath} | ||
import com.fulcrumgenomics.commons.io.Io | ||
import com.fulcrumgenomics.commons.util.Logger | ||
import com.github.condaincubator.condaenvbuilder.CondaEnvironmentBuilderDef.PathToYaml | ||
import com.github.condaincubator.condaenvbuilder.api.Environment | ||
import com.github.condaincubator.condaenvbuilder.cmdline.CondaEnvironmentBuilderTool | ||
|
||
import java.io.PrintWriter | ||
|
||
|
||
/** Companion to [[CondaBuildWriter]]. */ | ||
object CondaBuildWriter extends BuildWriterConstants { | ||
|
||
/** Builds a new [[CondaBuildWriter]] for the given environment. | ||
* | ||
* @param environment the environment for which build files should be created. | ||
* @param output the output directory where build files should be created. | ||
* @param environmentYaml the path to use for the environment's conda YAML, otherwise `<output>/<env-name>.yml`. | ||
* @param condaBuildScript the path to use for the environment's conda build script, | ||
* otherwise `<output>/<env-name>.build-conda.sh`. | ||
* @param codeBuildScript the path to use for the environment's custom code build script, | ||
* otherwise `<output>/<env-name>.build-local.sh`. | ||
* @param condaEnvironmentDirectory the directory in which conda environments should be stored when created. | ||
* @return | ||
*/ | ||
def apply(environment: Environment, | ||
output: DirPath, | ||
environmentYaml: Option[PathToYaml] = None, | ||
condaBuildScript: Option[FilePath] = None, | ||
codeBuildScript: Option[FilePath] = None, | ||
condaEnvironmentDirectory: Option[DirPath] = None): CondaBuildWriter = { | ||
CondaBuildWriter( | ||
environment = environment, | ||
environmentYaml = environmentYaml.getOrElse(toEnvironmentYaml(environment, output)), | ||
condaBuildScript = condaBuildScript.getOrElse(toCondaBuildScript(environment, output)), | ||
codeBuildScript = codeBuildScript.getOrElse(toCodeBuildScript(environment, output)), | ||
condaEnvironmentDirectory = condaEnvironmentDirectory | ||
) | ||
} | ||
} | ||
|
||
|
||
/** Writer that is used to create the build scripts for the conda environments. | ||
* | ||
* The conda build script should be executed first, then the custom code build script. The conda environment | ||
* specification is stored in the given environment YAML path. | ||
* | ||
* @param environment the environment for which build files should be created. | ||
* @param environmentYaml the path to use for the environment's conda YAML. | ||
* @param condaBuildScript the path to use for the environment's conda build script | ||
* @param codeBuildScript the path to use for the environment's custom code build script | ||
* @param condaEnvironmentDirectory the directory in which conda environments should be stored when created. | ||
*/ | ||
case class CondaBuildWriter(environment: Environment, | ||
environmentYaml: PathToYaml, | ||
condaBuildScript: FilePath, | ||
codeBuildScript: FilePath, | ||
condaEnvironmentDirectory: Option[DirPath]) extends BuildWriter { | ||
|
||
private lazy val condaExecutable: String = if (CondaEnvironmentBuilderTool.UseMamba) "mamba" else "conda" | ||
|
||
/** Writes the conda build command. */ | ||
protected def writeCondaBuildCommand(writer: PrintWriter): Unit = { | ||
writer.write(f"$condaExecutable env create --force --verbose --quiet") | ||
condaEnvironmentDirectory match { | ||
case Some(pre) => writer.write(f" --prefix ${pre.toAbsolutePath}/${environment.name}") | ||
case None => writer.write(f" --name ${environment.name}") | ||
} | ||
writer.println(f" --file ${environmentYaml.toFile.getName}\n") | ||
} | ||
} |
Oops, something went wrong.