Skip to content

Commit

Permalink
Use chdir hack in macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Oct 24, 2021
1 parent 9b5782d commit 57dcad6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/julia/libjulia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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")
)
Expand Down

0 comments on commit 57dcad6

Please sign in to comment.