|
1 |
| -import os, os.path, ctypes as c, shutil, subprocess, jill.install as jli |
2 |
| -from . import CONFIG, __version__, deps, semver |
| 1 | +import os, os.path, ctypes as c, shutil, subprocess |
| 2 | +from . import CONFIG, __version__, deps, semver, install |
3 | 3 |
|
4 | 4 | # Determine if this is a development version of juliacall
|
5 | 5 | # i.e. it is installed from the github repo, which contains Project.toml
|
|
15 | 15 | # Determine where to look for julia
|
16 | 16 | jldepot = os.environ.get("JULIA_DEPOT_PATH", "").split(";" if os.name == "nt" else ":")[0] or os.path.join(os.path.expanduser("~"), ".julia")
|
17 | 17 | jlprefix = os.path.join(jldepot, "pythoncall")
|
18 |
| -jlbin = os.path.join(jlprefix, "bin") |
19 |
| -jlinstall = os.path.join(jlprefix, "install") |
20 |
| -jldownload = os.path.join(jlprefix, "download") |
21 | 18 |
|
22 | 19 | # Determine where to put the julia environment
|
23 | 20 | # TODO: Can we more direcly figure out the environment from which python was called? Maybe find the first PATH entry containing python?
|
|
50 | 47 | # Find the Julia executable
|
51 | 48 | exepath = os.environ.get('PYTHON_JULIACALL_EXE')
|
52 | 49 | if exepath is not None:
|
53 |
| - v = semver.julia_version_str(exepath) |
| 50 | + v = deps.julia_version_str(exepath) |
54 | 51 | if v is None:
|
55 | 52 | raise ValueError("PYTHON_JULIACALL_EXE={!r} does not exist".format(exepath))
|
56 | 53 | else:
|
|
64 | 61 | else:
|
65 | 62 | # Find the best available version
|
66 | 63 | exepath = None
|
67 |
| - jill_upstream = os.getenv("JILL_UPSTREAM") or "Official" |
68 |
| - exever = deps.best_julia_version(compat, upstream=jill_upstream) |
69 |
| - v = semver.julia_version_str("julia") |
70 |
| - if v is not None and v == exever: |
71 |
| - exepath = "julia" |
72 |
| - elif os.path.isdir(jlbin): |
73 |
| - for f in os.listdir(jlbin): |
74 |
| - if f.startswith("julia"): |
75 |
| - x = os.path.join(jlbin, f) |
76 |
| - v = semver.julia_version_str(x) |
77 |
| - if v is not None and v == exever: |
78 |
| - exepath = x |
79 |
| - break |
| 64 | + exever, exeverinfo = install.best_julia_version(compat) |
| 65 | + default_exeprefix = os.path.join(jlprefix, 'julia-'+exever) |
| 66 | + default_exepath = os.path.join(default_exeprefix, 'bin', 'julia.exe' if os.name=='nt' else 'julia') |
| 67 | + for x in [default_exepath, 'julia']: |
| 68 | + v = deps.julia_version_str(x) |
| 69 | + if v is not None and v == exever: |
| 70 | + print(f'Found Julia {v} at {x!r}') |
| 71 | + exepath = x |
| 72 | + break |
| 73 | + elif v is not None: |
| 74 | + print(f'Found Julia {v} at {x!r} (but looking for Julia {exever})') |
80 | 75 | # If no such version, install it
|
81 | 76 | if exepath is None:
|
82 |
| - print("Installing Julia version {} to {!r}".format(exever, jlbin)) |
83 |
| - os.makedirs(jldownload, exist_ok=True) |
84 |
| - d = os.getcwd() |
85 |
| - p = os.environ.get("PATH") |
86 |
| - try: |
87 |
| - if p is None: |
88 |
| - os.environ["PATH"] = jlbin |
89 |
| - else: |
90 |
| - os.environ["PATH"] += os.pathsep + jlbin |
91 |
| - os.chdir(jldownload) |
92 |
| - jli.install_julia(version=exever, confirm=True, install_dir=jlinstall, symlink_dir=jlbin, upstream=jill_upstream) |
93 |
| - finally: |
94 |
| - if p is None: |
95 |
| - del os.environ["PATH"] |
96 |
| - else: |
97 |
| - os.environ["PATH"] = p |
98 |
| - os.chdir(d) |
99 |
| - exepath = os.path.join(jlbin, "julia.cmd" if os.name == "nt" else "julia") |
| 77 | + install.install_julia(exeverinfo, default_exeprefix) |
| 78 | + exepath = default_exepath |
100 | 79 | if not os.path.isfile(exepath):
|
101 |
| - raise Exception('Installed julia in {!r} but cannot find it'.format(jlbin)) |
| 80 | + raise Exception(f'Installed Julia in {default_exeprefix!r} but cannot find it') |
102 | 81 | # Check the version is compatible
|
103 |
| - v = semver.julia_version_str(exepath) |
| 82 | + v = deps.julia_version_str(exepath) |
104 | 83 | assert v is not None and (compat is None or semver.Version(v) in compat)
|
105 | 84 | CONFIG['exever'] = v
|
106 | 85 | CONFIG['exepath'] = exepath
|
107 |
| - libpath = subprocess.run([exepath, '--startup-file=no', '-O0', '--compile=min', '-e', 'import Libdl; print(abspath(Libdl.dlpath("libjulia")))'], stdout=(subprocess.PIPE)).stdout.decode('utf8') |
| 86 | + libpath = subprocess.run([exepath, '--startup-file=no', '-O0', '--compile=min', '-e', 'import Libdl; print(abspath(Libdl.dlpath("libjulia")))'], check=True, stdout=subprocess.PIPE).stdout.decode('utf8') |
108 | 87 |
|
109 | 88 | # Initialize Julia, including installing required packages
|
110 | 89 | d = os.getcwd()
|
|
0 commit comments