diff --git a/tools/src/com/github/condaincubator/condaenvbuilder/api/CondaStep.scala b/tools/src/com/github/condaincubator/condaenvbuilder/api/CondaStep.scala index ad5a462..6292db4 100644 --- a/tools/src/com/github/condaincubator/condaenvbuilder/api/CondaStep.scala +++ b/tools/src/com/github/condaincubator/condaenvbuilder/api/CondaStep.scala @@ -1,7 +1,6 @@ package com.github.condaincubator.condaenvbuilder.api -import com.github.condaincubator.condaenvbuilder.api.CondaStep.Channel -import com.github.condaincubator.condaenvbuilder.api.Platform.Platform +import com.github.condaincubator.condaenvbuilder.api.CondaStep.{Channel, Platform} import io.circe.Decoder.Result import io.circe.syntax._ import io.circe.{Decoder, Encoder, HCursor, Json} @@ -67,6 +66,7 @@ case class CondaStep(channels: Seq[Channel]=Seq.empty, requirements: Seq[Require */ object CondaStep { type Channel = String + type Platform = String import Encoders.EncodeRequirement @@ -74,9 +74,9 @@ object CondaStep { def encoder: Encoder[CondaStep] = new Encoder[CondaStep] { final def apply(step: CondaStep): Json = { val fields = ArrayBuffer[(String, Json)]() + if (step.platforms.nonEmpty) fields.append(("platforms", Json.fromValues(step.platforms.map(_.asJson)))) fields.append(("channels", Json.fromValues(step.channels.map(_.asJson)))) fields.append(("requirements", Json.fromValues(step.requirements.map(_.asJson)))) - if (step.platforms.nonEmpty) fields.append(("platforms", Json.fromValues(step.platforms.map(_.asJson)))) Json.obj(fields.toSeq:_*) } } @@ -88,6 +88,11 @@ object CondaStep { final def apply(c: HCursor): Decoder.Result[CondaStep] = { val keys: Seq[String] = c.keys.map(_.toSeq).getOrElse(Seq.empty) + val platformResults: Result[Seq[Platform]] = { + if (keys.contains("platforms")) c.downField("platforms").as[Seq[Platform]] + else Right(Seq.empty) + } + val channelsResults: Result[Seq[String]] = { if (keys.contains("channels")) c.downField("channels").as[Seq[String]] else Right(Seq.empty) @@ -98,10 +103,6 @@ object CondaStep { else Right(Seq.empty) } - val platformResults: Result[Seq[Platform]] = { - if (keys.contains("platforms")) c.downField("platforms").as[Seq[Platform]] - else Right(Seq.empty) - } for { channels <- channelsResults diff --git a/tools/src/com/github/condaincubator/condaenvbuilder/api/Platform.scala b/tools/src/com/github/condaincubator/condaenvbuilder/api/Platform.scala deleted file mode 100644 index f239278..0000000 --- a/tools/src/com/github/condaincubator/condaenvbuilder/api/Platform.scala +++ /dev/null @@ -1,6 +0,0 @@ -package com.github.condaincubator.condaenvbuilder.api - -/** The name of the platform (e.g. linux-32, linux-armv7l, win-64, osx-arm64) */ -object Platform { - type Platform = String -} diff --git a/tools/src/com/github/condaincubator/condaenvbuilder/io/BuildWriter.scala b/tools/src/com/github/condaincubator/condaenvbuilder/io/BuildWriter.scala index 72d207b..5c2fc64 100644 --- a/tools/src/com/github/condaincubator/condaenvbuilder/io/BuildWriter.scala +++ b/tools/src/com/github/condaincubator/condaenvbuilder/io/BuildWriter.scala @@ -1,15 +1,15 @@ package com.github.condaincubator.condaenvbuilder.io -import java.io.PrintWriter -import java.nio.file.Paths import com.fulcrumgenomics.commons.CommonsDef.{DirPath, FilePath} import com.fulcrumgenomics.commons.io.Io import com.fulcrumgenomics.commons.util.{LazyLogging, Logger} -import com.github.condaincubator.condaenvbuilder.cmdline.CondaEnvironmentBuilderTool import com.github.condaincubator.condaenvbuilder.CondaEnvironmentBuilderDef.PathToYaml import com.github.condaincubator.condaenvbuilder.api.CodeStep.Command import com.github.condaincubator.condaenvbuilder.api.{CodeStep, CondaStep, Environment, PipStep} -import com.github.condaincubator.condaenvbuilder.api.CondaStep +import com.github.condaincubator.condaenvbuilder.cmdline.CondaEnvironmentBuilderTool + +import java.io.PrintWriter +import java.nio.file.Paths /** Companion to [[BuildWriter]]. */ object BuildWriter { @@ -111,6 +111,12 @@ case class BuildWriter(environment: Environment, val writer = new PrintWriter(Io.toWriter(environmentYaml)) writer.println(f"name: ${environment.name}") + condaStep.foreach { step => + if (step.platforms.nonEmpty) { + writer.println("platforms:") + step.platforms.foreach { platform => writer.println(f" - $platform") } + } + } condaStep.foreach { step => if (step.channels.nonEmpty) { writer.println("channels:") diff --git a/tools/src/com/github/condaincubator/condaenvbuilder/tools/Assemble.scala b/tools/src/com/github/condaincubator/condaenvbuilder/tools/Assemble.scala index 848d928..e23aecf 100644 --- a/tools/src/com/github/condaincubator/condaenvbuilder/tools/Assemble.scala +++ b/tools/src/com/github/condaincubator/condaenvbuilder/tools/Assemble.scala @@ -1,16 +1,14 @@ package com.github.condaincubator.condaenvbuilder.tools -import java.nio.file.Files import com.fulcrumgenomics.commons.CommonsDef.DirPath import com.fulcrumgenomics.commons.io.Io import com.fulcrumgenomics.sopt.{arg, clp} +import com.github.condaincubator.condaenvbuilder.CondaEnvironmentBuilderDef._ import com.github.condaincubator.condaenvbuilder.api.{Environment, Spec} import com.github.condaincubator.condaenvbuilder.cmdline.{ClpGroups, CondaEnvironmentBuilderTool} -import com.github.condaincubator.condaenvbuilder.CondaEnvironmentBuilderDef._ import com.github.condaincubator.condaenvbuilder.io.{BuildWriter, SpecParser} -import com.github.condaincubator.condaenvbuilder.api.Spec -import com.github.condaincubator.condaenvbuilder.cmdline.CondaEnvironmentBuilderTool -import com.github.condaincubator.condaenvbuilder.io.BuildWriter + +import java.nio.file.Files @clp(description = diff --git a/tools/src/com/github/condaincubator/condaenvbuilder/tools/Solve.scala b/tools/src/com/github/condaincubator/condaenvbuilder/tools/Solve.scala index 283868f..ed719b1 100644 --- a/tools/src/com/github/condaincubator/condaenvbuilder/tools/Solve.scala +++ b/tools/src/com/github/condaincubator/condaenvbuilder/tools/Solve.scala @@ -1,19 +1,15 @@ package com.github.condaincubator.condaenvbuilder.tools import cats.syntax.either._ -import com.fulcrumgenomics.commons.CommonsDef -import com.fulcrumgenomics.commons.CommonsDef.{DirPath, FilePath, SafelyClosable} +import com.fulcrumgenomics.commons.CommonsDef.{DirPath, SafelyClosable} import com.fulcrumgenomics.commons.io.Io import com.fulcrumgenomics.commons.util.Logger import com.fulcrumgenomics.sopt.{arg, clp} -import com.github.condaincubator.condaenvbuilder.api.{CodeStep, CondaStep, Environment, PipStep, Requirement, Spec} -import com.github.condaincubator.condaenvbuilder.cmdline.{ClpGroups, CondaEnvironmentBuilderTool} -import com.github.condaincubator.condaenvbuilder.io.{BuildWriter, SpecParser, SpecWriter} import com.github.condaincubator.condaenvbuilder.CondaEnvironmentBuilderDef._ -import com.github.condaincubator.condaenvbuilder.api.CondaStep.Channel +import com.github.condaincubator.condaenvbuilder.api.CondaStep.{Channel, Platform} import com.github.condaincubator.condaenvbuilder.api._ -import com.github.condaincubator.condaenvbuilder.cmdline.CondaEnvironmentBuilderTool -import com.github.condaincubator.condaenvbuilder.io.BuildWriter +import com.github.condaincubator.condaenvbuilder.cmdline.{ClpGroups, CondaEnvironmentBuilderTool} +import com.github.condaincubator.condaenvbuilder.io.{BuildWriter, SpecParser, SpecWriter} import io.circe.Decoder.Result import io.circe.{Decoder, DecodingFailure, HCursor, yaml} @@ -201,6 +197,7 @@ object Solve { private case class CondaEnvironment (name: String, + platforms: Seq[Platform], channels: Seq[Channel], conda: Seq[Requirement], pip: Seq[Requirement] @@ -213,10 +210,11 @@ private object CondaEnvironment { def decoder: Decoder[CondaEnvironment] = new Decoder[CondaEnvironment] { final def apply(c: HCursor): Decoder.Result[CondaEnvironment] = { // Get the keys at this level - val keys = c.keys.map(_.toSeq).getOrElse(Seq.empty) - val nameResult = c.downField("name").as[String] - val channelsResult = if (keys.contains("channels")) c.downField("channels").as[Seq[String]] else Right(Seq.empty[String]) - val dependencies = c.downField("dependencies").values.toSeq.flatten + val keys = c.keys.map(_.toSeq).getOrElse(Seq.empty) + val nameResult = c.downField("name").as[String] + val platformsResult = if (keys.contains("platforms")) c.downField("platforms").as[Seq[String]] else Right(Seq.empty[String]) + val channelsResult = if (keys.contains("channels")) c.downField("channels").as[Seq[String]] else Right(Seq.empty[String]) + val dependencies = c.downField("dependencies").values.toSeq.flatten val condaResult: Result[Seq[Requirement]] = { val results = dependencies.filterNot(_.isObject).map(_.as[Requirement]) results.collectFirst { case left: Left[DecodingFailure, Requirement] => left } match { @@ -231,15 +229,17 @@ private object CondaEnvironment { for { name <- nameResult + platforms <- platformsResult channels <- channelsResult conda <- condaResult pip <- pipResult } yield { CondaEnvironment( - name = name, - channels = channels, - conda = conda, - pip = pip + name = name, + platforms = platforms, + channels = channels, + conda = conda, + pip = pip ) } } diff --git a/tools/test/src/com/github/condaincubator/condaenvbuilder/api/CondaStepTest.scala b/tools/test/src/com/github/condaincubator/condaenvbuilder/api/CondaStepTest.scala index 1207fd6..5685155 100644 --- a/tools/test/src/com/github/condaincubator/condaenvbuilder/api/CondaStepTest.scala +++ b/tools/test/src/com/github/condaincubator/condaenvbuilder/api/CondaStepTest.scala @@ -18,20 +18,24 @@ object CondaStepTest extends UnitSpec { // one channel, one requirement, one platform (api.CondaStep(channels=Seq("some channel"), requirements=Seq("a==1").reqs, platforms=Seq("linux-32")), { """{ + | "platforms" : [ + | "linux-32" + | ], | "channels" : [ | "some channel" | ], | "requirements" : [ | "a==1" - | ], - | "platforms" : [ - | "linux-32" | ] |}""".stripMargin }), // multiple channels, requirements, and platforms (api.CondaStep(channels=Seq("channel 1", "channel 2"), requirements=Seq("a==1", "b==2").reqs, platforms=Seq("linux-32", "win-32")), { """{ + | "platforms" : [ + | "linux-32", + | "win-32" + | ], | "channels" : [ | "channel 1", | "channel 2" @@ -39,10 +43,6 @@ object CondaStepTest extends UnitSpec { | "requirements" : [ | "a==1", | "b==2" - | ], - | "platforms" : [ - | "linux-32", - | "win-32" | ] |}""".stripMargin }), diff --git a/tools/test/src/com/github/condaincubator/condaenvbuilder/tools/ToolsTest.scala b/tools/test/src/com/github/condaincubator/condaenvbuilder/tools/ToolsTest.scala index 000b28c..3f66c86 100644 --- a/tools/test/src/com/github/condaincubator/condaenvbuilder/tools/ToolsTest.scala +++ b/tools/test/src/com/github/condaincubator/condaenvbuilder/tools/ToolsTest.scala @@ -14,6 +14,8 @@ class ToolsTest extends UnitSpec { | defaults: | steps: | - conda: + | platforms: + | - linux-32 | channels: | - conda-forge | - bioconda @@ -24,8 +26,6 @@ class ToolsTest extends UnitSpec { | - python=3.6.10 | - samtools=1.10 | - yaml=0.1.7 - | platforms: - | - linux-32 | - pip: | requirements: | - defopt==5.1.0 @@ -77,14 +77,14 @@ class ToolsTest extends UnitSpec { | group: conda-env-builder | steps: | - conda: + | platforms: + | - linux-32 | channels: | - conda-forge | - bioconda | requirements: | - pybedtools=0.8.1 | - yaml=0.1.7 - | platforms: - | - linux-32 | - pip: | args: [] | requirements: @@ -99,37 +99,37 @@ class ToolsTest extends UnitSpec { | group: alignment | steps: | - conda: + | platforms: + | - linux-32 | channels: | - conda-forge | - bioconda | requirements: | - samtools=1.9 | - hisat2=2.2.0 - | platforms: - | - linux-32 | bwa: | group: alignment | steps: | - conda: + | platforms: + | - linux-32 | channels: | - conda-forge | - bioconda | requirements: | - samtools=1.9 | - bwa=0.7.17 - | platforms: - | - linux-32 | samtools: | group: alignment | steps: | - conda: + | platforms: + | - linux-32 | channels: | - conda-forge | - bioconda | requirements: - | - samtools=1.9 - | platforms: - | - linux-32""".stripMargin + | - samtools=1.9""".stripMargin } val tabulatedString: String = { @@ -155,41 +155,43 @@ class ToolsTest extends UnitSpec { | group: alignment | steps: | - conda: + | platforms: + | - linux-32 | channels: | - conda-forge | - bioconda | requirements: | - samtools=1.9 - | platforms: - | - linux-32 | bwa: | group: alignment | steps: | - conda: + | platforms: + | - linux-32 | channels: | - conda-forge | - bioconda | requirements: | - samtools=1.9 | - bwa=0.7.17 - | platforms: - | - linux-32 | hisat2: | group: alignment | steps: | - conda: + | platforms: + | - linux-32 | channels: | - conda-forge | - bioconda | requirements: | - samtools=1.9 | - hisat2=2.2.0 - | platforms: - | - linux-32 | conda-env-builder: | group: conda-env-builder | steps: | - conda: + | platforms: + | - linux-32 | channels: | - conda-forge | - bioconda @@ -197,8 +199,6 @@ class ToolsTest extends UnitSpec { | - pybedtools=0.8.1 | - yaml=0.1.7 | - pip==default - | platforms: - | - linux-32 | - pip: | args: [] | requirements: @@ -219,49 +219,49 @@ class ToolsTest extends UnitSpec { | group: alignment | steps: | - conda: + | platforms: + | - linux-32 | channels: | - conda-forge | - bioconda | requirements: | - samtools=1.9 - | platforms: - | - linux-32 | bwa: | group: alignment | steps: | - conda: + | platforms: + | - linux-32 | channels: | - conda-forge | - bioconda | requirements: | - samtools=1.9 | - bwa=0.7.17 - | platforms: - | - linux-32 | hisat2: | group: alignment | steps: | - conda: + | platforms: + | - linux-32 | channels: | - conda-forge | - bioconda | requirements: | - samtools=1.9 | - hisat2=2.2.0 - | platforms: - | - linux-32 | conda-env-builder: | group: conda-env-builder | steps: | - conda: + | platforms: + | - linux-32 | channels: | - conda-forge | - bioconda | requirements: | - pybedtools=0.8.1 | - yaml=0.1.7 - | platforms: - | - linux-32 | - pip: | args: [] | requirements: @@ -461,6 +461,8 @@ class ToolsTest extends UnitSpec { Io.readLines(bwaYamlPath).mkString("\n") shouldBe { """name: bwa + |platforms: + | - linux-32 |channels: | - conda-forge | - bioconda