@@ -4,8 +4,8 @@ import java.io.{ BufferedReader, Closeable, File, IOException, InputStreamReader
4
4
import java .lang .ProcessBuilder .Redirect
5
5
import java .nio .file .Paths
6
6
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
9
9
10
10
import org .nlogo .languagelibrary .Subprocess .path
11
11
import org .nlogo .languagelibrary .Subprocess
@@ -15,6 +15,8 @@ import org.nlogo.api
15
15
import org .nlogo .api ._
16
16
import org .nlogo .core .{ LogoList , Syntax }
17
17
18
+ import scala .collection .immutable .ArraySeq
19
+
18
20
object PythonExtension {
19
21
val codeName = " py"
20
22
val longName = " Python"
@@ -50,20 +52,20 @@ class PythonExtension extends api.DefaultClassManager {
50
52
manager.addPrimitive(" runresult" , RunResult )
51
53
manager.addPrimitive(" set" , Set )
52
54
manager.addPrimitive(" python2" ,
53
- FindPython (PythonSubprocess .python2 _ )
55
+ FindPython (() => PythonSubprocess .python2)
54
56
)
55
57
manager.addPrimitive(" python3" ,
56
- FindPython (PythonSubprocess .python3 _ )
58
+ FindPython (() => PythonSubprocess .python3)
57
59
)
58
60
manager.addPrimitive(" python" ,
59
- FindPython (PythonSubprocess .anyPython _ )
61
+ FindPython (() => PythonSubprocess .anyPython)
60
62
)
61
63
manager.addPrimitive(" __path" , Path )
62
64
}
63
65
64
66
override def runOnce (em : ExtensionManager ): Unit = {
65
67
super .runOnce(em)
66
- mapper.configure( JsonParser . Feature .ALLOW_NON_NUMERIC_NUMBERS , true )
68
+ JsonMapper .builder().configure( JsonReadFeature .ALLOW_NON_NUMERIC_NUMBERS , true )
67
69
68
70
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. "
69
71
val py2Property = new FileProperty (" python2" , " python2" , PythonExtension .config.get(" python2" ).getOrElse(" " ), py2Message)
@@ -107,8 +109,8 @@ object PythonSubprocess {
107
109
108
110
def anyPython : Option [File ] = python3 orElse python2
109
111
110
- def pythons : Stream [PythonBinary ] =
111
- path.toStream
112
+ def pythons : LazyList [PythonBinary ] =
113
+ path.to( LazyList )
112
114
.flatMap(_.listFiles((_, name) => name.toLowerCase.matches(raw " python[\d\.]*(?:\.exe)?? " )))
113
115
.flatMap(PythonBinary .fromFile)
114
116
}
@@ -120,7 +122,7 @@ object SetupPython extends api.Command {
120
122
121
123
override def perform (args : Array [Argument ], context : Context ): Unit = {
122
124
val pyExtensionDirectory = Config .getExtensionRuntimeDirectory(classOf [PythonExtension ], PythonExtension .codeName)
123
- val pythonCmd = args.map(_.getString)
125
+ val pythonCmd = ArraySeq .unsafeWrapArray( args.map(_.getString) )
124
126
val maybePyFile = new File (pyExtensionDirectory, " pyext.py" )
125
127
val pyFile = if (maybePyFile.exists) { maybePyFile } else { (new File (" pyext.py" )).getCanonicalFile }
126
128
val pyScript : String = pyFile.toString
0 commit comments