Skip to content

Commit 28a990e

Browse files
authored
JupyterLab 3 compatibility (#457)
* WIP: JupyterLab 3 compatibility * Allow Observables 0.3 and 0.4 * Use Jupyter labextension cookiecutter * Update labextension LICENSE, relax compat requirements * Combine Jupyter labextension and serverextension * Add Jupyter serverextension installation stuff * Add nbextension to single Python package * Update Jupyter installation process * Fix diagnostic warning messages and whatnot * Remove ijulia-tests reference * Attempt to remove old Jupyter integration during build
1 parent b2efd5e commit 28a990e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1621
-793
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ node_modules
1515
lerna-debug.log
1616
package-lock.json
1717
*.tgz
18+
.yarn
1819

1920
# Miscellaneous
2021
.*~

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Widgets = "0.6.2"
3535
julia = "0.7, 1"
3636
JSExpr = "0.5"
3737
JSON = "0.18, 0.19, 0.20, 0.21"
38-
Observables = "0.4"
38+
Observables = "0.3, 0.4"
3939
FunctionalCollections = "0.5.0"
4040
AssetRegistry = "0.1.0"
4141
WebSockets = "1.5.0"

deps/_bundlejs.jl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ end
88
let
99
package_dir = dirname(@__DIR__)
1010

11-
# Don't build packages outside of a dev environment (or CI).
12-
if !isdev()
13-
@warn(
14-
"Can't build WebIO JS when not checked out for development. "
15-
* "Run `Pkg.dev(\"WebIO\")` if you want to build JS."
16-
)
17-
return
18-
end
19-
2011
# Build the dang packages!
2112
package_dir = normpath(joinpath(@__DIR__, "..", "packages"))
2213
npm = `npm -C $(package_dir)`
@@ -52,10 +43,6 @@ let
5243
@info "Copying $(generic_http_bundle_out) to $(GENERIC_HTTP_BUNDLE_PATH)..."
5344
cp(generic_http_bundle_out, GENERIC_HTTP_BUNDLE_PATH; force=true)
5445

55-
nbextension_bundle_out = joinpath(package_dir, "jupyter-notebook-provider", "dist", "jupyter-notebook.bundle.js")
56-
@info "Copying $(nbextension_bundle_out) to $(JUPYTER_NBEXTENSION_PATH)..."
57-
cp(nbextension_bundle_out, JUPYTER_NBEXTENSION_PATH; force=true)
58-
5946
mux_bundle_out = joinpath(package_dir, "mux-provider", "dist", "mux.bundle.js")
6047
@info "Copying $(mux_bundle_out) to $(MUX_BUNDLE_PATH)..."
6148
cp(mux_bundle_out, MUX_BUNDLE_PATH; force=true)

deps/build.jl

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,60 @@ include("./jupyter.jl")
55

66
download_js_bundles()
77

8-
# See https://github.com/JuliaGizmos/WebIO.jl/issues/314 for the rational behind
9-
# why we're not installing Jupyter packages by default anymore.
10-
@warn(
11-
"WebIO no longer installs Jupyter extensions automatically; please run "
12-
* "`WebIO.install_jupyter_notebook()` or `WebIO.install_jupyter_lab()` if "
13-
* "needed."
14-
)
8+
const CONFIG_BEGIN_MARKER = "###JULIA-WEBIO-CONFIG-BEGIN"
9+
const CONFIG_END_MARKER = "###JULIA-WEBIO-CONFIG-END"
10+
11+
macro meh(expr)
12+
quote
13+
try
14+
$(esc(expr))
15+
catch exc
16+
@info "Surpressed exception (this is probably harmless)" expr=$(string(expr)) exception=exc
17+
end
18+
end
19+
end
20+
21+
try
22+
@info "Attempting to uninstall old Jupyter integrations (it's probably okay if error messages appear below this point)"
23+
jupyter_config_dir = get(ENV, "JUPYTER_CONFIG_DIR", joinpath(homedir(), ".jupyter"))
24+
25+
config_file_py = joinpath(jupyter_config_dir, "jupyter_notebook_config.py")
26+
if isfile(config_file_py)
27+
config_regex = Regex(
28+
"\n?" * CONFIG_BEGIN_MARKER * ".*" * CONFIG_END_MARKER * "\n?",
29+
"s",
30+
)
31+
config_py = read(config_file_py, String)
32+
config_py = replace(config_py, config_regex => "")
33+
write(config_file_py, config_py)
34+
end
35+
36+
config_file_json = joinpath(jupyter_config_dir, "jupyter_notebook_config.json")
37+
if isfile(config_file_json)
38+
config_json = JSON.parse(read(config_file_json, String))
39+
@meh delete!(config_json["NotebookApp"]["nbserver_extensions"], "jlstaticserve")
40+
write(config_file_json, JSON.json(config_json, 4))
41+
end
42+
43+
notebook_config_json = joinpath(jupyter_config_dir, "nbconfig", "notebook.json")
44+
if isfile(notebook_config_json)
45+
config_json = JSON.parse(read(notebook_config_json, String))
46+
@meh delete!(config_json["load_extensions"], "webio-jupyter-notebook")
47+
write(notebook_config_json, JSON.json(config_json, 4))
48+
end
49+
50+
# try to uninstall labextension using system Jupyter installation
51+
@meh run(`jupyter labextension uninstall @webio/jupyter-lab-provider`)
52+
53+
# try to uninstall labextension using Conda Jupyter installation
54+
conda_root = joinpath(first(Base.DEPOT_PATH), "conda", "3")
55+
conda_py = normpath(joinpath(conda_root, @static(
56+
Sys.iswindows()
57+
? joinpath("Scripts", "python.exe")
58+
: joinpath("bin", "python")
59+
)))
60+
@meh run(`$conda_py -m jupyterlab.labextensions uninstall @webio/jupyter-lab-provider`)
61+
catch exc
62+
# pass
63+
@warn "Error while updating Jupyter config" exception=exc
64+
end

deps/bundlepaths.jl

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ const WEBIO_VERSION = let
66
VersionNumber(project["version"])
77
end
88

9-
# Make sure that we're running tests for this repository, we don't want to do
10-
# extra steps when testing other packages. For the time being we run tests only
11-
# on Travis, so isci() checks Travis-specific environment variables.
12-
function isci()
13-
return get(ENV, "TRAVIS", "false") == "true" &&
14-
split(get(ENV, "TRAVIS_REPO_SLUG", "Foo/Bar.jl"), '/')[2] == "WebIO.jl"
15-
end
16-
isdev() = isci() || basename(dirname(dirname(@__DIR__))) == "dev"
17-
189
const PACKAGES_PATH = normpath(joinpath(@__DIR__, "..", "packages"))
1910
const BUNDLES_PATH = normpath(joinpath(@__DIR__, "bundles"))
2011

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

32-
const JUPYTER_NBEXTENSION_NAME = "webio-jupyter-notebook"
33-
const JUPYTER_NBEXTENSION_PATH = joinpath(BUNDLES_PATH, "$(JUPYTER_NBEXTENSION_NAME).js")
34-
const JUPYTER_NBEXTENSION_URL = bundleurl("jupyter-notebook-provider", "jupyter-notebook.bundle.js")
35-
3623
# Deprecated! Remove for WebIO version 1.0.0
3724
const BLINK_BUNDLE_PATH = joinpath(BUNDLES_PATH, "blink.bundle.js")
3825
const BLINK_BUNDLE_URL = bundleurl("blink-provider", "blink.bundle.js")
@@ -44,6 +31,16 @@ function download_bundle(name::String, path::String, url::String)
4431
end
4532
end
4633

34+
35+
# TODO: this is all an ugly hack to avoid trying to build JS when other packages (that use WebIO)
36+
# are just trying to run their own tests. It desperately needs to be restructured.
37+
function isci()
38+
return (
39+
get(ENV, "CI", "false") == "true" &&
40+
split(get(ENV, "GITHUB_REPOSITORY", "Foo/Bar.jl"), '/')[2] == "WebIO.jl"
41+
)
42+
end
43+
4744
function download_js_bundles()
4845
if isci()
4946
# In CI, we always build the bundles from scratch.
@@ -56,10 +53,5 @@ function download_js_bundles()
5653
download_bundle("core", CORE_BUNDLE_PATH, CORE_BUNDLE_URL)
5754
download_bundle("generic-http", GENERIC_HTTP_BUNDLE_PATH, GENERIC_HTTP_BUNDLE_URL)
5855
download_bundle("mux", MUX_BUNDLE_PATH, MUX_BUNDLE_URL)
59-
download_bundle("jupyter-notebook", JUPYTER_NBEXTENSION_PATH, JUPYTER_NBEXTENSION_URL)
6056
download_bundle("blink", BLINK_BUNDLE_PATH, BLINK_BUNDLE_URL)
61-
62-
# NOTE: we don't download JupyterLab files because that should just begin
63-
# installed directly from npm (à la the
64-
# `jupyter labextension install @webio/jupyter-lab-provider` command).
6557
end

0 commit comments

Comments
 (0)