-
Notifications
You must be signed in to change notification settings - Fork 101
/
install.jl
120 lines (101 loc) · 3.27 KB
/
install.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
OP, python, libpython = ARGS
# Special exit codes for this script.
# (see: https://www.tldp.org/LDP/abs/html/exitcodes.html)
code_no_precompile_needed = 113
if VERSION < v"0.7.0"
error("Unsupported Julia version $VERSION")
end
const Pkg =
Base.require(Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg"))
const InteractiveUtils = Base.require(Base.PkgId(
Base.UUID("b77e0a4c-d291-57a0-90e8-8db25a27a240"),
"InteractiveUtils",
))
@info "Julia version info"
InteractiveUtils.versioninfo(verbose=true)
@info "Julia executable: $(Base.julia_cmd().exec[1])"
pkgid = Base.PkgId(Base.UUID(0x438e738f_606a_5dbb_bf0a_cddfbfd45ab0), "PyCall")
pycall_is_installed = Base.locate_package(pkgid) !== nothing
@info "Trying to import PyCall..."
module DummyPyCall
python = nothing
libpython = nothing
end
try
# `import PyCall` cannot be caught?
global PyCall = Base.require(pkgid)
catch err
@error "`import PyCall` failed" exception=(err, catch_backtrace())
global PyCall = DummyPyCall
end
ENV["PYTHON"] = python
# TODO: warn if some relevant JULIA_* environment variables are set
# TODO: use PackageSpec to specify PyCall's UUID
function build_pycall()
modpath = Base.locate_package(pkgid)
pkgdir = joinpath(dirname(modpath), "..")
if VERSION >= v"1.1.0-rc1"
@info """Run `Pkg.build("PyCall"; verbose=true)`"""
Pkg.build("PyCall"; verbose=true)
else
@info """Run `Pkg.build("PyCall")`"""
Pkg.build("PyCall")
logfile = joinpath(pkgdir, "deps", "build.log")
if isfile(logfile)
@info "Build log in $logfile"
print(stderr, read(logfile, String))
end
end
depsfile = joinpath(pkgdir, "deps", "deps.jl")
if isfile(depsfile)
@info "`$depsfile`"
print(stderr, read(depsfile, String))
else
@error "Missing `deps.jl` file at: `$depsfile`"
end
end
if OP == "build"
build_pycall()
elseif PyCall.python == python || PyCall.libpython == libpython
@info """
PyCall is already installed and compatible with Python executable.
PyCall:
python: $(PyCall.python)
libpython: $(PyCall.libpython)
Python:
python: $python
libpython: $libpython
"""
exit(code_no_precompile_needed)
else
if PyCall.python !== nothing
if isempty(libpython)
@warn """
PyCall is already installed. However, you may have trouble using
this Python executable because it is statically linked to libpython.
For more information, see:
https://pyjulia.readthedocs.io/en/latest/troubleshooting.html
Python executable:
$python
Julia executable:
$(Base.julia_cmd().exec[1])
"""
exit(code_no_precompile_needed)
else
@info """
PyCall is already installed but not compatible with this Python
executable. Re-building PyCall...
"""
build_pycall()
end
elseif pycall_is_installed
@info """
PyCall is already installed but importing it failed.
Re-building PyCall may fix the issue...
"""
build_pycall()
else
@info "Installing PyCall..."
Pkg.add("PyCall")
end
end