Skip to content

Commit

Permalink
Prompt to auto-install NodeJS.
Browse files Browse the repository at this point in the history
  • Loading branch information
twavv committed Dec 2, 2019
1 parent f9695da commit 356e5d9
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions deps/jupyter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ function install_jupyter_serverextension()
return nothing
end

function find_condajl_jupyter_cmd()::Cmd
function find_condajl_jupyter_cmd(;
check_nodejs::Bool=false,
)::Cmd
conda_root = joinpath(first(Base.DEPOT_PATH), "conda", "3")
conda_bin_dir = joinpath(
conda_root,
@static(Sys.iswindows() ? "Scripts" : "bin"),
)

jupyter = joinpath(conda_bin_dir, "jupyter")
jupyter = joinpath(conda_bin_dir, exe("jupyter"))
if !isfile(jupyter)
error(
"Could not find the Conda.jl `jupyter` executable " *
Expand All @@ -102,7 +104,25 @@ function find_condajl_jupyter_cmd()::Cmd
# detect nodejs.
conda_env = copy(ENV)
conda_env["PATH"] = string(conda_bin_dir, ":", conda_env["PATH"])
return Cmd(`$jupyter`, env=conda_env)
cmd = Cmd(`$jupyter`, env=conda_env)

if check_nodejs
node_exe = joinpath(conda_bin_dir, exe("node"))
if !Sys.isfile(node_exe)
install_node = Base.prompt(
"NodeJS is not installed in your Conda environment " *
"but is neccessary to install the JupyterLab extension. " *
"Install it? [Y/n]",
default="y"
)
if isyes(install_node)
@eval Main using IJulia
@eval Main.IJulia Conda.add("nodejs")
end
end
end

return cmd
end

function find_path_jupyter_cmd()::Cmd
Expand Down Expand Up @@ -261,3 +281,10 @@ function jupyter_config_dir()
end
jupyter_nbextensions_dir() = joinpath(jupyter_data_dir(), "nbextensions")
jupyter_nbconfig_dir() = joinpath(jupyter_config_dir(), "nbconfig")

isyes(s) = isempty(s) || lowercase(strip(s)) in ("y", "yes")
@static if Sys.iswindow()
exe(x::String) = endswith(x, "exe") ? x : string(x, ".exe")
else
exe(x::String) = x
end

0 comments on commit 356e5d9

Please sign in to comment.