@@ -28,38 +28,48 @@ like this (be careful to set _has\_server\_extension_ to _y_):
28
28
29
29
``` bash
30
30
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
32
33
project_short_description [A JupyterLab extension.]: A minimal JupyterLab extension with backend and frontend parts.
33
34
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]:
35
37
```
36
38
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
+
37
41
The cookiecutter creates the directory ` jlab_ext_example ` [ or your extension name]
38
42
that looks like this:
39
43
40
44
``` bash
41
45
jlab_ext_example/
42
46
│ # Generic Files
43
47
│ .gitignore
48
+ │ install.json # Information retrieved by JupyterLab to help users
44
49
│ LICENSE # License of your code
45
50
│ README.md # Instructions to install and build
46
51
│
47
52
├───.github
48
53
│ └───workflows
49
54
│ build.yml
55
+ │
56
+ ├───binder
57
+ │ environment.yml
58
+ │ postBuild
50
59
│
51
- │ # Backend (server) Files
60
+ │ # Python Package Files
52
61
│ 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
55
68
│
56
69
├───jlab_ext_example
57
70
│ handlers.py # API handler (where things happen)
58
71
│ _version.py # Server extension version
59
72
│ __init__.py # Hook the extension in the server
60
- │
61
- ├───jupyter-config
62
- │ jlab_ext_example.json # Server extension enabler
63
73
│
64
74
│ # Frontend Files
65
75
│ .eslintignore # Code linter configuration
@@ -71,15 +81,17 @@ jlab_ext_example/
71
81
│
72
82
├───src
73
83
│ 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
75
85
│
76
86
└───style
77
- index.css # CSS styling
87
+ base.css # CSS styling
88
+ index.css
89
+ index.js
78
90
```
79
91
80
92
There are two major parts in the extension:
81
93
82
- - A Python package for the server extension
94
+ - A Python package for the server extension and the packaging
83
95
- A NPM package for the frontend extension
84
96
85
97
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.
312
324
313
325
The server part of the extension is going to be presented in this section.
314
326
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
-
329
327
JupyterLab server is built on top of the [Tornado](https://tornadoweb.org/en/stable/guide.html) Python package. To extend the server,
330
328
your extension needs to be defined as a proper Python package with some hook functions:
331
329
@@ -370,8 +368,8 @@ def load_jupyter_server_extension(lab_app):
370
368
371
369
` ` `
372
370
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 `
375
373
that register new handlers.
376
374
377
375
` ` ` py
@@ -389,7 +387,7 @@ example the url is _base_server_url_`/jlab-ext-example/hello` and the class hand
389
387
host_pattern = " .*$"
390
388
base_url = web_app .settings [" base_url" ]
391
389
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
393
391
route_pattern = url_path_join (base_url , url_path , " hello" )
394
392
handlers = [(route_pattern , RouteHandler )]
395
393
web_app .add_handlers (host_pattern , handlers )
@@ -412,7 +410,7 @@ class RouteHandler(APIHandler):
412
410
413
411
@tornado .web .authenticated
414
412
def post (self ):
415
- # input_data is a dictionnary with a key " name"
413
+ # input_data is a dictionary with a key " name"
416
414
input_data = self .get_json_body ()
417
415
data = {" greetings" : " Hello {}, enjoy JupyterLab!" .format (input_data [" name" ])}
418
416
self .finish (json .dumps (data ))
@@ -619,7 +617,7 @@ Basically it will build the frontend NPM package:
619
617
install_npm (HERE , build_cmd =" build:prod" , npm =[" jlpm" ]),
620
618
` ` `
621
619
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 ` :
623
621
624
622
` ` ` py
625
623
# setup .py #L24 -L27
@@ -704,11 +702,11 @@ And that server extension is available through `pip`:
704
702
"pip"
705
703
`` `
706
704
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).
708
706
709
707
## Installing the Package
710
708
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 :
712
710
713
711
`` `bash
714
712
# Install the server extension and
@@ -721,14 +719,11 @@ This will shunt the installation machinery described above. Therefore the comman
721
719
to get you set are :
722
720
723
721
`` `bash
724
- # Install server extension in editable mode
722
+ # Install package in development mode
725
723
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
733
728
`` `
734
729
<!-- prettier -ignore -end -->
0 commit comments