[go: nahoru, domu]

Skip to content

Commit

Permalink
bump scala
Browse files Browse the repository at this point in the history
  • Loading branch information
zy4 committed Nov 23, 2021
1 parent 38a09fe commit bc2cfc9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ inThisBuild(
organizationName := "Dept. Protein Evolution, Max Planck Institute for Developmental Biology",
startYear := Some(2018),
licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0")),
scalaVersion := "2.13.6"
scalaVersion := "2.13.7"
)
)

Expand Down Expand Up @@ -43,7 +43,7 @@ lazy val jobs = (project in file("modules/jobs"))
.enablePlugins(PlayScala)
.dependsOn(common, auth, base, clusterApi, tel, tools, ui, util, user, statistics)
.settings(scalacOptions += "-Ymacro-annotations")
.settings(addCompilerPlugin(("org.typelevel" %% "kind-projector" % "0.13.0").cross(CrossVersion.full)))
.settings(addCompilerPlugin(("org.typelevel" %% "kind-projector" % "0.13.2").cross(CrossVersion.full)))
.disablePlugins(PlayLayoutPlugin)

lazy val user = (project in file("modules/user"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ import scala.util.matching.Regex

trait TELRegex {

// For translating the runscript template into an executable instance
val replaceString: Regex = """%([A-Za-z_\.]+)""".r("expression") // TODO Not needed anymore, remove

// A constant string starts with a percent sign
final val envString: Regex = """%([A-Z]+)""".r("constant")
final val envString: Regex = """%([A-Z]+)""".r
// A parameter String in an runscript starts with a percent sign, a parameter name and a representation
final val parameterString: Regex = """%([a-z_]+)\.([a-z_]+)""".r("paramName", "repr")
final val parameterString
: Regex = """%([a-z_]+)\.([a-z_]+)""".r // ("paramName", "repr")

val runscriptString: Regex = """%r""".r
val regexJobID: Regex = """%JOBID""".r
val regexPort: Regex = """%PORT""".r
val regexJobID: Regex = """%JOBID""".r
val regexPort: Regex = """%PORT""".r
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package de.proteinevolution.tel.execution

import javax.inject.{ Inject, Named, Singleton }
import javax.inject.{Inject, Named, Singleton}
import better.files._
import de.proteinevolution.tel.TELRegex
import java.nio.file.attribute.PosixFilePermission
Expand All @@ -30,7 +30,9 @@ import de.proteinevolution.tel.execution.WrapperExecutionFactory.{
import scala.sys.process.Process

@Singleton
class WrapperExecutionFactory @Inject() (@Named("wrapperPath") wrapperPath: String) extends TELRegex {
class WrapperExecutionFactory @Inject()(
@Named("wrapperPath") wrapperPath: String)
extends TELRegex {

private final val filePermissions = Set(
PosixFilePermission.OWNER_EXECUTE,
Expand All @@ -44,7 +46,8 @@ class WrapperExecutionFactory @Inject() (@Named("wrapperPath") wrapperPath: Stri
// Accept the content of a runscript and used the Wrapper script to produce the Registered Execution
// One might offer different Methods to create a Pending Execution to avoid the need to pass the content
// of the Runscript directly as String
def getInstance(content: String, env: Map[String, String]): PendingExecution = {
def getInstance(content: String,
env: Map[String, String]): PendingExecution = {

val register = { file: File =>
val runscript = (file / "runscript.sh").write(content)
Expand All @@ -56,7 +59,8 @@ class WrapperExecutionFactory @Inject() (@Named("wrapperPath") wrapperPath: Stri

wrapper.write(
envString.replaceAllIn(
runscriptString.replaceAllIn(wrapperPath.toFile.contentAsString, runscript.pathAsString),
runscriptString.replaceAllIn(wrapperPath.toFile.contentAsString,
runscript.pathAsString),
m => env.getOrElse(m.group("constant"), "")
)
)
Expand Down Expand Up @@ -84,8 +88,9 @@ class WrapperExecutionFactory @Inject() (@Named("wrapperPath") wrapperPath: Stri
object WrapperExecutionFactory {

sealed trait Execution
case class PendingExecution(register: File => RegisteredExecution) extends Execution
case class RegisteredExecution(run: () => RunningExecution) extends Execution
case class RunningExecution(terminate: () => Boolean) extends Execution
case class PendingExecution(register: File => RegisteredExecution)
extends Execution
case class RegisteredExecution(run: () => RunningExecution) extends Execution
case class RunningExecution(terminate: () => Boolean) extends Execution

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import scala.collection.mutable
import scala.util.matching.Regex

/**
* Represents one particular runscript, specified by the path of the corresponding file. Instances should be created via
* the companion object.
*/
* Represents one particular runscript, specified by the path of the corresponding file. Instances should be created via
* the companion object.
*/
class Runscript(files: Seq[File]) extends TELRegex with Logging {

val parameters: Seq[(String, Evaluation)] = parameterString
Expand All @@ -40,7 +40,9 @@ class Runscript(files: Seq[File]) extends TELRegex with Logging {
m.group("repr") match {
// TODO Constraints are not yet supported, currently all arguments are valid
case "path" =>
ValidArgument(new FileRepresentation(executionContext.getFile(paramName, value.inner().toString)))
ValidArgument(
new FileRepresentation(
executionContext.getFile(paramName, value.inner().toString)))
case "content" => ValidArgument(new LiteralRepresentation(value))
}
}
Expand All @@ -50,22 +52,23 @@ class Runscript(files: Seq[File]) extends TELRegex with Logging {
type Condition = (String, RType => Boolean, String, RType => Boolean)

final val parameterNames: Seq[String] =
parameters.map(_._1).distinct // Names of the parameters that need to be supplied
parameters
.map(_._1)
.distinct // Names of the parameters that need to be supplied

// Special fields to put the runscript into a larger context

private case class Replacer(arguments: Seq[(String, ValidArgument)]) {
private var counter = -1
def apply(m: Regex.Match): String = {
m.groupNames.foreach(s =>
logger.debug(s)
) // just use m because of https://stackoverflow.com/questions/43964571/scala-2-12-2-emits-a-ton-of-useless-warning-parameter-value-in-method
// m.groupNames.foreach(s => logger.debug(s)) // just use m because of https://stackoverflow.com/questions/43964571/scala-2-12-2-emits-a-ton-of-useless-warning-parameter-value-in-method
counter += 1
arguments(counter)._2.representation.represent
}
}

private val translationSteps = mutable.Queue[String => String](_ => files.map(_.contentAsString).mkString("\n"))
private val translationSteps = mutable.Queue[String => String](_ =>
files.map(_.contentAsString).mkString("\n"))

// Translates A sequence of Arguments with the parameter names into a runnable runscript instance
def apply(arguments: Seq[(String, ValidArgument)]): String = {
Expand Down Expand Up @@ -96,8 +99,8 @@ object Runscript extends TELRegex {
type Evaluation = (RType, ExecutionContext) => Argument

/**
* Reads the lines of a runscript file and returns a new runscript instance
*/
* Reads the lines of a runscript file and returns a new runscript instance
*/
def apply(files: Seq[File]): Runscript = new Runscript(files)

}

0 comments on commit bc2cfc9

Please sign in to comment.