forked from almond-sh/almond
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
269 lines (246 loc) · 6.26 KB
/
build.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import Settings._
inThisBuild(List(
organization := "sh.almond",
homepage := Some(url("https://github.com/almond-sh/almond")),
licenses := List("BSD-3-Clause" -> url("https://opensource.org/licenses/BSD-3-Clause")),
developers := List(
Developer(
"alexarchambault",
"Alexandre Archambault",
url("https://github.com/alexarchambault")
)
),
version := {
// Simple X.Y.Z-SNAPSHOT versions are easier to find once published locally
val forceSimpleVersion = sys.env
.get("FORCE_SIMPLE_VERSION")
.contains("1")
val onTravisCi = sys.env.exists(_._1.startsWith("TRAVIS_"))
val v = version.value
if ((forceSimpleVersion || !onTravisCi) && v.contains("+") && v.endsWith("-SNAPSHOT")) {
val base = v.takeWhile(_ != '+')
val elems = base.split('.')
val last = scala.util.Try(elems.last.toInt)
.toOption
.fold(elems.last)(n => (n + 1).toString)
val bumpedBase = (elems.init :+ last).mkString(".")
bumpedBase + "-SNAPSHOT"
} else
v
}
))
lazy val logger = project
.underShared
.settings(
shared,
testSettings,
libraryDependencies += Deps.scalaReflect.value
)
lazy val channels = project
.underShared
.dependsOn(logger)
.settings(
shared,
testSettings,
libraryDependencies ++= Seq(
Deps.fs2,
Deps.jeromq
)
)
lazy val protocol = project
.underShared
.dependsOn(channels)
.settings(
shared,
libraryDependencies += Deps.argonautShapeless
)
lazy val `interpreter-api` = project
.underShared
.settings(
shared
)
lazy val interpreter = project
.underShared
.dependsOn(`interpreter-api`, protocol)
.settings(
shared,
libraryDependencies ++= Seq(
Deps.metabrowseServer,
Deps.scalatags,
// picked by jboss-logging, that metabrowse transitively depends on
Deps.slf4jNop
),
testSettings
)
lazy val kernel = project
.underShared
.dependsOn(interpreter, interpreter % "test->test")
.settings(
shared,
testSettings,
libraryDependencies ++= Seq(
Deps.caseAppAnnotations,
Deps.fs2
)
)
lazy val test = project
.underShared
.dependsOn(`interpreter-api`)
.settings(
shared
)
lazy val `scala-kernel-api` = project
.underScala
.dependsOn(`interpreter-api`)
.settings(
shared,
crossVersion := CrossVersion.full,
generatePropertyFile("almond/almond.properties"),
generateDependenciesFile,
libraryDependencies ++= Seq(
Deps.ammoniteRepl,
Deps.jvmRepr
)
)
lazy val `scala-interpreter` = project
.underScala
.dependsOn(interpreter, `scala-kernel-api`, kernel % "test->test", `almond-rx` % Test)
.settings(
shared,
crossVersion := CrossVersion.full,
testSettings
)
lazy val `scala-kernel` = project
.underScala
.enablePlugins(PackPlugin)
.dependsOn(kernel, `scala-interpreter`)
.settings(
shared,
crossVersion := CrossVersion.full,
libraryDependencies += Deps.caseApp,
packExcludeArtifactTypes -= "source",
packModuleEntries ++= {
val report = updateClassifiers.value
for {
c <- report.configurations
m <- c.modules
(a, f) <- m.artifacts
if a.classifier.contains("sources")
} yield xerial.sbt.pack.PackPlugin.ModuleEntry(
m.module.organization,
m.module.name,
xerial.sbt.pack.VersionString(m.module.revision),
a.name,
a.classifier,
f
)
}
)
lazy val echo = project
.underModules
.dependsOn(kernel, test % Test)
.settings(
shared,
generatePropertyFile("almond/echo.properties"),
testSettings,
libraryDependencies += Deps.caseApp
)
lazy val `almond-spark` = project
.underScala
.dependsOn(`scala-kernel-api` % "provided")
.settings(
shared,
libraryDependencies ++= Seq(
Deps.ammoniteRepl % "provided",
Deps.ammoniteSpark,
Deps.argonautShapeless,
Deps.sparkSql.value % "provided"
)
)
lazy val `almond-rx` = project
.underScala
.dependsOn(`scala-kernel-api` % Provided)
.settings(
shared,
libraryDependencies += Deps.scalaRx
)
lazy val almond = project
.in(file("."))
.aggregate(
`almond-rx`,
`almond-spark`,
channels,
echo,
`interpreter-api`,
interpreter,
kernel,
logger,
protocol,
`scala-interpreter`,
`scala-kernel-api`,
`scala-kernel`,
test
)
.settings(
shared,
dontPublish
)
lazy val jupyterStart = taskKey[Unit]("")
lazy val jupyterStop = taskKey[Unit]("")
lazy val jupyterDir = taskKey[File]("")
jupyterDir := {
baseDirectory.in(ThisBuild).value / "target" / "jupyter"
}
lazy val jupyterCommand = Seq("jupyter", "lab")
jupyterStart := {
val pack0 = (pack.in(`scala-kernel`).value / "bin" / "scala-kernel").getAbsolutePath
val jupyterDir0 = jupyterDir.value
val dir = jupyterDir0 / "kernels" / "scala"
dir.mkdirs()
val kernelJson = s"""{
"language": "scala",
"display_name": "Scala (sources)",
"argv": [
"$pack0",
"--metabrowse", "--log", "info",
"--connection-file", "{connection_file}"
]
}"""
java.nio.file.Files.write((dir / "kernel.json").toPath, kernelJson.getBytes("UTF-8"))
val b = new ProcessBuilder(jupyterCommand: _*).inheritIO()
val env = b.environment()
env.put("JUPYTER_PATH", jupyterDir0.getAbsolutePath)
val p = b.start()
val pidOpt = try {
val fld = p.getClass.getDeclaredField("pid")
fld.setAccessible(true)
Some(fld.getInt(p))
} catch {
case _: Throwable => None
}
for (pid <- pidOpt) {
java.nio.file.Files.write((jupyterDir0 / "pid").toPath, pid.toString.getBytes("UTF-8"))
java.lang.Runtime.getRuntime.addShutdownHook(
new Thread("jupyter-stop") {
override def run() =
Helper.jupyterStop(jupyterDir0)
}
)
}
}
lazy val Helper = new {
def jupyterStop(jupyterDir: File): Unit = {
val pidFile = jupyterDir / "pid"
if (pidFile.exists()) {
val b = java.nio.file.Files.readAllBytes((jupyterDir / "pid").toPath)
val pid = new String(b, "UTF-8").toInt
new ProcessBuilder("kill", pid.toString).start().waitFor()
java.nio.file.Files.deleteIfExists(pidFile.toPath)
}
}
}
jupyterStop := {
val jupyterDir0 = jupyterDir.value
Helper.jupyterStop(jupyterDir0)
}