@@ -4,8 +4,8 @@ import java.io.{ BufferedReader, Closeable, File, IOException, InputStreamReader
44import java .lang .ProcessBuilder .Redirect
55import 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
1010import org .nlogo .languagelibrary .Subprocess .path
1111import org .nlogo .languagelibrary .Subprocess
@@ -15,6 +15,8 @@ import org.nlogo.api
1515import org .nlogo .api ._
1616import org .nlogo .core .{ LogoList , Syntax }
1717
18+ import scala .collection .immutable .ArraySeq
19+
1820object 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