Skip to content

Commit 7c56b65

Browse files
committed
Updated Language Library and Scala code
1 parent aca3bda commit 7c56b65

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

build.sbt

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ isSnapshot := true
88
scalaVersion := "2.13.16"
99
Test / scalaSource := baseDirectory.value / "src" / "test"
1010
Compile / scalaSource := baseDirectory.value / "src" / "main"
11-
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature", "-Xfatal-warnings", "-Xlint", "-release", "11")
11+
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature", "-quickfix:any", "-Xfatal-warnings", "-Xlint", "-release", "11")
1212

13-
netLogoVersion := "6.3.0"
13+
netLogoVersion := "7.0.0-internal1"
1414
netLogoClassManager := "org.nlogo.extensions.py.PythonExtension"
1515
netLogoExtName := "py"
1616
netLogoPackageExtras += (baseDirectory.value / "src" / "pyext.py", None)
@@ -23,5 +23,5 @@ Compile / packageBin / artifactPath := {
2323

2424
resolvers += "netlogo-language-library" at "https://dl.cloudsmith.io/public/netlogo/language-library/maven"
2525
libraryDependencies ++= Seq(
26-
"org.nlogo.languagelibrary" %% "language-library" % "2.4.0"
26+
"org.nlogo.languagelibrary" %% "language-library" % "3.0.0"
2727
)

src/main/PythonExtension.scala

+11-9
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import java.io.{ BufferedReader, Closeable, File, IOException, InputStreamReader
44
import java.lang.ProcessBuilder.Redirect
55
import java.nio.file.Paths
66

7-
import com.fasterxml.jackson.core.JsonParser
8-
import org.json4s.jackson.JsonMethods.mapper
7+
import com.fasterxml.jackson.core.json.JsonReadFeature
8+
import com.fasterxml.jackson.databind.json.JsonMapper
99

1010
import org.nlogo.languagelibrary.Subprocess.path
1111
import org.nlogo.languagelibrary.Subprocess
@@ -15,6 +15,8 @@ import org.nlogo.api
1515
import org.nlogo.api._
1616
import org.nlogo.core.{ LogoList, Syntax }
1717

18+
import scala.collection.immutable.ArraySeq
19+
1820
object PythonExtension {
1921
val codeName = "py"
2022
val longName = "Python"
@@ -50,20 +52,20 @@ class PythonExtension extends api.DefaultClassManager {
5052
manager.addPrimitive("runresult", RunResult)
5153
manager.addPrimitive("set", Set)
5254
manager.addPrimitive("python2",
53-
FindPython(PythonSubprocess.python2 _)
55+
FindPython(() => PythonSubprocess.python2)
5456
)
5557
manager.addPrimitive("python3",
56-
FindPython(PythonSubprocess.python3 _)
58+
FindPython(() => PythonSubprocess.python3)
5759
)
5860
manager.addPrimitive("python",
59-
FindPython(PythonSubprocess.anyPython _)
61+
FindPython(() => PythonSubprocess.anyPython)
6062
)
6163
manager.addPrimitive("__path", Path)
6264
}
6365

6466
override def runOnce(em: ExtensionManager): Unit = {
6567
super.runOnce(em)
66-
mapper.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true)
68+
JsonMapper.builder().configure(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS, true)
6769

6870
val py2Message = s"It is recommended to use Python 3 if possible and enter its path above. If you must use Python 2, enter the path to its executable folder below."
6971
val py2Property = new FileProperty("python2", "python2", PythonExtension.config.get("python2").getOrElse(""), py2Message)
@@ -107,8 +109,8 @@ object PythonSubprocess {
107109

108110
def anyPython: Option[File] = python3 orElse python2
109111

110-
def pythons: Stream[PythonBinary] =
111-
path.toStream
112+
def pythons: LazyList[PythonBinary] =
113+
path.to(LazyList)
112114
.flatMap(_.listFiles((_, name) => name.toLowerCase.matches(raw"python[\d\.]*(?:\.exe)??")))
113115
.flatMap(PythonBinary.fromFile)
114116
}
@@ -120,7 +122,7 @@ object SetupPython extends api.Command {
120122

121123
override def perform(args: Array[Argument], context: Context): Unit = {
122124
val pyExtensionDirectory = Config.getExtensionRuntimeDirectory(classOf[PythonExtension], PythonExtension.codeName)
123-
val pythonCmd = args.map(_.getString)
125+
val pythonCmd = ArraySeq.unsafeWrapArray(args.map(_.getString))
124126
val maybePyFile = new File(pyExtensionDirectory, "pyext.py")
125127
val pyFile = if (maybePyFile.exists) { maybePyFile } else { (new File("pyext.py")).getCanonicalFile }
126128
val pyScript: String = pyFile.toString

0 commit comments

Comments
 (0)