forked from legend-exp/legend-julia-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsystem_check.jl
55 lines (48 loc) · 2.15 KB
/
system_check.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
# This script is licensed under the MIT License (MIT).
jupyter_cmds = ["jupyter"]
python_cmds = ["python3", "python"]
function detect_application(
application_name::AbstractString,
envvar_name::AbstractString,
julia_pkg_name::AbstractString,
python_pkg_name::AbstractString,
command_candidates::AbstractVector{<:AbstractString}
)
if get(ENV, envvar_name, nothing) == ""
@info "\$$envvar_name is set to \"$(ENV[envvar_name])\", $julia_pkg_name will create a Julia-internal Conda installation for $python_pkg_name."
else
if haskey(ENV, envvar_name)
cmd_name = ENV[envvar_name]
else
cmd_idxs = findall(!isequal(nothing), Sys.which.(command_candidates))
if !isempty(cmd_idxs)
cmd_name = command_candidates[first(cmd_idxs)]
else
@error "No $(join(command_candidates, " or ")) command available, consider installing Anaconda and adding the Anaconda \"bin\" directory to your \$PATH"
exit(1)
end
end
try
cmd_version = chomp(read(`$cmd_name --version`, String))
# ENV[envvar_name] = cmd_name
@info "Using command \"$cmd_name\" for $application_name, $application_name version $cmd_version"
catch err
@error "Trying to use $application_name command \"$cmd_name\", but \"$cmd_name --version\" fails."
exit(1)
end
if application_name == "Python"
try
read(`$cmd_name -c "import matplotlib.pyplot"`, String)
@info "Python can import matplotlib.pyplot"
catch err
@error "Python cannot import matplotlib.pyplot, consider installing Anaconda and adding the Anaconda \"bin\" directory to your \$PATH"
exit(1)
end
end
if !haskey(ENV, envvar_name)
println("Please set environment variable $envvar_name=\"$cmd_name\"")
end
end
end
detect_application("Jupyter", "JUPYTER", "PyCall.jl/PyPlot.jl", "Jupyter", jupyter_cmds)
detect_application("Python", "PYTHON", "PyCall.jl/PyPlot.jl", "matplotlib/PyPlot", python_cmds)