Skip to content
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

JupyterLab 3 compatibility #457

Merged
merged 11 commits into from
Sep 10, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ node_modules
lerna-debug.log
package-lock.json
*.tgz
.yarn

# Miscellaneous
.*~
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Widgets = "0.6.2"
julia = "0.7, 1"
JSExpr = "0.5"
JSON = "0.18, 0.19, 0.20, 0.21"
Observables = "0.4"
Observables = "0.3, 0.4"
FunctionalCollections = "0.5.0"
AssetRegistry = "0.1.0"
WebSockets = "1.5.0"
Expand Down
13 changes: 0 additions & 13 deletions deps/_bundlejs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ end
let
package_dir = dirname(@__DIR__)

# Don't build packages outside of a dev environment (or CI).
if !isdev()
@warn(
"Can't build WebIO JS when not checked out for development. "
* "Run `Pkg.dev(\"WebIO\")` if you want to build JS."
)
return
end

# Build the dang packages!
package_dir = normpath(joinpath(@__DIR__, "..", "packages"))
npm = `npm -C $(package_dir)`
Expand Down Expand Up @@ -52,10 +43,6 @@ let
@info "Copying $(generic_http_bundle_out) to $(GENERIC_HTTP_BUNDLE_PATH)..."
cp(generic_http_bundle_out, GENERIC_HTTP_BUNDLE_PATH; force=true)

nbextension_bundle_out = joinpath(package_dir, "jupyter-notebook-provider", "dist", "jupyter-notebook.bundle.js")
@info "Copying $(nbextension_bundle_out) to $(JUPYTER_NBEXTENSION_PATH)..."
cp(nbextension_bundle_out, JUPYTER_NBEXTENSION_PATH; force=true)

mux_bundle_out = joinpath(package_dir, "mux-provider", "dist", "mux.bundle.js")
@info "Copying $(mux_bundle_out) to $(MUX_BUNDLE_PATH)..."
cp(mux_bundle_out, MUX_BUNDLE_PATH; force=true)
Expand Down
64 changes: 57 additions & 7 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,60 @@ include("./jupyter.jl")

download_js_bundles()

# See https://github.com/JuliaGizmos/WebIO.jl/issues/314 for the rational behind
# why we're not installing Jupyter packages by default anymore.
@warn(
"WebIO no longer installs Jupyter extensions automatically; please run "
* "`WebIO.install_jupyter_notebook()` or `WebIO.install_jupyter_lab()` if "
* "needed."
)
const CONFIG_BEGIN_MARKER = "###JULIA-WEBIO-CONFIG-BEGIN"
const CONFIG_END_MARKER = "###JULIA-WEBIO-CONFIG-END"

macro meh(expr)
quote
try
$(esc(expr))
catch exc
@info "Surpressed exception (this is probably harmless)" expr=$(string(expr)) exception=exc
end
end
end

try
@info "Attempting to uninstall old Jupyter integrations (it's probably okay if error messages appear below this point)"
jupyter_config_dir = get(ENV, "JUPYTER_CONFIG_DIR", joinpath(homedir(), ".jupyter"))

config_file_py = joinpath(jupyter_config_dir, "jupyter_notebook_config.py")
if isfile(config_file_py)
config_regex = Regex(
"\n?" * CONFIG_BEGIN_MARKER * ".*" * CONFIG_END_MARKER * "\n?",
"s",
)
config_py = read(config_file_py, String)
config_py = replace(config_py, config_regex => "")
write(config_file_py, config_py)
end

config_file_json = joinpath(jupyter_config_dir, "jupyter_notebook_config.json")
if isfile(config_file_json)
config_json = JSON.parse(read(config_file_json, String))
@meh delete!(config_json["NotebookApp"]["nbserver_extensions"], "jlstaticserve")
write(config_file_json, JSON.json(config_json, 4))
end

notebook_config_json = joinpath(jupyter_config_dir, "nbconfig", "notebook.json")
if isfile(notebook_config_json)
config_json = JSON.parse(read(notebook_config_json, String))
@meh delete!(config_json["load_extensions"], "webio-jupyter-notebook")
write(notebook_config_json, JSON.json(config_json, 4))
end

