From: Jeff A. <ja...@fa...> - 2020-03-28 11:48:45
|
I think this is because you are no longer running the interpreter via the jython.main() programme. Try setting in the Java System property python.path, what you might have put in JYTHONPATH. If you are initialising Jython with your own properties object(s) it should go in the earliest consulted, I suspect. *Rationale** * The design intent in Jython is that it use the registry (Java properties) as the means of configuring the interpreter. (Well, it seems to have been that from early on: I'm inferring a principle from the implementation.) Java promotes a platform-independent world where the Java interpreter can be launched any number of ways, and there isn't necessarily a shell environment in the way Unix and C have led us to expect. System properties, however, are a Java feature so it must always be possible to set them. The main program, that you might invoke from the console (even if it is via the java command rather than the launcher), sits as a bridge between console world and Java world, and so I think it is only there that environment variables should be consulted, rather than in a scattered way. (This was mostly true already, but maybe not for JYTHONPATH.) Implementation of the -E option (ignore environment variables), and of trying to be more faithful to CPython in our main program, is behind making this absolute. Jeff On 27/03/2020 21:59, Pekka Klärck wrote: > Hi, > > In the Robot Framework project > (https://github.com/robotframework/robotframework) one of our > distributions is a standalone JAR that is built on top of standalone > Jython. We've earlier used Jython 2.7.0, but there have been lot of > fixes since that and we are now planning to switch to Jython 2.7.2. I > have already changed our build scripts and have been running all our > acceptance tests using the new JAR. > > Things have worked pretty well with the new JAR otherwise, but it > seems it doesn't obey JYTHONPATH set externally before execution. > Executing Python code can see the environment variable, but Python > modules in directories listed in it cannot be imported. I just tested > that if I build a JAR from same sources with Jython 2.7.0, JYTHONPATH > works as expected. > > The strange thing is that when I tested with the standalone Jython > 2.7.2 alone, it did handle JYTHONPATH just fine. This got me thinking > that perhaps we are somehow embedding Jython wrong. Are there some > know changes related to embedding Jython using PythonInterpreter? > Should we perhaps configure it somehow to get JYTHONPATH processed > correctly? The code currently just initialized PythonInterpreter > without any arguments and then calls `interpreter.exec(code)`. You can > find the full code here: > https://github.com/robotframework/robotframework/blob/master/src/java/org/robotframework/RobotRunner.java > > One workaround for us is processing JYTHONPATH in our code and I > already tested that it works. If that turns out to be the only > solution, I just need to find a way to do that only when using the JAR > distribution. > > Cheers, > .peke |