Commit c3e6d3d0 authored by Romain Reuillon's avatar Romain Reuillon
Browse files

Merge branch 'master' into 9-dev

parents 9b8e4869 0a7b31b0
Pipeline #324 failed with stage
in 5 minutes and 42 seconds
package org.openmole.plugin.task.python
import org.openmole.core.context.{ Context, Val }
import monocle.macros._
import org.openmole.core.context.{Context, Val}
import org.openmole.core.dsl._
import org.openmole.core.dsl.extension._
import org.openmole.core.fileservice.FileService
......@@ -9,16 +10,35 @@ import org.openmole.core.networkservice.NetworkService
import org.openmole.core.preference.Preference
import org.openmole.core.threadprovider.ThreadProvider
import org.openmole.core.workflow.builder._
import org.openmole.core.workflow.task.TaskExecutionContext
import org.openmole.core.workflow.tools.OptionalArgument
import org.openmole.core.workspace.{ NewFile, Workspace }
import org.openmole.plugin.task.container.HostFile
import org.openmole.core.workflow.validation.ValidateTask
import org.openmole.core.workspace.{NewFile, Workspace}
import org.openmole.plugin.task.container.{HostFile, HostFiles}
import org.openmole.plugin.task.external._
import org.openmole.plugin.task.udocker._
import org.openmole.plugin.tool.json._
import org.openmole.tool.outputredirection.OutputRedirection
import org.openmole.plugin.task.container
import org.openmole.plugin.task.systemexec._
object PythonTask {
implicit def isTask: InputOutputBuilder[PythonTask] = InputOutputBuilder(PythonTask.config)
implicit def isExternal: ExternalBuilder[PythonTask] = ExternalBuilder(PythonTask.external)
implicit def isInfo = InfoBuilder(info)
implicit def isMapped = MappedInputOutputBuilder(PythonTask.mapped)
implicit def isBuilder = new ReturnValue[PythonTask] with ErrorOnReturnValue[PythonTask] with StdOutErr[PythonTask] with EnvironmentVariables[PythonTask] with HostFiles[PythonTask] with WorkDirectory[PythonTask] { builder
override def returnValue = PythonTask.returnValue
override def errorOnReturnValue = PythonTask.errorOnReturnValue
override def stdOut = PythonTask.stdOut
override def stdErr = PythonTask.stdErr
override def environmentVariables = PythonTask.uDocker composeLens UDockerArguments.environmentVariables
override def hostFiles = PythonTask.uDocker composeLens UDockerArguments.hostFiles
override def workDirectory = PythonTask.uDocker composeLens UDockerArguments.workDirectory
}
// could to make distinct image for python 2 and 3
def dockerImage(major: Int) = DockerImage("python")
......@@ -28,7 +48,6 @@ object PythonTask {
(effintsall ++ libraries.map { l "pip"+major+" install " + l }).toVector
}
def apply(
script: RunnableScript,
major: Int = 3,
......@@ -43,9 +62,7 @@ object PythonTask {
stdOut: OptionalArgument[Val[String]] = None,
stdErr: OptionalArgument[Val[String]] = None)(implicit name: sourcecode.Name, definitionScope: DefinitionScope, newFile: NewFile, workspace: Workspace, preference: Preference, fileService: FileService, threadProvider: ThreadProvider, outputRedirection: OutputRedirection, networkService: NetworkService) = {
lazy val containerPoolKey = UDockerTask.newCacheKey
val udocker =
val uDocker =
UDockerTask.createUDocker(
dockerImage(major),
install = installCommands(install, libraries,major),
......@@ -57,7 +74,41 @@ object PythonTask {
workDirectory = workDirectory,
environmentVariables = environmentVariables.toVector)
Task("PythonTask") { p
new PythonTask(
script = script,
uDocker,
errorOnReturnValue = errorOnReturnValue,
returnValue = returnValue,
stdOut = stdOut,
stdErr = stdErr,
config = InputOutputConfig(),
external = External(),
info = InfoConfig(),
mapped = MappedInputOutputConfig(),
major = major
) set (outputs += (Seq(returnValue.option, stdOut.option, stdErr.option).flatten: _*))
}
}
@Lenses case class PythonTask(
script: RunnableScript,
uDocker: UDockerArguments,
errorOnReturnValue: Boolean,
returnValue: Option[Val[Int]],
stdOut: Option[Val[String]],
stdErr: Option[Val[String]],
config: InputOutputConfig,
external: External,
info: InfoConfig,
mapped: MappedInputOutputConfig,
major: Int) extends Task with ValidateTask {
lazy val containerPoolKey = UDockerTask.newCacheKey
override def validate = container.validateContainer(Vector(), uDocker.environmentVariables, external, inputs)
override def process(executionContext: TaskExecutionContext) = FromContext { p
import org.json4s.jackson.JsonMethods._
import p._
import Mapped.noFile
......@@ -106,15 +157,15 @@ object PythonTask {
def uDockerTask =
UDockerTask(
udocker,
uDocker,
commands = s"python${major.toString} $scriptName",
errorOnReturnValue = errorOnReturnValue,
returnValue = returnValue,
stdOut = stdOut,
stdErr = stdErr,
config = InputOutputConfig(),
external = External(),
info = InfoConfig(),
external = external,
info = info,
containerPoolKey = containerPoolKey) set (
resources += (scriptFile, scriptName, true),
resources += (jsonInputs, inputJSONName, true),
......@@ -123,15 +174,13 @@ object PythonTask {
Mapped.files(mapped.outputs).map { case m outputFiles +=[UDockerTask] (m.name, m.v) }
)
val resultContext = uDockerTask.process(p.executionContext).from(p.context)(p.random, p.newFile, p.fileService)
val resultContext = uDockerTask.process(executionContext).from(p.context)(p.random, p.newFile, p.fileService)
resultContext ++ readOutputJSON(resultContext(outputFile))
}
}
resultContext
} validate { _ Seq.empty } set (
outputs += (Seq(returnValue.option, stdOut.option, stdErr.option).flatten: _*)
)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment