Skip to content

Commit 3911248

Browse files
committed
Fix juliainfo for the case when PyCall.jl is not installed
1 parent cdbefb1 commit 3911248

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

julia/core.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,12 @@ def determine_if_statically_linked():
267267
'pyprogramname', 'libpython'])
268268

269269

270-
def juliainfo(runtime='julia'):
270+
def juliainfo(runtime='julia', **popen_kwargs):
271+
# Use the original environment variables to avoid a cryptic
272+
# error "fake-julia/../lib/julia/sys.so: cannot open shared
273+
# object file: No such file or directory":
274+
popen_kwargs.setdefault("env", _enviorn)
275+
271276
output = subprocess.check_output(
272277
[runtime, "-e",
273278
"""
@@ -282,18 +287,19 @@ def juliainfo(runtime='julia'):
282287
PyCall_depsfile = Pkg.dir("PyCall","deps","deps.jl")
283288
else
284289
modpath = Base.locate_package(Base.identify_package("PyCall"))
285-
PyCall_depsfile = joinpath(dirname(modpath),"..","deps","deps.jl")
290+
if modpath == nothing
291+
PyCall_depsfile = nothing
292+
else
293+
PyCall_depsfile = joinpath(dirname(modpath),"..","deps","deps.jl")
294+
end
286295
end
287296
if PyCall_depsfile !== nothing && isfile(PyCall_depsfile)
288297
include(PyCall_depsfile)
289298
println(pyprogramname)
290299
println(libpython)
291300
end
292301
"""],
293-
# Use the original environment variables to avoid a cryptic
294-
# error "fake-julia/../lib/julia/sys.so: cannot open shared
295-
# object file: No such file or directory":
296-
env=_enviorn)
302+
**popen_kwargs)
297303
args = output.decode("utf-8").rstrip().split("\n")
298304
args.extend([None] * (len(JuliaInfo._fields) - len(args)))
299305
return JuliaInfo(*args)

test/test_juliainfo.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import subprocess
3+
4+
from julia.core import juliainfo, _enviorn
5+
6+
7+
def check_core_juliainfo(jlinfo):
8+
assert os.path.exists(jlinfo.JULIA_HOME)
9+
assert os.path.exists(jlinfo.libjulia_path)
10+
assert os.path.exists(jlinfo.image_file)
11+
12+
13+
def test_juliainfo_normal():
14+
jlinfo = juliainfo(os.getenv("JULIA_EXE", "julia"))
15+
check_core_juliainfo(jlinfo)
16+
assert os.path.exists(jlinfo.pyprogramname)
17+
# Note: jlinfo.libpython is probably not a full path so we are not
18+
# testing it here.
19+
20+
21+
def test_juliainfo_without_pycall(tmpdir):
22+
"""
23+
`juliainfo` should not fail even when PyCall.jl is not installed.
24+
"""
25+
26+
runtime = os.getenv("JULIA_EXE", "julia")
27+
28+
JULIA_DEPOT_PATH = subprocess.check_output(
29+
[runtime, "-e", """
30+
paths = [ARGS[1], DEPOT_PATH[2:end]...]
31+
print(join(paths, Sys.iswindows() ? ';' : ':'))
32+
""", str(tmpdir)],
33+
env=_enviorn,
34+
universal_newlines=True)
35+
36+
jlinfo = juliainfo(
37+
runtime,
38+
env=dict(_enviorn, JULIA_DEPOT_PATH=JULIA_DEPOT_PATH))
39+
40+
check_core_juliainfo(jlinfo)
41+
assert jlinfo.pyprogramname is None
42+
assert jlinfo.libpython is None

0 commit comments

Comments
 (0)