Skip to content

Commit 28c3e0a

Browse files
authored
Setup CI for testing (scalapy#3)
* Setup CI for testing * Integration tests * Use coursier setup-action
1 parent 2554072 commit 28c3e0a

File tree

11 files changed

+127
-7
lines changed

11 files changed

+127
-7
lines changed

.github/scripts/integration_test.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
sbt +publishLocal
4+
sbt -Dplugin.ci=true -Dplugin.python.executable="$1" -Dplugin.scalapy.version="$2" scripted

.github/workflows/ci.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
tags:
7+
- v*
8+
pull_request:
9+
10+
jobs:
11+
test:
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os: [ubuntu-latest]
17+
jdk: [8]
18+
python: [3.7, 3.8, 3.9]
19+
steps:
20+
- uses: actions/checkout@master
21+
- uses: coursier/[email protected]
22+
- uses: coursier/setup-action@v1
23+
with:
24+
jvm: ${{ matrix.jdk }}
25+
apps: sbtn
26+
- name: Set up Python ${{ matrix.python }}
27+
uses: actions/setup-python@v2
28+
with:
29+
python: ${{ matrix.python }}
30+
- name: Unit tests
31+
run: sbt +test
32+
shell: bash
33+
- name: Integration tests again latest ScalaPy stable
34+
run: .github/scripts/integration_test.sh python3 0.5.0
35+
shell: bash

build.sbt

+25-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import Dependencies._
2-
import com.typesafe.sbt.SbtGit.git
3-
import java.nio.file.{Files, Paths}
4-
import java.io.File
52

63
inThisBuild(
74
List(
@@ -23,7 +20,9 @@ lazy val scala212 = "2.12.14"
2320
lazy val scala213 = "2.13.6"
2421
lazy val scala3 = "3.0.0"
2522

26-
ThisBuild / scalaVersion := scala213
23+
lazy val enableScripted = Option(sys.props("plugin.ci")).map(_.trim.nonEmpty).getOrElse(false)
24+
25+
ThisBuild / scalaVersion := (if (enableScripted) scala212 else scala213)
2726

2827
ThisBuild / scalafixDependencies += organizeImports
2928

@@ -33,7 +32,27 @@ def warnUnusedImports(scalaVersion: String) =
3332
case _ => Nil
3433
}
3534

35+
def scriptedPlugin = if (enableScripted) Seq(ScriptedPlugin) else Nil
36+
37+
def scriptedSettings = if (enableScripted) {
38+
Seq(
39+
scriptedLaunchOpts := {
40+
scriptedLaunchOpts.value ++ {
41+
Seq(s"-Dplugin.scalapy.version=$scalapyVersion") ++
42+
Option(sys.props("plugin.python.executable"))
43+
.map("-Dplugin.python.executable=" + _)
44+
.toSeq ++
45+
Seq("-Xmx1024M", "-Dplugin.version=" + version.value)
46+
}
47+
},
48+
scriptedBufferLog := false
49+
)
50+
} else Nil
51+
52+
lazy val scalapyVersion = Option(sys.props("plugin.scalapy.version")).map(_.trim).getOrElse("0.5.0")
53+
3654
lazy val root = (project in file("."))
55+
.enablePlugins(scriptedPlugin: _*)
3756
.settings(
3857
name := "Python Native Libs",
3958
crossScalaVersions := Seq(scala212, scala213, scala3),
@@ -48,13 +67,14 @@ lazy val root = (project in file("."))
4867
semanticdbVersion := scalafixSemanticdb.revision,
4968
scalacOptions ++= warnUnusedImports(scalaVersion.value)
5069
)
70+
.settings(scriptedSettings)
5171

5272
lazy val docs = project
5373
.in(file("python-docs"))
5474
.settings(
5575
mdocVariables := Map(
5676
"VERSION" -> "0.1.3",
57-
"SCALAPY_VERSION" -> "0.5.0",
77+
"SCALAPY_VERSION" -> scalapyVersion,
5878
"PYTHON" -> "/usr/bin/python3"
5979
)
6080
)

project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.5.2
1+
sbt.version=1.5.5

src/main/scala/ai/kien/python/Python.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Python private[python] (
5151
nativeLibraryPaths <- nativeLibraryPaths
5252
libPathFlags = nativeLibraryPaths.map("-L" + _)
5353
flags = rawLdflags
54-
.split("\\s+(?=-)")
54+
.split("\\s+")
5555
.filter(f => f.nonEmpty && !libPathFlags.contains(f))
5656
} yield libPathFlags ++ flags
5757

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import ai.kien.python.Python
2+
3+
lazy val scala212 = "2.12.14"
4+
lazy val scala213 = "2.13.6"
5+
lazy val scala3 = "3.0.0"
6+
7+
ThisBuild / scalaVersion := scala213
8+
9+
lazy val scalapyVersion = sys.props("plugin.scalapy.version")
10+
11+
lazy val python = Python(
12+
Option(sys.props("plugin.python.executable")).filter(_.trim.nonEmpty)
13+
)
14+
15+
lazy val pythonLdFlags = python.ldflags.get
16+
17+
lazy val javaOpts = python.scalapyProperties.get.map { case (k, v) =>
18+
s"""-D$k=$v"""
19+
}.toSeq
20+
21+
lazy val root = crossProject(JVMPlatform, NativePlatform)
22+
.in(file("."))
23+
.settings(
24+
crossScalaVersions := Seq(scala212, scala213)
25+
)
26+
.jvmSettings(
27+
fork := true,
28+
javaOptions ++= javaOpts,
29+
libraryDependencies += "me.shadaj" %% "scalapy-core" % scalapyVersion
30+
)
31+
.nativeSettings(
32+
libraryDependencies += "me.shadaj" %%% "scalapy-core" % scalapyVersion,
33+
nativeLinkStubs := true,
34+
nativeLinkingOptions ++= pythonLdFlags
35+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
project/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.5.5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.1.0")
2+
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0")
3+
4+
sys.props.get("plugin.version") match {
5+
case Some(v) => libraryDependencies += "ai.kien" %% "python-native-libs" % v
6+
case _ =>
7+
sys.error(
8+
"""|The system property 'plugin.version' is not defined.
9+
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin
10+
)
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package project
2+
3+
import me.shadaj.scalapy.py
4+
import me.shadaj.scalapy.py.{PyQuote, SeqConverters}
5+
6+
object Main {
7+
def main(args: Array[String]): Unit = {
8+
println(py.Dynamic.global.list(Seq(1, 2, 3).toPythonProxy))
9+
println(py"'Hello from ScalaPy!'")
10+
}
11+
}

src/sbt-test/integration/scalapy/test

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> +rootJVM/run
2+
> +rootNative/run

0 commit comments

Comments
 (0)