From 57dcad6db84a566380cc2c2fdef753b528db7e8b Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 24 Oct 2021 05:10:48 -0400 Subject: [PATCH] Use chdir hack in macOS --- src/julia/libjulia.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/julia/libjulia.py b/src/julia/libjulia.py index d994649e..27a6433d 100644 --- a/src/julia/libjulia.py +++ b/src/julia/libjulia.py @@ -9,7 +9,7 @@ from .juliainfo import JuliaInfo from .options import parse_jl_options -from .utils import is_windows +from .utils import is_apple, is_windows logger = getLogger("julia") @@ -216,14 +216,14 @@ def __init__(self, libjulia_path, bindir, sysimage): if sys.version_info >= (2, 7, 13) and sys.version_info < (2, 7, 14): libjulia_path = libjulia_path.encode("ascii") - with self._windows_pathhack(): + with self._pathhack(): self.libjulia = ctypes.PyDLL(libjulia_path, ctypes.RTLD_GLOBAL) setup_libjulia(self.libjulia) @contextmanager - def _windows_pathhack(self): - if not is_windows: + def _pathhack(self): + if not is_windows and not is_apple: yield return # Using `os.chdir` as a workaround for an error in Windows @@ -233,6 +233,8 @@ def _windows_pathhack(self): # is reported to work by many users: # https://github.com/JuliaPy/pyjulia/issues/67 # https://github.com/JuliaPy/pyjulia/pull/367 + # Using this workaround for Julia >= 1.6 in macOS for now: + # https://github.com/JuliaLang/julia/issues/40246 cwd = os.getcwd() try: os.chdir(os.path.dirname(self.libjulia_path)) @@ -326,7 +328,7 @@ def init_julia(self, options=None): logger.debug("argv[%d] = %r", i, argv[i]) logger.debug("calling jl_init_with_image(%s, %s)", jl_init_path, sysimage) - with self._windows_pathhack(): + with self._pathhack(): self.jl_init_with_image( jl_init_path.encode("utf-8"), sysimage.encode("utf-8") )