Skip to content

Commit 0f1ac43

Browse files
authored
Support Julia 1.7 (#457)
* Update Julia versions in CI * Ignore when jl_ is not defined * Skip running tests with nightly for now * Use chdir hack in macOS * Skip sysimage tests in macOS * More verbose import error if debug=True
1 parent 3c76992 commit 0f1ac43

File tree

7 files changed

+45
-16
lines changed

7 files changed

+45
-16
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@ jobs:
1919
- windows-latest
2020
architecture: [x64, x86]
2121
python-version: ['3.7', '3.8']
22-
julia-version: ['1.0', '1.3', '~1.5.0-rc1', 'nightly']
22+
julia-version:
23+
- '1.0'
24+
- '1.6'
25+
- '~1.7.0-rc1'
26+
# - 'nightly' # TODO: reenable
2327
exclude:
2428
- os: ubuntu-latest
2529
architecture: x86
2630
- os: macos-latest
2731
architecture: x86
2832
- os: macos-latest
29-
julia-version: '1.3'
33+
julia-version: '1.6'
3034
- os: windows-latest
31-
julia-version: '1.3'
35+
julia-version: '1.6'
3236
- os: macos-latest
3337
julia-version: 'nightly'
3438
- os: windows-latest

src/julia/core.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from .libjulia import UNBOXABLE_TYPES, LibJulia, get_inprocess_libjulia, get_libjulia
3333
from .options import JuliaOptions, options_docs
3434
from .release import __version__
35-
from .utils import IMPORT_PYCALL, is_windows
35+
from .utils import PYCALL_PKGID, is_windows
3636

3737
try:
3838
from shutil import which
@@ -500,7 +500,18 @@ def __init__(self, init_julia=True, jl_init_path=None, runtime=None,
500500

501501
# Currently, PyJulia assumes that `Main.PyCall` exsits. Thus, we need
502502
# to import `PyCall` again here in case `init_julia=False` is passed:
503-
self._call(IMPORT_PYCALL)
503+
if debug:
504+
self._call("""
505+
const PyCall = try
506+
Base.require({0})
507+
catch err
508+
@error "Failed to import PyCall" exception = (err, catch_backtrace())
509+
rethrow()
510+
end
511+
""".format(PYCALL_PKGID))
512+
else:
513+
self._call("const PyCall = Base.require({0})".format(PYCALL_PKGID))
514+
504515
self._call(u"using .PyCall")
505516

506517
# Whether we initialized Julia or not, we MUST create at least one

src/julia/libjulia.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from .juliainfo import JuliaInfo
1111
from .options import parse_jl_options
12-
from .utils import is_windows
12+
from .utils import is_apple, is_windows
1313

1414
logger = getLogger("julia")
1515

@@ -31,8 +31,13 @@
3131

3232
def setup_libjulia(libjulia):
3333
# Store the running interpreter reference so we can start using it via self.call
34-
libjulia.jl_.argtypes = [c_void_p]
35-
libjulia.jl_.restype = None
34+
try:
35+
jl_ = libjulia.jl_
36+
except AttributeError:
37+
pass
38+
else:
39+
jl_.argtypes = [c_void_p]
40+
jl_.restype = None
3641

3742
# Set the return types of some of the bridge functions in ctypes terminology
3843
libjulia.jl_eval_string.argtypes = [c_char_p]
@@ -211,14 +216,14 @@ def __init__(self, libjulia_path, bindir, sysimage):
211216
if sys.version_info >= (2, 7, 13) and sys.version_info < (2, 7, 14):
212217
libjulia_path = libjulia_path.encode("ascii")
213218

214-
with self._windows_pathhack():
219+
with self._pathhack():
215220
self.libjulia = ctypes.PyDLL(libjulia_path, ctypes.RTLD_GLOBAL)
216221

217222
setup_libjulia(self.libjulia)
218223

219224
@contextmanager
220-
def _windows_pathhack(self):
221-
if not is_windows:
225+
def _pathhack(self):
226+
if not is_windows and not is_apple:
222227
yield
223228
return
224229
# Using `os.chdir` as a workaround for an error in Windows
@@ -228,6 +233,8 @@ def _windows_pathhack(self):
228233
# is reported to work by many users:
229234
# https://github.com/JuliaPy/pyjulia/issues/67
230235
# https://github.com/JuliaPy/pyjulia/pull/367
236+
# Using this workaround for Julia >= 1.6 in macOS for now:
237+
# https://github.com/JuliaLang/julia/issues/40246
231238
cwd = os.getcwd()
232239
try:
233240
os.chdir(os.path.dirname(self.libjulia_path))
@@ -321,7 +328,7 @@ def init_julia(self, options=None):
321328
logger.debug("argv[%d] = %r", i, argv[i])
322329

323330
logger.debug("calling jl_init_with_image(%s, %s)", jl_init_path, sysimage)
324-
with self._windows_pathhack():
331+
with self._pathhack():
325332
self.jl_init_with_image(
326333
jl_init_path.encode("utf-8"), sysimage.encode("utf-8")
327334
)

src/julia/pyjulia_helper.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fullnamestr(m) = join(fullname(m), ".")
2727
isdefinedstr(parent, member) = isdefined(parent, Symbol(member))
2828

2929
function completions(str, pos)
30-
ret, ran, should_complete = REPL.completions(str, pos)
30+
ret, ran, should_complete = REPL.completions(str, Int(pos))
3131
return (
3232
map(REPL.completion_text, ret),
3333
(first(ran), last(ran)),

src/julia/tests/test_sysimage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ..tools import build_pycall
1010
from .test_compatible_exe import runcode
11-
from .utils import only_in_ci, skip_in_windows
11+
from .utils import only_in_ci, skip_in_apple, skip_in_windows
1212

1313

1414
def skip_early_julia_versions(juliainfo):
@@ -44,6 +44,7 @@ def assert_sample_julia_code_runs(juliainfo, sysimage_path):
4444
@pytest.mark.julia
4545
@only_in_ci
4646
@skip_in_windows
47+
@skip_in_apple
4748
@pytest.mark.parametrize("with_pycall_cache", [False, True])
4849
def test_build_and_load(tmpdir, juliainfo, with_pycall_cache):
4950
skip_early_julia_versions(juliainfo)
@@ -71,6 +72,7 @@ def test_build_and_load(tmpdir, juliainfo, with_pycall_cache):
7172
@pytest.mark.julia
7273
@only_in_ci
7374
@skip_in_windows # Avoid "LVM ERROR: out of memory"
75+
@skip_in_apple
7476
def test_build_with_basesysimage_and_load(tmpdir, juliainfo):
7577
skip_early_julia_versions(juliainfo)
7678

src/julia/tests/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
2+
import sys
23

34
import pytest
45

56
is_windows = os.name == "nt"
7+
is_apple = sys.platform == "darwin"
68
in_github_actions = os.environ.get("GITHUB_ACTIONS", "false").lower() == "true"
79

810
only_in_ci = pytest.mark.skipif(
@@ -17,6 +19,11 @@
1719
Tests that are known to fail in Windows.
1820
"""
1921

22+
skip_in_apple = pytest.mark.skipif(is_apple, reason="Running in macOS")
23+
"""
24+
Tests that are known to fail in macOS.
25+
"""
26+
2027
skip_in_github_actions_windows = pytest.mark.skipif(
2128
is_windows and in_github_actions, reason="Running in Windows in GitHub Actions"
2229
)

src/julia/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,3 @@ def _execprog_subprocess(cmd):
2626

2727
PYCALL_PKGID = """\
2828
Base.PkgId(Base.UUID("438e738f-606a-5dbb-bf0a-cddfbfd45ab0"), "PyCall")"""
29-
30-
IMPORT_PYCALL = "const PyCall = Base.require({})".format(PYCALL_PKGID)

0 commit comments

Comments
 (0)