diff --git a/julia/core.py b/julia/core.py index b97f033c..95a889e4 100644 --- a/julia/core.py +++ b/julia/core.py @@ -124,7 +124,7 @@ def __setattr__(self, name, value): else: juliapath = remove_prefix(self.__name__, "julia.") setter = ''' - Main.PyCall.pyfunctionret( + PyCall.pyfunctionret( (x) -> eval({}, :({} = $x)), Any, PyCall.PyAny) @@ -407,9 +407,10 @@ def __init__(self, init_julia=True, jl_runtime_path=None, jl_init_path=None, self.api.jl_typeof_str.restype = char_p self.api.jl_call2.argtypes = [void_p, void_p, void_p] self.api.jl_call2.restype = void_p + self.api.jl_get_field.argtypes = [void_p, char_p] self.api.jl_get_field.restype = void_p self.api.jl_typename_str.restype = char_p - self.api.jl_typeof_str.restype = char_p + self.api.jl_unbox_voidpointer.argtypes = [void_p] self.api.jl_unbox_voidpointer.restype = py_object self.api.jl_exception_clear.restype = None @@ -420,9 +421,6 @@ def __init__(self, init_julia=True, jl_runtime_path=None, jl_init_path=None, self.api.jl_printf.restype = ctypes.c_int self.api.jl_exception_clear() - # We use show() for displaying uncaught exceptions. - self.api.show = self._call("Base.show") - if init_julia: if use_separate_cache: # First check that this is supported @@ -460,9 +458,6 @@ def __init__(self, init_julia=True, jl_runtime_path=None, jl_init_path=None, self.api.PyObject = self._call("PyCall.PyObject") self.api.convert = self._call("convert") - # We use show() for displaying uncaught exceptions. - self.api.show = self._call("Base.show") - # Flag process-wide that Julia is initialized and store the actual # runtime interpreter, so we can reuse it across calls and module # reloads. @@ -494,7 +489,7 @@ def _call(self, src): return ans - def check_exception(self, src=None): + def check_exception(self, src=""): exoc = self.api.jl_exception_occurred() self._debug("exception occured? " + str(exoc)) if not exoc: @@ -511,9 +506,7 @@ def check_exception(self, src=None): except AttributeError: res = None else: - res = self.api.jl_call2(void_p(self.api.convert), - void_p(self.api.PyObject), - void_p(exoc)) + res = self.api.jl_call2(self.api.convert, self.api.PyObject, exoc) if res is None: exception = self.api.jl_typeof_str(exoc).decode('utf-8') else: @@ -539,17 +532,17 @@ def eval(self, src): ans = self._call(src) if not ans: return None - res = self.api.jl_call2(void_p(self.api.convert), void_p(self.api.PyObject), void_p(ans)) + res = self.api.jl_call2(self.api.convert, self.api.PyObject, ans) if res is None: - self.check_exception(src) - return self._as_pyobj(res, "convert(PyCall.PyObject, {})".format(src)) + self.check_exception("convert(PyCall.PyObject, {})".format(src)) + return self._as_pyobj(res) - def _as_pyobj(self, res, src=None): + def _as_pyobj(self, res): if res == 0: return None - boxed_obj = self.api.jl_get_field(void_p(res), b'o') - pyobj = self.api.jl_unbox_voidpointer(void_p(boxed_obj)) + boxed_obj = self.api.jl_get_field(res, b'o') + pyobj = self.api.jl_unbox_voidpointer(boxed_obj) # make sure we incref it before returning it, # as this is a borrowed reference ctypes.pythonapi.Py_IncRef(ctypes.py_object(pyobj)) diff --git a/julia/with_rebuilt.py b/julia/with_rebuilt.py index 902adfd4..48ce7122 100644 --- a/julia/with_rebuilt.py +++ b/julia/with_rebuilt.py @@ -85,6 +85,13 @@ def main(args=None): '--rebuild', default=os.getenv('PYJULIA_TEST_REBUILD', 'no'), choices=('yes', 'no'), help=""" + *Be careful using this option!* When it is set to `yes`, your + `PyCall.jl` installation will be rebuilt using the Python + interpreter used for testing. The test suite tries to build + back to the original configuration but the precompilation + would be in the stale state after the test. Note also that it + does not work if you unconditionally set `PYTHON` environment + variable in your Julia startup file. """) parser.add_argument( '--julia', default=os.getenv('JULIA_EXE', 'julia'),