Skip to content

Improve juliainfo #197

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

Merged
merged 4 commits into from
Oct 24, 2018
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
42 changes: 33 additions & 9 deletions julia/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,14 @@ def determine_if_statically_linked():
'pyprogramname', 'libpython'])


def juliainfo(runtime='julia'):
output = subprocess.check_output(
[runtime, "-e",
def juliainfo(runtime='julia', **popen_kwargs):
# Use the original environment variables to avoid a cryptic
# error "fake-julia/../lib/julia/sys.so: cannot open shared
# object file: No such file or directory":
popen_kwargs.setdefault("env", _enviorn)

proc = subprocess.Popen(
[runtime, "--startup-file=no", "-e",
"""
println(VERSION < v"0.7.0-DEV.3073" ? JULIA_HOME : Base.Sys.BINDIR)
if VERSION >= v"0.7.0-DEV.3630"
Expand All @@ -282,19 +287,38 @@ def juliainfo(runtime='julia'):
PyCall_depsfile = Pkg.dir("PyCall","deps","deps.jl")
else
modpath = Base.locate_package(Base.identify_package("PyCall"))
PyCall_depsfile = joinpath(dirname(modpath),"..","deps","deps.jl")
if modpath == nothing
PyCall_depsfile = nothing
else
PyCall_depsfile = joinpath(dirname(modpath),"..","deps","deps.jl")
end
end
if PyCall_depsfile !== nothing && isfile(PyCall_depsfile)
include(PyCall_depsfile)
println(pyprogramname)
println(libpython)
end
"""],
# Use the original environment variables to avoid a cryptic
# error "fake-julia/../lib/julia/sys.so: cannot open shared
# object file: No such file or directory":
env=_enviorn)
args = output.decode("utf-8").rstrip().split("\n")
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
**popen_kwargs)

stdout, stderr = proc.communicate()
retcode = proc.wait()
if retcode != 0:
raise subprocess.CalledProcessError(
retcode,
[runtime, "-e", "..."],
stdout,
stderr,
)

stderr = stderr.strip()
if stderr:
warnings.warn("{} warned:\n{}".format(runtime, stderr))

args = stdout.rstrip().split("\n")
args.extend([None] * (len(JuliaInfo._fields) - len(args)))
return JuliaInfo(*args)

Expand Down
49 changes: 49 additions & 0 deletions test/test_juliainfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
import subprocess

from julia.core import juliainfo, _enviorn


def check_core_juliainfo(jlinfo):
assert os.path.exists(jlinfo.JULIA_HOME)
assert os.path.exists(jlinfo.libjulia_path)
assert os.path.exists(jlinfo.image_file)


def test_juliainfo_normal():
jlinfo = juliainfo(os.getenv("JULIA_EXE", "julia"))
check_core_juliainfo(jlinfo)
assert os.path.exists(jlinfo.pyprogramname)
# Note: jlinfo.libpython is probably not a full path so we are not
# testing it here.


def test_juliainfo_without_pycall(tmpdir):
"""
`juliainfo` should not fail even when PyCall.jl is not installed.
"""

runtime = os.getenv("JULIA_EXE", "julia")

env_var = subprocess.check_output(
[runtime, "--startup-file=no", "-e", """
if VERSION < v"0.7-"
println("JULIA_PKGDIR")
print(ARGS[1])
else
paths = [ARGS[1], DEPOT_PATH[2:end]...]
println("JULIA_DEPOT_PATH")
print(join(paths, Sys.iswindows() ? ';' : ':'))
end
""", str(tmpdir)],
env=_enviorn,
universal_newlines=True)
name, val = env_var.split("\n", 1)

jlinfo = juliainfo(
runtime,
env=dict(_enviorn, **{name: val}))

check_core_juliainfo(jlinfo)
assert jlinfo.pyprogramname is None
assert jlinfo.libpython is None