Skip to content

Commit 3357949

Browse files
author
Christopher Doris
committed
add best_julia_version()
1 parent 07303c7 commit 3357949

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

juliacall/deps.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import os
22
import sys
3+
import jill.utils.version_utils
4+
import jill.install
35

46
from time import time
57

68
from . import CONFIG, __version__
7-
from .jlcompat import JuliaCompat
9+
from .jlcompat import JuliaCompat, Version
810

911
### META
1012

@@ -199,6 +201,33 @@ def required_julia():
199201
raise Exception("'julia' compat entries have empty intersection:\n{}".format('\n'.join(['- {!r} at {}'.format(v,f) for (f,v) in compats.items()])))
200202
return compat
201203

204+
def best_julia_version():
205+
"""
206+
Selects the best Julia version available matching required_julia().
207+
208+
It's based on jill.utils.version_utils.latest_version() and jill.install.install_julia().
209+
"""
210+
compat = required_julia()
211+
system = jill.install.current_system()
212+
arch = jill.install.current_architecture()
213+
if system == 'linux' and jill.install.current_libc() == 'musl':
214+
system = 'musl'
215+
releases = jill.utils.version_utils.read_releases()
216+
releases = [r for r in releases if r[1]==system and r[2]==arch]
217+
if compat is not None:
218+
_releases = releases
219+
releases = []
220+
for r in _releases:
221+
try:
222+
v = Version(r[0])
223+
if v in compat:
224+
releases.append(r)
225+
except:
226+
pass
227+
if not releases:
228+
raise Exception('Did not find a version of Julia satisfying {!r}'.format(compat.jlstr()))
229+
return max(releases, key=lambda x: jill.utils.version_utils.Version(x[0]))[0]
230+
202231
def record_resolve(pkgs):
203232
set_meta("pydeps", {
204233
"version": __version__,

juliacall/init.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
libpath = os.environ.get('PYTHON_JULIACALL_LIB')
4343
if libpath is None:
4444
# Find the Julia executable...
45+
# TODO: Check the Julia executable is compatible with jlcompat
46+
# - If Julia is not found, install a compatible one.
47+
# - If Julia is found in the default prefix and not compatible, reinstall.
48+
# - If Julia is found elsewhere, emit a warning?
49+
jlcompat = deps.required_julia()
4550
# ... in a specified location
4651
exepath = os.environ.get('PYTHON_JULIACALL_EXE')
4752
# ... in the default prefix

juliacall/jlcompat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def __and__(self, other):
4646
return JuliaCompat(parts)
4747
def __repr__(self):
4848
return 'JuliaCompat({!r})'.format(self.parts)
49+
def __contains__(self, v):
50+
return any(v in p for p in self.parts)
4951

5052
class Version:
5153
def __init__(self, src):

0 commit comments

Comments
 (0)