-
Notifications
You must be signed in to change notification settings - Fork 24
/
python.sbt
31 lines (25 loc) · 1.06 KB
/
python.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// See https://stackoverflow.com/questions/30205003/using-sbt-to-manage-projects-that-contain-both-scala-and-python
import sbt.io.IO
import scala.sys.process.Process
val testPythonTask = TaskKey[Unit]("testPython", "Run Python tests")
testPythonTask := {
val taskStreams: TaskStreams = streams.value
taskStreams.log.info("Starting testPythonTask...")
val command = "pytest"
val mainDir = new File("./src/main/python")
val testDir = new File("./src/test/python")
val workDir = new File("./target/python")
taskStreams.log.info(s"Deleting workDir $workDir...")
IO.delete(workDir)
taskStreams.log.info(s"Copying mainDir $mainDir...")
IO.copyDirectory(mainDir, workDir)
taskStreams.log.info(s"Copying testDir $testDir...")
IO.copyDirectory(testDir, workDir)
taskStreams.log.info(s"Executing command $command...")
val result = Process(command, workDir) ! taskStreams.log
taskStreams.log.info("Stopping testPythonTask...")
val message = s"Result of testPythonTask was $result."
taskStreams.log.info(message)
if (result != 0)
sys.error(message)
}