Using SBT to manage projects containing both Scala and Python

In the current project, I created Python code to interact with a specific data source; I am now working on a version of Scala.

I rebuilt everything so that all of the Python code is in src/main/python in the SBT project for my Scala code, but it made me wonder: is there any good way to integrate project management between the two? To configure SBT so that I can run python distutils / sdist generation or create sphinx document as SBT tasks?

Or, in a more general sense: is there a standard method for starting arbitrary system tasks via SBT?

+6
source share
3 answers

From the docs ( http://www.scala-sbt.org/0.13/docs/Process.html ):

sbt includes a process library to simplify working with external processes. The library is accessible without import in the assembly of definitions and the interpreter launched using the consoleProject task.

To start an external command, follow it with an exclamation mark !:

 "find project -name *.jar" ! 
+1
source

To run Python unit tests of python code with SBT test tasks I did this in build.sbt :

 //define task that should be run with tests. val testPythonTask = TaskKey[Unit]("testPython", "Run python tests.") val command = "python3 -m unittest app_test.py" val workingDirectory = new File("python/working/directory") testPythonTask := { val s: TaskStreams = streams.value s.log.info("Executing task testPython") Process(command, // optional workingDirectory, // optional system variables "CLASSPATH" -> "path/to.jar", "OTHER_SYS_VAR" -> "other_value") ! s.log } //attach custom test task to default test tasks test in Test := { testPythonTask.value (test in Test).value } testOnly in Test := { testPythonTask.value (testOnly in Test).value } 
+1
source

You can create a python task that zips up the source code files. This example depends on the build task:

  lazy val pythonAssembly = TaskKey[Unit]("pythonAssembly", "Zips all files in src/main/python") lazy val pythonAssemblyTask = pythonAssembly := { val baseDir = sourceDirectory.value val targetDir = assembly.value.getParentFile.getParent val target = new File(targetDir + s"/python/rfu-api-client-python-${Commons.appVersion}.zip") val pythonBaseDir = new File(baseDir + "/main/python") val pythonFiles = Path.allSubpaths(pythonBaseDir) println("Zipping files in " + pythonBaseDir) pythonFiles foreach { case (_, s) => println(s) } IO.zip(pythonFiles, target) println(s"Created $target") 
0
source

Source: https://habr.com/ru/post/987098/


All Articles