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 6 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
12 changes: 10 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 IMPORT_PYCALL, PYCALL_PKGID, is_windows

try:
from shutil import which
Expand Down Expand Up @@ -500,7 +500,15 @@ 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)
self._call("""
const PyCall = try
Base.require({0})
catch err
@error "Failed to import PyCall" exception = (err, catch_backtrace())
rethrow()
end
""".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