11import xerial .sbt .Sonatype ._
22import sbtassembly .AssemblyPlugin .autoImport ._
3+ import scala .sys .process ._
34
45lazy val versionNum : String = " 0.8.8"
6+ lazy val spark3Version : String = " 3.5.1"
7+ lazy val pythonVenvDir : String = System .getProperty(" java.io.tmpdir" ) + " /dataflint-pyspark-venv"
8+ lazy val pythonExec : String = " python3.11"
9+ val createPythonVenv = taskKey[Unit ](" Create Python venv and install pyspark test dependencies" )
510lazy val scala212 = " 2.12.20"
611lazy val scala213 = " 2.13.16"
712lazy val supportedScalaVersions = List (scala212, scala213)
@@ -35,8 +40,8 @@ lazy val plugin = (project in file("plugin"))
3540 } else {
3641 versionNum + " -SNAPSHOT"
3742 }),
38- libraryDependencies += " org.apache.spark" %% " spark-core" % " 3.5.1 " % " provided" ,
39- libraryDependencies += " org.apache.spark" %% " spark-sql" % " 3.5.1 " % " provided" ,
43+ libraryDependencies += " org.apache.spark" %% " spark-core" % spark3Version % " provided" ,
44+ libraryDependencies += " org.apache.spark" %% " spark-sql" % spark3Version % " provided" ,
4045 libraryDependencies += " com.amazonaws" % " aws-java-sdk-s3" % " 1.12.470" % " provided" ,
4146 libraryDependencies += " org.apache.iceberg" %% " iceberg-spark-runtime-3.5" % " 1.5.0" % " provided" ,
4247 libraryDependencies += " io.delta" %% " delta-spark" % " 3.2.0" % " provided" ,
@@ -61,12 +66,12 @@ lazy val pluginspark3 = (project in file("pluginspark3"))
6166 } else {
6267 versionNum + " -SNAPSHOT"
6368 }),
64- libraryDependencies += " org.apache.spark" %% " spark-core" % " 3.5.1 " % " provided" ,
65- libraryDependencies += " org.apache.spark" %% " spark-sql" % " 3.5.1 " % " provided" ,
69+ libraryDependencies += " org.apache.spark" %% " spark-core" % spark3Version % " provided" ,
70+ libraryDependencies += " org.apache.spark" %% " spark-sql" % spark3Version % " provided" ,
6671 libraryDependencies += " com.amazonaws" % " aws-java-sdk-s3" % " 1.12.470" % " provided" ,
6772 libraryDependencies += " org.apache.iceberg" %% " iceberg-spark-runtime-3.5" % " 1.5.0" % " provided" ,
6873 libraryDependencies += " io.delta" %% " delta-spark" % " 3.2.0" % " provided" ,
69-
74+
7075 // Assembly configuration to create fat JAR with common code
7176 assembly / assemblyJarName := s " ${name.value}_ ${scalaBinaryVersion.value}- ${version.value}.jar " ,
7277 // Exclude Scala library from assembly - Spark provides its own Scala runtime
@@ -96,8 +101,8 @@ lazy val pluginspark3 = (project in file("pluginspark3"))
96101 Compile / unmanagedResourceDirectories += (plugin / Compile / resourceDirectory).value,
97102 libraryDependencies += " org.scalatest" %% " scalatest-funsuite" % " 3.2.17" % Test ,
98103 libraryDependencies += " org.scalatest" %% " scalatest-shouldmatchers" % " 3.2.17" % Test ,
99- libraryDependencies += " org.apache.spark" %% " spark-core" % " 3.5.1 " % Test ,
100- libraryDependencies += " org.apache.spark" %% " spark-sql" % " 3.5.1 " % Test ,
104+ libraryDependencies += " org.apache.spark" %% " spark-core" % spark3Version % Test ,
105+ libraryDependencies += " org.apache.spark" %% " spark-sql" % spark3Version % Test ,
101106
102107 // Include source and resources from plugin directory for tests
103108 Test / unmanagedSourceDirectories += (plugin / Compile / sourceDirectory).value / " scala" ,
@@ -107,6 +112,24 @@ lazy val pluginspark3 = (project in file("pluginspark3"))
107112 // Run test suites sequentially — parallel suites share the SparkSession via getOrCreate()
108113 // and one suite stopping the session causes NPEs in concurrently-running suites
109114 Test / parallelExecution := false ,
115+ createPythonVenv := {
116+ val venvDir = new java.io.File (pythonVenvDir)
117+ val log = streams.value.log
118+ if (! venvDir.exists()) {
119+ log.info(s " Creating Python venv at $pythonVenvDir ... " )
120+ val rc = Process (Seq (pythonExec, " -m" , " venv" , pythonVenvDir)).!
121+ if (rc != 0 ) sys.error(s " Failed to create Python venv at $pythonVenvDir" )
122+ }
123+ val pip = s " $pythonVenvDir/bin/pip "
124+ log.info(s " Installing pyspark== $spark3Version pandas pyarrow into venv... " )
125+ val rc = Process (Seq (pip, " install" , " --quiet" , s " pyspark== $spark3Version" , " pandas" , " pyarrow" )).!
126+ if (rc != 0 ) sys.error(" pip install failed" )
127+ },
128+ Test / compile := (Test / compile).dependsOn(createPythonVenv).value,
129+ Test / testOnly := (Test / testOnly).dependsOn(createPythonVenv).evaluated,
130+ Test / javaOptions ++= Seq (
131+ s " -Ddataflint.projectRoot= ${baseDirectory.value.getParentFile.toString}" ,
132+ ),
110133 Test / javaOptions ++= {
111134 // --add-opens is not supported on Java 8 (spec version starts with "1.")
112135 if (sys.props(" java.specification.version" ).startsWith(" 1." )) Seq .empty
0 commit comments