Skip to content

Commit

Permalink
Displaying info about which JEP path is used (#1633)
Browse files Browse the repository at this point in the history
We also take the first path and then break, so that it won't get overidden.
  • Loading branch information
oxisto authored Jul 25, 2024
1 parent 96849df commit fdc642b
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ import jep.JepConfig
import jep.MainInterpreter
import jep.SharedInterpreter
import kotlin.io.path.exists
import org.slf4j.Logger
import org.slf4j.LoggerFactory

/**
* Takes care of configuring Jep according to some well known paths on popular operating systems.
*/
object JepSingleton {
val log: Logger = LoggerFactory.getLogger(JepSingleton::class.java)

init {
// TODO logging
val config = JepConfig()
Expand Down Expand Up @@ -101,20 +105,23 @@ object JepSingleton {
wellKnownPaths.add(Paths.get("/", "usr", "lib", "libjep.so"))
wellKnownPaths.add(Paths.get("/", "Library", "Java", "Extensions", "libjep.jnilib"))

wellKnownPaths.forEach {
if (it.exists()) {
for (path in wellKnownPaths) {
if (path.exists()) {
// Jep's configuration must be set before the first instance is created. Later
// calls to setJepLibraryPath and co result in failures.
MainInterpreter.setJepLibraryPath(it.toString())
MainInterpreter.setJepLibraryPath(path.toString())

log.info("Using Jep native library in {}", path.toString())

// also add include path so that Python can find jep in case of virtual environment
// fixes: jep.JepException: <class 'ModuleNotFoundError'>: No module named 'jep'
if (
it.parent.fileName.toString() == "jep" &&
(Paths.get(it.parent.toString(), "__init__.py").exists())
path.parent.fileName.toString() == "jep" &&
(Paths.get(path.parent.toString(), "__init__.py").exists())
) {
config.addIncludePaths(it.parent.parent.toString())
config.addIncludePaths(path.parent.parent.toString())
}
break
}
}

Expand Down

0 comments on commit fdc642b

Please sign in to comment.