Skip to content

Commit e915146

Browse files
committed
misc fixes
1 parent 6cae3fe commit e915146

File tree

10 files changed

+71
-128
lines changed

10 files changed

+71
-128
lines changed

idom_jupyter/jupyter_server_extension.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from typing import Any
1+
from __future__ import annotations
2+
23
from pathlib import Path
34
from urllib.parse import urljoin
45

56
from appdirs import user_data_dir
7+
from jupyter_server.serverapp import ServerApp
68
from notebook.notebookapp import NotebookApp
79
from notebook.base.handlers import AuthenticatedFileHandler
810

9-
from tornado.web import Application
10-
1111
try:
1212
from idom.config import IDOM_WEB_MODULES_DIR
1313
except ImportError:
@@ -19,8 +19,8 @@
1919
IDOM_RESOURCE_BASE_PATH = "_idom_web_modules"
2020

2121

22-
def _load_jupyter_server_extension(notebook_app: NotebookApp):
23-
web_app: Application = notebook_app.web_app
22+
def _load_jupyter_server_extension(server_app: ServerApp | NotebookApp):
23+
web_app = server_app.web_app
2424
base_url = web_app.settings["base_url"]
2525
route_pattern = urljoin(base_url, rf"{IDOM_RESOURCE_BASE_PATH}/(.*)")
2626
web_app.add_handlers(

idom_jupyter/widget.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class LayoutWidget(widgets.DOMWidget):
5757
_model_module = Unicode("idom-client-jupyter").tag(sync=True)
5858

5959
# Version of the front-end module containing widget view
60-
_view_module_version = Unicode("^0.9.0").tag(sync=True)
60+
_view_module_version = Unicode("^0.9.1").tag(sync=True)
6161
# Version of the front-end module containing widget model
62-
_model_module_version = Unicode("^0.9.0").tag(sync=True)
62+
_model_module_version = Unicode("^0.9.1").tag(sync=True)
6363

6464
_import_source_base_url = Unicode().tag(sync=True)
6565

js/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Export widget models and views, and the npm package version number.
22

3-
export { HelloModel, HelloView } from "./widget";
3+
export { IdomModel, IdomView } from "./widget";
44
export { version } from "../package.json";

js/lib/labplugin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { HelloModel, HelloView, version } from "./index";
1+
import { IdomModel, IdomView, version } from "./index";
22
import { IJupyterWidgetRegistry } from "@jupyter-widgets/base";
33

4-
export const helloWidgetPlugin = {
4+
export const idomWidgetPlugin = {
55
id: "idom-client-jupyter:plugin",
66
requires: [IJupyterWidgetRegistry],
77
activate: function (app, widgets) {
88
widgets.registerWidget({
99
name: "idom-client-jupyter",
1010
version: version,
11-
exports: { HelloModel, HelloView },
11+
exports: { IdomModel, IdomView },
1212
});
1313
},
1414
autoStart: true,
1515
};
1616

17-
export default helloWidgetPlugin;
17+
export default idomWidgetPlugin;

js/lib/widget.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
var widgets = require("@jupyter-widgets/base");
2-
var idomClientReact = require("idom-client-react");
3-
var _ = require("lodash");
1+
import { DOMWidgetModel, DOMWidgetView } from "@jupyter-widgets/base";
2+
import { mountLayout } from "idom-client-react";
43

5-
var IdomModel = widgets.DOMWidgetModel.extend({
6-
defaults: _.extend(widgets.DOMWidgetModel.prototype.defaults(), {
7-
_model_name: "IdomModel",
8-
_view_name: "IdomView",
9-
_model_module: "idom-client-jupyter",
10-
_view_module: "idom-client-jupyter",
11-
_model_module_version: "0.9.0",
12-
_view_module_version: "0.9.0",
13-
}),
14-
});
4+
export class IdomModel extends DOMWidgetModel {
5+
defaults() {
6+
return {
7+
...super.defaults(),
8+
_model_name: "IdomModel",
9+
_view_name: "IdomView",
10+
_model_module: "idom-client-jupyter",
11+
_view_module: "idom-client-jupyter",
12+
_model_module_version: "0.9.1",
13+
_view_module_version: "0.9.1",
14+
};
15+
}
16+
}
1517

1618
var _nextViewID = { id: 0 };
1719

@@ -23,7 +25,7 @@ const jupyterServerBaseUrl = (() => {
2325
return document.getElementsByTagName("body")[0].getAttribute("data-base-url");
2426
})();
2527

26-
class IdomView extends widgets.DOMWidgetView {
28+
export class IdomView extends DOMWidgetView {
2729
constructor(options) {
2830
super(options);
2931
this.render = this.render.bind(this);
@@ -77,7 +79,7 @@ class IdomView extends widgets.DOMWidgetView {
7779
);
7880
};
7981

80-
idomClientReact.mountLayout(this.el, {
82+
mountLayout(this.el, {
8183
saveUpdateHook,
8284
sendEvent,
8385
loadImportSource,
@@ -114,8 +116,3 @@ function concatAndResolveUrl(url, concat) {
114116
}
115117
return url3.join("/");
116118
}
117-
118-
module.exports = {
119-
IdomModel: IdomModel,
120-
IdomView: IdomView,
121-
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"NotebookApp": {
3+
"nbserver_extensions": {
4+
"idom_jupyter.jupyter_server_extension": true
5+
}
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ServerApp": {
3+
"jpserver_extensions": {
4+
"idom_jupyter.jupyter_server_extension": true
5+
}
6+
}
7+
}

notebooks/introduction.ipynb

Lines changed: 11 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
{
4343
"data": {
4444
"text/plain": [
45-
"App(7fb06f32c400)"
45+
"App(7f911920b6a0)"
4646
]
4747
},
4848
"execution_count": 2,
@@ -52,12 +52,12 @@
5252
{
5353
"data": {
5454
"application/vnd.jupyter.widget-view+json": {
55-
"model_id": "c788abe7d2404a57a53902bdb13f4c1a",
55+
"model_id": "14bfdffe5d5148b8bf923dc95fbfd788",
5656
"version_major": 2,
5757
"version_minor": 0
5858
},
5959
"text/plain": [
60-
"LayoutWidget(Layout(App(7fb06f32c400)))"
60+
"LayoutWidget(Layout(App(7f911920b6a0)))"
6161
]
6262
},
6363
"metadata": {},
@@ -89,34 +89,9 @@
8989
},
9090
{
9191
"cell_type": "code",
92-
"execution_count": 3,
92+
"execution_count": null,
9393
"metadata": {},
94-
"outputs": [
95-
{
96-
"data": {
97-
"text/plain": [
98-
"TodoList(7fb06f32c880)"
99-
]
100-
},
101-
"execution_count": 3,
102-
"metadata": {},
103-
"output_type": "execute_result"
104-
},
105-
{
106-
"data": {
107-
"application/vnd.jupyter.widget-view+json": {
108-
"model_id": "6263559b25bf445e9c8c3e8e12995d0b",
109-
"version_major": 2,
110-
"version_minor": 0
111-
},
112-
"text/plain": [
113-
"LayoutWidget(Layout(TodoList(7fb06f32c880)))"
114-
]
115-
},
116-
"metadata": {},
117-
"output_type": "display_data"
118-
}
119-
],
94+
"outputs": [],
12095
"source": [
12196
"from idom import component, html\n",
12297
"\n",
@@ -165,34 +140,9 @@
165140
},
166141
{
167142
"cell_type": "code",
168-
"execution_count": 4,
143+
"execution_count": null,
169144
"metadata": {},
170-
"outputs": [
171-
{
172-
"data": {
173-
"text/plain": [
174-
"Gallery(7fb0845b7460)"
175-
]
176-
},
177-
"execution_count": 4,
178-
"metadata": {},
179-
"output_type": "execute_result"
180-
},
181-
{
182-
"data": {
183-
"application/vnd.jupyter.widget-view+json": {
184-
"model_id": "7421b51daf6c44e09922f2cc3df143e4",
185-
"version_major": 2,
186-
"version_minor": 0
187-
},
188-
"text/plain": [
189-
"LayoutWidget(Layout(Gallery(7fb0845b7460)))"
190-
]
191-
},
192-
"metadata": {},
193-
"output_type": "display_data"
194-
}
195-
],
145+
"outputs": [],
196146
"source": [
197147
"import json\n",
198148
"from pathlib import Path\n",
@@ -239,46 +189,14 @@
239189
"\n",
240190
"While IDOM is a great tool for displaying HTML and responding to browser events with pure Python, there are other projects which already allow you to do this inside Jupyter Notebooks or in standard web apps. The real power of IDOM comes from its ability to seamlessly leverage the existing Javascript ecosystem:\n",
241191
"\n",
242-
"<a href=\"https://idom-docs.herokuapp.com/docs/escape-hatches/javascript-components.html\" target=\"_blank\"><button>Read More!</button></a>"
192+
"<a href=\"https://idom-docs.herokuapp.com/docs/guides/escape-hatches/javascript-components.html\" target=\"_blank\"><button>Read More!</button></a>"
243193
]
244194
},
245195
{
246196
"cell_type": "code",
247-
"execution_count": 5,
197+
"execution_count": null,
248198
"metadata": {},
249-
"outputs": [
250-
{
251-
"name": "stdout",
252-
"output_type": "stream",
253-
"text": [
254-
"2022-12-23T00:31:22-0800 | \u001b[32mINFO\u001b[0m | Existing web module '__from_template__/victory-bar.js' will be replaced with /home/ryan/.local/share/idom-jupyter/__from_template__/victory-bar.js\u001b[0m\n"
255-
]
256-
},
257-
{
258-
"data": {
259-
"text/plain": [
260-
"Demo(7fb06f32e3e0)"
261-
]
262-
},
263-
"execution_count": 5,
264-
"metadata": {},
265-
"output_type": "execute_result"
266-
},
267-
{
268-
"data": {
269-
"application/vnd.jupyter.widget-view+json": {
270-
"model_id": "041a6087bb294cfcac034f01decee3a9",
271-
"version_major": 2,
272-
"version_minor": 0
273-
},
274-
"text/plain": [
275-
"LayoutWidget(Layout(Demo(7fb06f32e3e0)))"
276-
]
277-
},
278-
"metadata": {},
279-
"output_type": "display_data"
280-
}
281-
],
199+
"outputs": [],
282200
"source": [
283201
"from idom import component, web\n",
284202
"\n",
@@ -306,7 +224,7 @@
306224
],
307225
"metadata": {
308226
"kernelspec": {
309-
"display_name": "Python 3.10.6 ('venv': venv)",
227+
"display_name": "Python 3 (ipykernel)",
310228
"language": "python",
311229
"name": "python3"
312230
},

setup.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@
2525
name=NAME,
2626
description="A client for IDOM implemented using Jupyter widgets",
2727
include_package_data=True,
28-
install_requires=["ipywidgets>=7.6.0", "idom>=0.42,<0.43", "appdirs", "requests"],
28+
install_requires=[
29+
"ipywidgets>=7.6.0",
30+
"idom>=0.42,<0.43",
31+
"appdirs",
32+
"requests",
33+
"jupyter_server",
34+
],
2935
packages=find_packages(),
3036
zip_safe=False,
3137
author="Ryan Morshead",
@@ -84,8 +90,16 @@
8490
"idom_jupyter/labextension",
8591
"**",
8692
),
87-
("share/jupyter/labextensions/idom-client-jupyter", ".", "install.json"),
88-
("etc/jupyter/nbconfig/notebook.d", ".", "idom-client-jupyter.json"),
93+
(
94+
"share/jupyter/labextensions/idom-client-jupyter",
95+
".",
96+
"install.json",
97+
),
98+
(
99+
"etc/jupyter",
100+
"jupyter-config",
101+
"**/*.json",
102+
),
89103
]
90104

91105
cmdclass = create_cmdclass("jsdeps", data_files_spec=data_files_spec)

0 commit comments

Comments
 (0)