From 4381bfbe2103691e0ce4a7c73e67dae8656ac68e Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sat, 18 Aug 2018 23:02:21 -0700 Subject: [PATCH 1/7] Remove unused arguments from Julia._as_pyobj --- julia/core.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/julia/core.py b/julia/core.py index b97f033c..4d265ea5 100644 --- a/julia/core.py +++ b/julia/core.py @@ -494,7 +494,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: @@ -542,10 +542,10 @@ def eval(self, src): res = self.api.jl_call2(void_p(self.api.convert), void_p(self.api.PyObject), void_p(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') From 8e0a92fccb63d46d72eda3b336bdde2f4e06e13f Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sat, 18 Aug 2018 23:15:15 -0700 Subject: [PATCH 2/7] Remove obsolete Julia.api.show --- julia/core.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/julia/core.py b/julia/core.py index 4d265ea5..5cc927e1 100644 --- a/julia/core.py +++ b/julia/core.py @@ -420,9 +420,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 +457,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. From ff3858bf66c4b7665493f055102073adb7e91e57 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sat, 18 Aug 2018 23:17:55 -0700 Subject: [PATCH 3/7] Remove redundant jl_typeof_str.restype --- julia/core.py | 1 - 1 file changed, 1 deletion(-) diff --git a/julia/core.py b/julia/core.py index 5cc927e1..2535279d 100644 --- a/julia/core.py +++ b/julia/core.py @@ -409,7 +409,6 @@ def __init__(self, init_julia=True, jl_runtime_path=None, jl_init_path=None, self.api.jl_call2.restype = void_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.restype = py_object self.api.jl_exception_clear.restype = None From 016f4ac587ac8f4449e6095bc461379788164955 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sat, 18 Aug 2018 23:25:33 -0700 Subject: [PATCH 4/7] Remove unnecessary explicit casting --- julia/core.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/julia/core.py b/julia/core.py index 2535279d..77563511 100644 --- a/julia/core.py +++ b/julia/core.py @@ -504,9 +504,7 @@ def check_exception(self, src=""): 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: @@ -532,7 +530,7 @@ 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("convert(PyCall.PyObject, {})".format(src)) From 02f3066a1bb0fee19261ecad68dd862a5c35512e Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sat, 18 Aug 2018 23:26:42 -0700 Subject: [PATCH 5/7] Let ctypes handle casting --- julia/core.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/julia/core.py b/julia/core.py index 77563511..0864e88c 100644 --- a/julia/core.py +++ b/julia/core.py @@ -407,8 +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_unbox_voidpointer.argtypes = [void_p] self.api.jl_unbox_voidpointer.restype = py_object self.api.jl_exception_clear.restype = None @@ -539,8 +541,8 @@ def eval(self, src): 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)) From 11ef08589e5f0d06905cfcb6ea3d4ecef54cd002 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Mon, 20 Aug 2018 23:41:19 -0700 Subject: [PATCH 6/7] Remove unnecessary "Main." --- julia/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/julia/core.py b/julia/core.py index 0864e88c..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) From f7fabaf310730fbb65ee445856c7b21d66cbcf35 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Tue, 21 Aug 2018 23:30:27 -0700 Subject: [PATCH 7/7] Add missing --rebuild help --- julia/with_rebuilt.py | 7 +++++++ 1 file changed, 7 insertions(+) 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'),