Skip to content

Commit 7d5f53e

Browse files
committed
Update examples
1 parent 7f89e5d commit 7d5f53e

File tree

13 files changed

+86
-81
lines changed

13 files changed

+86
-81
lines changed

advanced/kernel-messaging/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
![Kernel Messages](preview.gif)
1111

12-
## Custom Kernel Interactions: Kernel Managment and Messaging
12+
## Custom Kernel Interactions: Kernel Management and Messaging
1313

1414
One of the main features of JupyterLab is the possibility to manage and
1515
interact with [kernels](https://jupyter-client.readthedocs.io/en/latest/kernels.html).

advanced/kernel-output/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ object ([see the documentation](https://jupyterlab.github.io/jupyterlab/classes/
4141
Here it is stored in the private `_sessionContext` variable:
4242

4343
```ts
44-
// src/panel.ts#L94-L94
44+
// src/panel.ts#L95-L95
4545

4646
private _sessionContext: SessionContext;
4747
```
@@ -50,7 +50,7 @@ A `SessionContext` handles a single kernel session. The session itself (not yet
5050
the kernel) is started with these lines:
5151

5252
```ts
53-
// src/panel.ts#L44-L48
53+
// src/panel.ts#L45-L49
5454

5555
this._sessionContext = new SessionContext({
5656
sessionManager: manager.sessions,
@@ -63,7 +63,7 @@ The private session variable is exposed as read-only for other users
6363
through a getter method:
6464

6565
```ts
66-
// src/panel.ts#L72-L74
66+
// src/panel.ts#L73-L75
6767

6868
get session(): ISessionContext {
6969
return this._sessionContext;
@@ -75,7 +75,7 @@ with this line:
7575

7676
<!-- prettier-ignore-start -->
7777
```ts
78-
// src/panel.ts#L58-L69
78+
// src/panel.ts#L59-L70
7979

8080
void this._sessionContext
8181
.initialize()
@@ -93,13 +93,13 @@ void this._sessionContext
9393
<!-- prettier-ignore-end -->
9494

9595
When a session has no predefined preferred kernel, a dialog will request the user to choose a kernel to start. Conveniently, this can
96-
also be an already existing kernel, as you will see later.
96+
also be an already existing kernel.
9797

9898
The following two methods ensure the clean disposal of the session
9999
when you close the panel.
100100

101101
```ts
102-
// src/panel.ts#L76-L79
102+
// src/panel.ts#L77-L80
103103

104104
dispose(): void {
105105
this._sessionContext.dispose();
@@ -108,7 +108,7 @@ dispose(): void {
108108
```
109109

110110
```ts
111-
// src/panel.ts#L89-L92
111+
// src/panel.ts#L90-L93
112112

113113
protected onCloseRequest(msg: Message): void {
114114
super.onCloseRequest(msg);
@@ -120,11 +120,11 @@ protected onCloseRequest(msg: Message): void {
120120

121121
The `SimplifiedOutputArea` class is a `Widget`, as described in the [widget example](../../widget-tracker/widgets/README.md).
122122
It has the ability to display the results of a notebook cell execution.
123-
You can instantiate it with a new `OutputAreaModel`; this is class containing
123+
You can instantiate it with a new `OutputAreaModel`; this class is containing
124124
the data to show:
125125

126126
```ts
127-
// src/panel.ts#L50-L54
127+
// src/panel.ts#L51-L55
128128

129129
this._outputareamodel = new OutputAreaModel();
130130
this._outputarea = new SimplifiedOutputArea({
@@ -138,7 +138,7 @@ some code to a kernel through a `ISessionContext` ([see documentation](https://j
138138
in the specific `SimplifiedOutputArea` object you created:
139139

140140
```ts
141-
// src/panel.ts#L81-L87
141+
// src/panel.ts#L82-L88
142142

143143
execute(code: string): void {
144144
SimplifiedOutputArea.execute(code, this._outputarea, this._sessionContext)
@@ -158,7 +158,7 @@ To display the `SimplifiedOutputArea` Widget you need to add it to your
158158
panel with:
159159

160160
```ts
161-
// src/panel.ts#L56-L56
161+
// src/panel.ts#L57-L57
162162

163163
this.addWidget(this._outputarea);
164164
```
@@ -266,4 +266,4 @@ the variable name in the input dialog, it will be displayed in the example panel
266266
## Where to Go Next
267267

268268
This example makes use of input dialogs. To know which input dialogs are available
269-
have a look at the [documentation](https://jupyterlab.readthedocs.io/en/stable/developer/ui_helpers.html).
269+
have a look at the [documentation](https://jupyterlab.readthedocs.io/en/stable/extension/ui_helpers.html#dialogs).

advanced/kernel-output/src/panel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { OutputAreaModel, SimplifiedOutputArea } from '@jupyterlab/outputarea';
99
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
1010

1111
import { KernelMessage, ServiceManager } from '@jupyterlab/services';
12+
1213
import {
1314
ITranslator,
1415
nullTranslator,

advanced/server-extension/README.md

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,48 @@ like this (be careful to set _has\_server\_extension_ to _y_):
2828

2929
```bash
3030
author_name []: my_name
31-
extension_name [myextension]: jlab_ext_example
31+
python_name [myextension]: jlab_ext_example
32+
extension_name [jlab_ext_example]: jlab-ext-example
3233
project_short_description [A JupyterLab extension.]: A minimal JupyterLab extension with backend and frontend parts.
3334
has_server_extension [n]: y
34-
repository [https://github.com/my_name/myextension]:
35+
has_binder [n]: y
36+
repository [https://github.com/github_username/jlab_ext_example]:
3537
```
3638

39+
> The python name should not contain `-`. It is nice for user to test your extension online, so the `has_binder` was set to _yes_.
40+
3741
The cookiecutter creates the directory `jlab_ext_example` [or your extension name]
3842
that looks like this:
3943

4044
```bash
4145
jlab_ext_example/
4246
│  # Generic Files
4347
│ .gitignore
48+
│ install.json # Information retrieved by JupyterLab to help users
4449
│ LICENSE # License of your code
4550
│ README.md # Instructions to install and build
4651
4752
├───.github
4853
│ └───workflows
4954
│ build.yml
55+
56+
├───binder
57+
│ environment.yml
58+
│ postBuild
5059
│  
51-
│  # Backend (server) Files
60+
│  # Python Package Files
5261
│ MANIFEST.in # Help Python to list your source files
53-
│ pyproject.toml # Define dependencies for building the server package
54-
│ setup.py # Information about the server package
62+
│ pyproject.toml # Define dependencies for building the package
63+
│ setup.py # Information about the package
64+
65+
# Backend (server) Files
66+
├───jupyter-config
67+
│ jlab_ext_example.json # Server extension enabler
5568
5669
├───jlab_ext_example
5770
│ handlers.py # API handler (where things happen)
5871
│ _version.py # Server extension version
5972
│ __init__.py # Hook the extension in the server
60-
61-
├───jupyter-config
62-
│ jlab_ext_example.json # Server extension enabler
6373
│  
6474
│  # Frontend Files
6575
│ .eslintignore # Code linter configuration
@@ -71,15 +81,17 @@ jlab_ext_example/
7181
│  
7282
├───src
7383
│ index.ts # Actual code of the extension
74-
jlabextexample.ts # More code used by the extension
84+
handler.ts # More code used by the extension
7585
7686
└───style
77-
index.css # CSS styling
87+
base.css # CSS styling
88+
index.css
89+
index.js
7890
```
7991

8092
There are two major parts in the extension:
8193

82-
- A Python package for the server extension
94+
- A Python package for the server extension and the packaging
8395
- A NPM package for the frontend extension
8496

8597
In this example, you will see that the template code have been extended
@@ -312,20 +324,6 @@ an `IFrame` that will display static content fetched from the server extension.
312324
313325
The server part of the extension is going to be presented in this section.
314326
315-
You first need to install the python source code. The following will install
316-
the `jlab_ext_example` package in dev mode:
317-
318-
```bash
319-
pip install -e .
320-
```
321-
322-
Then you need to enable the package at the Jupyter level
323-
so that it becomes a server extension.
324-
325-
```bash
326-
jupyter serverextension enable --py jlab_ext_example
327-
```
328-
329327
JupyterLab server is built on top of the [Tornado](https://tornadoweb.org/en/stable/guide.html) Python package. To extend the server,
330328
your extension needs to be defined as a proper Python package with some hook functions:
331329
@@ -370,8 +368,8 @@ def load_jupyter_server_extension(lab_app):
370368

371369
```
372370
373-
The `_jupyter_jlab_ext_example_paths` provides the Python package name
374-
to the server. But the most important one is `load_jupyter_jlab_ext_example`
371+
The `_jupyter_server_extension_paths` provides the Python package name
372+
to the server. But the most important one is `load_jupyter_server_extension`
375373
that register new handlers.
376374
377375
```py
@@ -389,7 +387,7 @@ example the url is _base_server_url_`/jlab-ext-example/hello` and the class hand
389387
host_pattern = ".*$"
390388
base_url = web_app.settings["base_url"]
391389

392-
# Prepend the base_url so that it works in a jupyterhub setting
390+
# Prepend the base_url so that it works in a JupyterHub setting
393391
route_pattern = url_path_join(base_url, url_path, "hello")
394392
handlers = [(route_pattern, RouteHandler)]
395393
web_app.add_handlers(host_pattern, handlers)
@@ -412,7 +410,7 @@ class RouteHandler(APIHandler):
412410

413411
@tornado.web.authenticated
414412
def post(self):
415-
# input_data is a dictionnary with a key "name"
413+
# input_data is a dictionary with a key "name"
416414
input_data = self.get_json_body()
417415
data = {"greetings": "Hello {}, enjoy JupyterLab!".format(input_data["name"])}
418416
self.finish(json.dumps(data))
@@ -619,7 +617,7 @@ Basically it will build the frontend NPM package:
619617
install_npm(HERE, build_cmd="build:prod", npm=["jlpm"]),
620618
```
621619
622-
It will ensure one of the generated JS files is `lib/jlabextexample.js`:
620+
It will ensure one of the generated files is `jlab_ext_example/labextension/package.json`:
623621
624622
```py
625623
# setup.py#L24-L27
@@ -704,11 +702,11 @@ And that server extension is available through `pip`:
704702
"pip"
705703
```
706704

707-
For more information on the `discovery` metadata, please refer to the [documentation](https://jupyterlab.readthedocs.io/en/stable/developer/extension_dev.html#ext-author-companion-packages).
705+
For more information on the `discovery` metadata, please refer to the [documentation](https://jupyterlab.readthedocs.io/en/stable/extension/extension_dev.html#ext-author-companion-packages).
708706

709707
## Installing the Package
710708

711-
With the packaging described above, installing the extension is done in two commands once the package is published on pypi.org:
709+
With the packaging described above, installing the extension is done in one command once the package is published on pypi.org:
712710

713711
```bash
714712
# Install the server extension and
@@ -721,14 +719,11 @@ This will shunt the installation machinery described above. Therefore the comman
721719
to get you set are:
722720

723721
```bash
724-
# Install server extension in editable mode
722+
# Install package in development mode
725723
pip install -e .
726-
# Build Typescript source
727-
jlpm build
728-
# Install your development version of the extension with JupyterLab
729-
jupyter labextension develop .
730-
731-
# Rebuild Typescript source after making changes
732-
jlpm build
724+
# Link your development version of the extension with JupyterLab
725+
jupyter labextension develop . --overwrite
726+
# Rebuild extension Typescript source after making changes
727+
jlpm run build
733728
```
734729
<!-- prettier-ignore-end -->

advanced/server-extension/jlab_ext_example/handlers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def get(self):
1818

1919
@tornado.web.authenticated
2020
def post(self):
21-
# input_data is a dictionnary with a key "name"
21+
# input_data is a dictionary with a key "name"
2222
input_data = self.get_json_body()
2323
data = {"greetings": "Hello {}, enjoy JupyterLab!".format(input_data["name"])}
2424
self.finish(json.dumps(data))
@@ -28,12 +28,12 @@ def setup_handlers(web_app, url_path):
2828
host_pattern = ".*$"
2929
base_url = web_app.settings["base_url"]
3030

31-
# Prepend the base_url so that it works in a jupyterhub setting
31+
# Prepend the base_url so that it works in a JupyterHub setting
3232
route_pattern = url_path_join(base_url, url_path, "hello")
3333
handlers = [(route_pattern, RouteHandler)]
3434
web_app.add_handlers(host_pattern, handlers)
3535

36-
# Prepend the base_url so that it works in a jupyterhub setting
36+
# Prepend the base_url so that it works in a JupyterHub setting
3737
doc_url = url_path_join(base_url, url_path, "public")
3838
doc_dir = os.getenv(
3939
"JLAB_SERVER_EXAMPLE_STATIC_DIR",

basics/datagrid/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,27 @@ class LargeDataModel extends DataModel {
8888
The three abstract methods are `rowCount`, `columnCount` and `data`. The
8989
first two must return a number from a region argument. To know the possible
9090
values of `RowRegion` and the `ColumnRegion`, you can look at the
91-
[Lumino code](https://github.com/jupyterlab/lumino/blob/9f5e11025b62d2c4a6fb59e2681ae1ed323dcde4/packages/datagrid/src/datamodel.ts#L112-L129):
91+
[Lumino code](https://github.com/jupyterlab/lumino/blob/9c5f31cca3b02441850e086c1b19642a6e298493/packages/datagrid/src/datamodel.ts#L134-L155):
9292
9393
```ts
9494
/**
9595
* A type alias for the data model row regions.
9696
*/
97-
type RowRegion = 'body' | 'column-header';
97+
export type RowRegion = 'body' | 'column-header';
98+
9899
/**
99100
* A type alias for the data model column regions.
100101
*/
101-
type ColumnRegion = 'body' | 'row-header';
102+
export type ColumnRegion = 'body' | 'row-header';
103+
102104
/**
103105
* A type alias for the data model cell regions.
104106
*/
105-
type CellRegion = 'body' | 'row-header' | 'column-header' | 'corner-header';
107+
export type CellRegion =
108+
| 'body'
109+
| 'row-header'
110+
| 'column-header'
111+
| 'corner-header';
106112
```
107113
108114
The `|` can be read as `or`. This means that the `RowRegion` type is

basics/hello-world/README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ author_name []: tuto
2525
python_name [myextension]: hello_world
2626
extension_name [hello_world]: hello-world
2727
project_short_description [A JupyterLab extension.]: Minimal JupyterLab example
28-
has_server_extension [n]:
28+
has_server_extension [n]:
2929
has_binder [n]: y
3030
repository [https://github.com/github_username/hello_world]:
3131
```
@@ -55,14 +55,14 @@ hello_world/
5555
│ └───workflows
5656
│ build.yml
5757
58-
├───hello_world
59-
│ __init__.py
60-
│ _version.py
61-
6258
├───binder
6359
│ environment.yml
6460
│ postBuild
6561
62+
├───hello_world
63+
│ __init__.py
64+
│ _version.py
65+
6666
├───src
6767
│ index.ts
6868
@@ -134,6 +134,12 @@ const extension: JupyterFrontEndPlugin<void> = {
134134
id: 'hello-world',
135135
autoStart: true,
136136
activate: (app: JupyterFrontEnd) => {
137+
console.log('the JupyterLab main application:', app);
138+
}
139+
};
140+
141+
export default extension;
142+
137143
```
138144

139145
```ts
@@ -200,7 +206,6 @@ The second command create a symbolic link to the folder `hello_world/labextensio
200206
The third command allows you to update the Javascript code each time you modify your
201207
extension code.
202208

203-
204209
After all of these steps are done, running `jupyter labextension list` should
205210
show something like:
206211

0 commit comments

Comments
 (0)