Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
don't require jupyter for installation (#791)
* work on jupyter-free installation * rebase fix * drop compat, save jupyter pref again, add env to installkernel * updated notebook command, also jupyterlab command adapted from #783 * installkernel test * clean up test output * whoops * rm another compat reference * rm more compatibility code * updated docs * installkernel is exported * add .exe suffix on Windows * fix path for windows * no compat * only prompt once for jupyterlab install
- Loading branch information
Showing
15 changed files
with
371 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,5 @@ julia 0.7 | |
MbedTLS 0.4.3 | ||
JSON 0.17 | ||
ZMQ 1.0.0 | ||
Compat 0.69.0 | ||
Conda 0.1.5 | ||
SoftGlobalScope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,43 @@ | ||
####################################################################### | ||
import JSON, Conda | ||
using Compat | ||
using Compat.Unicode: lowercase | ||
using Conda | ||
|
||
jupyter="" | ||
|
||
# remove deps.jl at exit if it exists, in case build.jl fails | ||
try | ||
####################################################################### | ||
# Install Jupyter kernel-spec file. | ||
include("kspec.jl") | ||
kernelpath = installkernel("Julia") | ||
|
||
# Make sure Python uses UTF-8 output for Unicode paths | ||
ENV["PYTHONIOENCODING"] = "UTF-8" | ||
# make it easier to get more debugging output by setting JULIA_DEBUG=1 | ||
# when building. | ||
IJULIA_DEBUG = lowercase(get(ENV, "IJULIA_DEBUG", "0")) | ||
IJULIA_DEBUG = IJULIA_DEBUG in ("1", "true", "yes") | ||
|
||
function prog_version(prog) | ||
v = try | ||
chomp(read(`$prog --version`, String)) | ||
catch | ||
return nothing | ||
end | ||
try | ||
return VersionNumber(v) | ||
catch | ||
Compat.@warn("`$jupyter --version` returned an unrecognized version number $v") | ||
return v"0.0" | ||
end | ||
end | ||
|
||
# remember the user's Jupyter preference, if any; empty == Conda | ||
prefsfile = joinpath(first(DEPOT_PATH), "prefs", "IJulia") | ||
mkpath(dirname(prefsfile)) | ||
|
||
global jupyter = get(ENV, "JUPYTER", isfile(prefsfile) ? readchomp(prefsfile) : Compat.Sys.isunix() && !Compat.Sys.isapple() ? "jupyter" : "") | ||
if isempty(jupyter) | ||
jupyter_vers = nothing | ||
else | ||
jupyter_vers = prog_version(jupyter) | ||
if jupyter_vers === nothing | ||
jupyter_vers = prog_version(jupyter * "-notebook") | ||
end | ||
if jupyter_vers === nothing | ||
Compat.@warn("Could not execute `$jupyter --version`.") | ||
jupyter = get(ENV, "JUPYTER", isfile(prefsfile) ? readchomp(prefsfile) : Sys.isunix() && !Sys.isapple() ? "jupyter" : "") | ||
condajupyter = normpath(Conda.SCRIPTDIR, exe("jupyter")) | ||
if !isempty(jupyter) | ||
if dirname(jupyter) == abspath(Conda.SCRIPTDIR) | ||
jupyter = condajupyter # will be installed if needed | ||
end | ||
end | ||
isconda = dirname(jupyter) == abspath(Conda.SCRIPTDIR) | ||
if Sys.ARCH in (:i686, :x86_64) && (jupyter_vers === nothing || jupyter_vers < v"3.0" || isconda) | ||
isconda || jupyter_vers === nothing || Compat.@info("$jupyter was too old: got $jupyter_vers, required ≥ 3.0") | ||
Compat.@info("Installing Jupyter via the Conda package.") | ||
Conda.add("jupyter") | ||
jupyter = abspath(Conda.SCRIPTDIR, "jupyter") | ||
jupyter_vers = prog_version(jupyter) | ||
end | ||
if jupyter_vers === nothing || jupyter_vers < v"3.0" | ||
error("Failed to find or install Jupyter 3.0 or later. Please install Jupyter manually, set `ENV[\"JUPYTER\"]=\"/path/to/jupyter\", and rerun `Pkg.build(\"IJulia\")`.") | ||
end | ||
Compat.@info("Found Jupyter version $jupyter_vers: $jupyter") | ||
|
||
####################################################################### | ||
# Get the latest syntax highlighter file. | ||
if isconda | ||
highlighter = joinpath(Conda.LIBDIR, "python2.7", "site-packages", "notebook", "static", | ||
"components", "codemirror", "mode", "julia", "julia.js") | ||
# CodeMirror commit from which we get the syntax highlighter | ||
cm_commit = "ed9278cba6e1f75328df6b257f1043d35a690c59" | ||
highlighter_url = "https://raw.githubusercontent.com/codemirror/CodeMirror/" * | ||
cm_commit * "/mode/julia/julia.js" | ||
if isfile(highlighter) | ||
try | ||
download(highlighter_url, highlighter) | ||
catch e | ||
Compat.@warn("The following error occurred while attempting to download latest ", | ||
"syntax highlighting definitions:\n\n", e, "\n\nSyntax highlighting may ", | ||
"not work as expected.") | ||
if isabspath(jupyter) | ||
if !Sys.isexecutable(jupyter) | ||
@warn("ignoring non-executable JUPYTER=$jupyter") | ||
jupyter = condajupyter | ||
end | ||
elseif Sys.which(jupyter) === nothing | ||
@warn("JUPYTER=$jupyter not found in PATH") | ||
end | ||
end | ||
|
||
####################################################################### | ||
# Warn people upgrading from older IJulia versions: | ||
try | ||
juliaprof = chomp(read(pipeline(`$ipython locate profile julia`, | ||
stderr=devnull), String)) | ||
Compat.@warn("""You should now run IJulia just via `$jupyter notebook`, without | ||
the `--profile julia` flag. IJulia no longer maintains the profile. | ||
Consider deleting $juliaprof""") | ||
catch | ||
function write_if_changed(filename, contents) | ||
if !isfile(filename) || read(filename, String) != contents | ||
write(filename, contents) | ||
end | ||
end | ||
|
||
####################################################################### | ||
# Install Jupyter kernel-spec file. | ||
|
||
include("kspec.jl") | ||
kspec_cmd, = installkernel("Julia") | ||
|
||
# figure out the notebook command by replacing (only!) the last occurrence of | ||
# "kernelspec" with "notebook": | ||
notebook = kspec_cmd.exec | ||
n = notebook[end] | ||
ki = findlast("kernelspec", n) | ||
notebook[end] = n[1:prevind(n,first(ki))] * "notebook" * n[nextind(n,last(ki)):end] | ||
|
||
####################################################################### | ||
# make it easier to get more debugging output by setting JULIA_DEBUG=1 | ||
# when building. | ||
IJULIA_DEBUG = lowercase(get(ENV, "IJULIA_DEBUG", "0")) | ||
IJULIA_DEBUG = IJULIA_DEBUG in ("1", "true", "yes") | ||
|
||
####################################################################### | ||
# Install the deps.jl file: | ||
|
||
if v"4.2" ≤ jupyter_vers < v"5.1" | ||
# disable broken data-rate limit (issue #528) | ||
push!(notebook, "--NotebookApp.iopub_data_rate_limit=2147483647") | ||
end | ||
deps = """ | ||
const jupyter = "$(escape_string(jupyter))" | ||
const notebook_cmd = ["$(join(map(escape_string, notebook), "\", \""))"] | ||
const jupyter_vers = $(repr(jupyter_vers)) | ||
const IJULIA_DEBUG = $(IJULIA_DEBUG) | ||
""" | ||
if !isfile("deps.jl") || read("deps.jl", String) != deps | ||
write("deps.jl", deps) | ||
end | ||
write(prefsfile, jupyter) | ||
|
||
####################################################################### | ||
catch | ||
isfile("deps.jl") && rm("deps.jl") # remove deps.jl file on build error | ||
rethrow() | ||
end | ||
const JUPYTER = $(repr(jupyter)) | ||
""" | ||
write_if_changed("deps.jl", deps) | ||
write_if_changed(prefsfile, jupyter) |
Oops, something went wrong.