| 35 | override fun support(box: Box, prop: Dict.Prop<String>): Execution.ExecutionSupport? { |
| 36 | if (box == this) return null |
| 37 | if (prop != Execution.code) return null; |
| 38 | |
| 39 | val ef = this.properties.get(Execution.executionFilter) |
| 40 | return if (ef == null || ef.apply(box)) pi.computeIfAbsent(box) { |
| 41 | wrap( |
| 42 | box, |
| 43 | prop, |
| 44 | initPythonInterface(box, prop) |
| 45 | ) |
| 46 | } else null |
| 47 | } |
| 48 | |
| 49 | companion object { |
| 50 | |
| 51 | val jc = object : JepConfig() { |
| 52 | init { |
| 53 | setSharedModules(setOf("numpy", "spacy", "spacy.lang")) |
| 54 | setClassLoader(PI::class.java.classLoader) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | } |
| 59 | |
| 60 | lateinit var globalShared: SharedInterpreter |
| 61 | |
| 62 | |
| 63 | private fun initPythonInterface( |
| 64 | box: Box, |
| 65 | prop: Dict.Prop<String> |
| 66 | ): SharedInterpreter { |
| 67 | |
| 68 | if (this::globalShared.isInitialized) |
| 69 | { |
| 70 | makeLocals(globalShared, box) |
| 71 | return globalShared |
| 72 | } |
| 73 | |
| 74 | // initSharedInterpreter() |
| 75 | var s = SharedInterpreter(); |
| 76 | s.exec(stdlib) |
| 77 | s.set("_", box) |
| 78 | s.exec( |
| 79 | """ |
| 80 | __localmap__ = {} |
| 81 | |
| 82 | import sys |
| 83 | |
| 84 | from java.lang import System |
| 85 | class StdOutToJava(object): |
| 86 | def __init__(self): |
| 87 | self.oldout = sys.stdout |
| 88 | |
| 89 | def write(self, msg): |
| 90 | System.out.println(msg) |
| 91 | if ("__writer__" in globals()): |
| 92 | __writer__.write(str(msg)) |
| 93 | |
| 94 | def flush(self): |
nothing calls this directly
no test coverage detected