# try to uninstall labextension using system Jupyter installation
@meh run(`jupyter labextension uninstall @webio/jupyter-lab-provider`)

# try to uninstall labextension using Conda Jupyter installation
conda_root = joinpath(first(Base.DEPOT_PATH), "conda", "3")
conda_py = normpath(joinpath(conda_root, @static(
Sys.iswindows()
? joinpath("Scripts", "python.exe")
: joinpath("bin", "python")
)))
@meh run(`$conda_py -m jupyterlab.labextensions uninstall @webio/jupyter-lab-provider`)
catch exc
# pass
@warn "Error while updating Jupyter config" exception=exc
end
28 changes: 10 additions & 18 deletions deps/bundlepaths.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ const WEBIO_VERSION = let
VersionNumber(project["version"])
end

# Make sure that we're running tests for this repository, we don't want to do
# extra steps when testing other packages. For the time being we run tests only
# on Travis, so isci() checks Travis-specific environment variables.
function isci()
return get(ENV, "TRAVIS", "false") == "true" &&
split(get(ENV, "TRAVIS_REPO_SLUG", "Foo/Bar.jl"), '/')[2] == "WebIO.jl"
end
isdev() = isci() || basename(dirname(dirname(@__DIR__))) == "dev"

const PACKAGES_PATH = normpath(joinpath(@__DIR__, "..", "packages"))
const BUNDLES_PATH = normpath(joinpath(@__DIR__, "bundles"))

Expand All @@ -29,10 +20,6 @@ const GENERIC_HTTP_BUNDLE_URL = bundleurl("generic-http-provider", "generic-http
const MUX_BUNDLE_PATH = joinpath(BUNDLES_PATH, "mux.bundle.js")
const MUX_BUNDLE_URL = bundleurl("mux-provider", "mux.bundle.js")

const JUPYTER_NBEXTENSION_NAME = "webio-jupyter-notebook"
const JUPYTER_NBEXTENSION_PATH = joinpath(BUNDLES_PATH, "$(JUPYTER_NBEXTENSION_NAME).js")
const JUPYTER_NBEXTENSION_URL = bundleurl("jupyter-notebook-provider", "jupyter-notebook.bundle.js")

# Deprecated! Remove for WebIO version 1.0.0
const BLINK_BUNDLE_PATH = joinpath(BUNDLES_PATH, "blink.bundle.js")
const BLINK_BUNDLE_URL = bundleurl("blink-provider", "blink.bundle.js")
Expand All @@ -44,6 +31,16 @@ function download_bundle(name::String, path::String, url::String)
end
end


# TODO: this is all an ugly hack to avoid trying to build JS when other packages (that use WebIO)
# are just trying to run their own tests. It desperately needs to be restructured.
function isci()
return (
get(ENV, "CI", "false") == "true" &&
split(get(ENV, "GITHUB_REPOSITORY", "Foo/Bar.jl"), '/')[2] == "WebIO.jl"
)
end

function download_js_bundles()
if isci()
# In CI, we always build the bundles from scratch.
Expand All @@ -56,10 +53,5 @@ function download_js_bundles()
download_bundle("core", CORE_BUNDLE_PATH, CORE_BUNDLE_URL)
download_bundle("generic-http", GENERIC_HTTP_BUNDLE_PATH, GENERIC_HTTP_BUNDLE_URL)
download_bundle("mux", MUX_BUNDLE_PATH, MUX_BUNDLE_URL)
download_bundle("jupyter-notebook", JUPYTER_NBEXTENSION_PATH, JUPYTER_NBEXTENSION_URL)
download_bundle("blink", BLINK_BUNDLE_PATH, BLINK_BUNDLE_URL)

# NOTE: we don't download JupyterLab files because that should just begin
# installed directly from npm (à la the
# `jupyter labextension install @webio/jupyter-lab-provider` command).
end
Loading