On Mon, 4 Feb 2013, Andi Vajda wrote:
On Mon, 4 Feb 2013, Petrus Hyvönen wrote:
I have some strange error when an java exception occurs in the wrapped
library 'orekit', the exception text is not printed and a python error
"NameError: global name 'StringWriter' is not defined" occurs in
__init__.py
I am using the --use_full_names option, latest JCC from SVN.
It is in the __init__.py file, mine looks like:
import os, sys
if sys.platform == 'win32':
import jcc, _orekit
else:
import _orekit
__dir__ = os.path.abspath(os.path.dirname(__file__))
class JavaError(Exception):
def getJavaException(self):
return self.args[0]
def __str__(self):
writer = StringWriter()
self.getJavaException().printStackTrace(PrintWriter(writer))
return "\n".join((super(JavaError, self).__str__(), " Java
stacktrace:", str(writer)))
class InvalidArgsError(Exception):
pass
_orekit._set_exception_types(JavaError, InvalidArgsError)
VERSION = "6.0.0"
CLASSPATH = [os.path.join(__dir__, "orekit-6.0-SNAPSHOT.jar"),
os.path.join(__dir__, "commons-math3-3.1.1.jar")]
CLASSPATH = os.pathsep.join(CLASSPATH)
_orekit.CLASSPATH = CLASSPATH
_orekit._set_function_self(_orekit.initVM, _orekit)
from _orekit import *
With the error:
C:\Users\phy\Desktop\WinPy\WinPython-32bit-2.7.3.3\python-2.7.3\lib\site-packages\orekit\__init__.pyc
in __str__(self)
13 return self.args[0]
14 def __str__(self):
---> 15 writer = StringWriter()
16 self.getJavaException().printStackTrace(PrintWriter(writer))
17 return "\n".join((super(JavaError, self).__str__(), " Java
stacktrace:", str(writer)))
NameError: global name 'StringWriter' is not defined
If I manually add an from java.io import StringWriter, PrintWriter in the
__str__ function it seems to work (not if on module level, no idea why).
Could it be that the last line in __init__.py, from orekit import * is
related to the non-full-names option?
my build string, if interesting is as follows:
python -m jcc --use_full_names --shared --python orekit --version 6.0.0
--jar orekit-6.0-SNAPSHOT.jar --jar commons-math3-3.1.1.jar --package
java.util java.util.Arrays java.util.List java.util.ArrayList
java.util.Collection java.util.Collections java.util.Set java.util.Map
java.util.HashMap java.util.Date --package java.io java.io.InputStream
java.io.StringWriter java.io.StringReader --package java.lang
java.lang.System --package
org.apache.commons.math3.geometry.euclidean.threed.Vector3D --reserved
INFINITE --reserved ERROR --reserved OVERFLOW --reserved NO_DATA --reserved
min --reserved max --reserved mean --build --wininst
Any comments appriciated
Yes, it looks like __init__.py needs to adapt to the full names features.
Thank you for reporting this !
Hopefully fixed in rev 1442394.
Petrus, please try it out and let me know if it's _really_ fixed.
Thanks !
Andi..