Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions julia/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -494,7 +489,7 @@ def _call(self, src):

return ans

def check_exception(self, src=None):
def check_exception(self, src="<unknown code>"):
exoc = self.api.jl_exception_occurred()
self._debug("exception occured? " + str(exoc))
if not exoc:
Expand All @@ -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:
Expand All @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions julia/with_rebuilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down