Skip to content

Commit 53b76b4

Browse files
authored
Merge pull request #44 from jelmerk/simplify
remove duplication
2 parents 24bfb3e + 4592eb8 commit 53b76b4

File tree

4 files changed

+30
-32
lines changed

4 files changed

+30
-32
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ jobs:
5050
timeout_minutes: 5
5151
max_attempts: 3
5252
command: |
53-
sbt clean scalafmtCheckAll scapegoat blackCheck flake8 +test pyTest -DsparkVersion="$SPARK_VERSION"
53+
sbt clean scalafmtCheckAll scapegoat blackCheck flake8 +test pyTest

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: git config --global --add safe.directory '*'
4848
- name: Upload to Maven Central
4949
run: |
50-
sbt clean +publishSigned -DsparkVersion="$SPARK_VERSION" sonatypeBundleRelease
50+
sbt clean +publishSigned sonatypeBundleRelease
5151
5252
publish-pypi-artifacts:
5353
runs-on: ubuntu-latest

build.sbt

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import scalapb.compiler.Version.grpcJavaVersion
22
import scalapb.compiler.Version.scalapbVersion
33
import sys.process.*
44

5+
val hnswLibVersion = "1.2.1"
6+
val sparkVersion = settingKey[String]("Spark version")
7+
val venvFolder = settingKey[String]("Venv folder")
8+
val pythonVersion = settingKey[String]("Python version")
9+
10+
lazy val createVirtualEnv = taskKey[Unit]("Create venv")
11+
lazy val pyTest = taskKey[Unit]("Run the python tests")
12+
lazy val black = taskKey[Unit]("Run the black code formatter")
13+
lazy val blackCheck = taskKey[Unit]("Run the black code formatter in check mode")
14+
lazy val flake8 = taskKey[Unit]("Run the flake8 style enforcer")
15+
lazy val pyPackage = taskKey[Unit]("Package python code")
16+
lazy val pyPublish = taskKey[Unit]("Publish python code")
17+
518
ThisBuild / organization := "com.github.jelmerk"
619
ThisBuild / scalaVersion := "2.13.16"
720

@@ -42,6 +55,18 @@ ThisBuild / scalacOptions ++= Seq(
4255

4356
ThisBuild / versionScheme := Some("early-semver")
4457

58+
ThisBuild / sparkVersion := sys.props.get("sparkVersion").orElse(sys.env.get("SPARK_VERSION")).getOrElse("3.5.5")
59+
60+
ThisBuild / pythonVersion := "python3.9"
61+
62+
ThisBuild / crossScalaVersions := {
63+
if (sparkVersion.value >= "4.0.0") {
64+
Seq("2.13.16")
65+
} else {
66+
Seq("2.12.20", "2.13.16")
67+
}
68+
}
69+
4570
ThisBuild / resolvers += "Local Maven Repository" at "file://" + Path.userHome.absolutePath + "/.m2/repository"
4671

4772
ThisBuild / scapegoatIgnoredFiles := Seq(".*/src_managed/.*")
@@ -72,18 +97,6 @@ lazy val publishSettings = Seq(
7297
lazy val noPublishSettings =
7398
publish / skip := true
7499

75-
val hnswLibVersion = "1.2.1"
76-
val sparkVersion = settingKey[String]("Spark version")
77-
val venvFolder = settingKey[String]("Venv folder")
78-
val pythonVersion = settingKey[String]("Python version")
79-
80-
lazy val createVirtualEnv = taskKey[Unit]("Create venv")
81-
lazy val pyTest = taskKey[Unit]("Run the python tests")
82-
lazy val black = taskKey[Unit]("Run the black code formatter")
83-
lazy val blackCheck = taskKey[Unit]("Run the black code formatter in check mode")
84-
lazy val flake8 = taskKey[Unit]("Run the flake8 style enforcer")
85-
lazy val pyPackage = taskKey[Unit]("Package python code")
86-
lazy val pyPublish = taskKey[Unit]("Publish python code")
87100

88101
lazy val root = (project in file("."))
89102
.aggregate(uberJar, cosmetic)
@@ -93,13 +106,6 @@ lazy val uberJar = (project in file("hnswlib-spark"))
93106
.settings(
94107
name := s"hnswlib-spark-uberjar_${sparkVersion.value.split('.').take(2).mkString("_")}",
95108
noPublishSettings,
96-
crossScalaVersions := {
97-
if (sparkVersion.value >= "4.0.0") {
98-
Seq("2.13.16")
99-
} else {
100-
Seq("2.12.20", "2.13.16")
101-
}
102-
},
103109
autoScalaLibrary := false,
104110
Compile / unmanagedResourceDirectories += baseDirectory.value / "src" / "main" / "python",
105111
Compile / unmanagedResources / includeFilter := {
@@ -154,9 +160,7 @@ lazy val uberJar = (project in file("hnswlib-spark"))
154160
Compile / PB.targets := Seq(
155161
scalapb.gen() -> (Compile / sourceManaged).value / "scalapb"
156162
),
157-
sparkVersion := sys.props.getOrElse("sparkVersion", "3.5.5"),
158163
venvFolder := s"${baseDirectory.value}/.venv",
159-
pythonVersion := "python3.9",
160164
createVirtualEnv := {
161165
val ret = (
162166
s"${pythonVersion.value} -m venv ${venvFolder.value}" #&&
@@ -243,13 +247,5 @@ lazy val cosmetic = project
243247
Compile / packageDoc := (uberJar / Compile / packageDoc).value,
244248
Compile / packageSrc := (uberJar / Compile / packageSrc).value,
245249
autoScalaLibrary := false,
246-
crossScalaVersions := {
247-
if (sparkVersion.value >= "4.0.0") {
248-
Seq("2.13.16")
249-
} else {
250-
Seq("2.12.20", "2.13.16")
251-
}
252-
},
253-
sparkVersion := sys.props.getOrElse("sparkVersion", "3.5.5"),
254250
publishSettings
255251
)

project/plugins.sbt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
66
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.8")
77
addSbtPlugin("com.sksamuel.scapegoat" %% "sbt-scapegoat" % "1.2.13")
88

9-
if (sys.props.get("sparkVersion").exists(_.startsWith("4."))) {
9+
val sparkVersion = sys.props.get("sparkVersion").orElse(sys.env.get("SPARK_VERSION")).getOrElse("3.5.5")
10+
11+
if (sparkVersion.startsWith("4.")) {
1012
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.17"
1113
} else {
1214
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.11"

0 commit comments

Comments
 (0)