Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Julia 1.7 #457

Merged
merged 10 commits into from
Oct 24, 2021
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
10 changes: 7 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ jobs:
- windows-latest
architecture: [x64, x86]
python-version: ['3.7', '3.8']
julia-version: ['1.0', '1.3', '~1.5.0-rc1', 'nightly']
julia-version:
- '1.0'
- '1.6'
- '~1.7.0-rc1'
# - 'nightly' # TODO: reenable
exclude:
- os: ubuntu-latest
architecture: x86
- os: macos-latest
architecture: x86
- os: macos-latest
julia-version: '1.3'
julia-version: '1.6'
- os: windows-latest
julia-version: '1.3'
julia-version: '1.6'
- os: macos-latest
julia-version: 'nightly'
- os: windows-latest
Expand Down
15 changes: 13 additions & 2 deletions src/julia/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .libjulia import UNBOXABLE_TYPES, LibJulia, get_inprocess_libjulia, get_libjulia
from .options import JuliaOptions, options_docs
from .release import __version__
from .utils import IMPORT_PYCALL, is_windows
from .utils import PYCALL_PKGID, is_windows

try:
from shutil import which
Expand Down Expand Up @@ -500,7 +500,18 @@ def __init__(self, init_julia=True, jl_init_path=None, runtime=None,

# Currently, PyJulia assumes that `Main.PyCall` exsits. Thus, we need
# to import `PyCall` again here in case `init_julia=False` is passed:
self._call(IMPORT_PYCALL)
if debug:
self._call("""
const PyCall = try
Base.require({0})
catch err
@error "Failed to import PyCall" exception = (err, catch_backtrace())
rethrow()
end
""".format(PYCALL_PKGID))
else:
self._call("const PyCall = Base.require({0})".format(PYCALL_PKGID))

self._call(u"using .PyCall")

# Whether we initialized Julia or not, we MUST create at least one
Expand Down
21 changes: 14 additions & 7 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 All @@ -31,8 +31,13 @@

def setup_libjulia(libjulia):
# Store the running interpreter reference so we can start using it via self.call
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line that this comment, "Store the running interpreter reference...", to has been gone for a long time.

libjulia.jl_.argtypes = [c_void_p]
libjulia.jl_.restype = None
try:
jl_ = libjulia.jl_
except AttributeError:
pass
else:
jl_.argtypes = [c_void_p]
jl_.restype = None

# Set the return types of some of the bridge functions in ctypes terminology
libjulia.jl_eval_string.argtypes = [c_char_p]
Expand Down Expand Up @@ -211,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 @@ -228,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))
Comment on lines +236 to 240
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand Down Expand Up @@ -321,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
2 changes: 1 addition & 1 deletion src/julia/pyjulia_helper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fullnamestr(m) = join(fullname(m), ".")
isdefinedstr(parent, member) = isdefined(parent, Symbol(member))

function completions(str, pos)
ret, ran, should_complete = REPL.completions(str, pos)
ret, ran, should_complete = REPL.completions(str, Int(pos))
return (
map(REPL.completion_text, ret),
(first(ran), last(ran)),
Expand Down
4 changes: 3 additions & 1 deletion src/julia/tests/test_sysimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ..tools import build_pycall
from .test_compatible_exe import runcode
from .utils import only_in_ci, skip_in_windows
from .utils import only_in_ci, skip_in_apple, skip_in_windows


def skip_early_julia_versions(juliainfo):
Expand Down Expand Up @@ -44,6 +44,7 @@ def assert_sample_julia_code_runs(juliainfo, sysimage_path):
@pytest.mark.julia
@only_in_ci
@skip_in_windows
@skip_in_apple
@pytest.mark.parametrize("with_pycall_cache", [False, True])
def test_build_and_load(tmpdir, juliainfo, with_pycall_cache):
skip_early_julia_versions(juliainfo)
Expand Down Expand Up @@ -71,6 +72,7 @@ def test_build_and_load(tmpdir, juliainfo, with_pycall_cache):
@pytest.mark.julia
@only_in_ci
@skip_in_windows # Avoid "LVM ERROR: out of memory"
@skip_in_apple
def test_build_with_basesysimage_and_load(tmpdir, juliainfo):
skip_early_julia_versions(juliainfo)

Expand Down
7 changes: 7 additions & 0 deletions src/julia/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import sys

import pytest

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

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

skip_in_apple = pytest.mark.skipif(is_apple, reason="Running in macOS")
"""
Tests that are known to fail in macOS.
"""

skip_in_github_actions_windows = pytest.mark.skipif(
is_windows and in_github_actions, reason="Running in Windows in GitHub Actions"
)
Expand Down
2 changes: 0 additions & 2 deletions src/julia/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ def _execprog_subprocess(cmd):

PYCALL_PKGID = """\
Base.PkgId(Base.UUID("438e738f-606a-5dbb-bf0a-cddfbfd45ab0"), "PyCall")"""

IMPORT_PYCALL = "const PyCall = Base.require({})".format(PYCALL_PKGID)