Skip to content

Commit

Permalink
embedme
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Nov 6, 2020
1 parent 169decf commit bfcc2da
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
43 changes: 23 additions & 20 deletions advanced/server-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ if (launcher) {
}
```
Invoking the command (via the command palette or the launcher) will open a new tab with
Invoking the command (via the command palette or the launcher) will open a new tab with
an `IFrame` that will display static content fetched from the server extension.
**Note**
Expand All @@ -312,14 +312,14 @@ an `IFrame` that will display static content fetched from the server extension.
The server part of the extension is going to be presented in this section.
You first need to install the python source code. The following will install
You first need to install the python source code. The following will install
the `jlab_ext_example` package in dev mode:
```bash
pip install -e .
```
Then you need to enable the package at the Jupyter level
Then you need to enable the package at the Jupyter level
so that it becomes a server extension.
```bash
Expand Down Expand Up @@ -450,7 +450,7 @@ input_data = self.get_json_body()
data = {"greetings": "Hello {}, enjoy JupyterLab!".format(input_data["name"])}
```
The part responsible to serve static content with a `StaticFileHandler` handler
The part responsible to serve static content with a `StaticFileHandler` handler
is the following:
```py
Expand Down Expand Up @@ -486,7 +486,7 @@ through package managers like `pip`.
> Note: In particular, [`jupyter-packaging`](https://github.com/jupyter/jupyter-packaging) provides helpers to package and install JS files
> with a Python package for Jupyter frontends (classical notebook,
> JupyterLab,...).
> JupyterLab,...).
> As this package is a setup requirement, it needs to be specified in the `pyproject.toml` to be installed by `pip`.
The `setup.py` file is the entry point to describe package metadata:
Expand All @@ -497,6 +497,7 @@ The `setup.py` file is the entry point to describe package metadata:
"""
jlab_ext_example setup
"""
import json
import os

from jupyter_packaging import (
Expand All @@ -511,14 +512,15 @@ HERE = os.path.abspath(os.path.dirname(__file__))
name="jlab_ext_example"

# Get our version
version = get_version(os.path.join(name, "_version.py"))
with open(os.path.join(HERE, 'package.json')) as f:
version = json.load(f)['version']

lab_path = os.path.join(HERE, name, "static")
lab_path = os.path.join(HERE, name, "labextension")

# Representative files that should exist after a successful build
jstargets = [
os.path.join(HERE, "lib", "index.js"),
os.path.join(HERE, name, "static", "package.json"),
os.path.join(lab_path, "package.json"),
]

package_data_spec = {
Expand All @@ -530,7 +532,8 @@ package_data_spec = {
labext_name = "@jupyterlab-examples/server-extension"

data_files_spec = [
("share/jupyter/labextensions/%s" % labext_name, lab_path, "*.*"),("etc/jupyter/jupyter_server_config.d",
("share/jupyter/labextensions/%s" % labext_name, lab_path, "**"),
("share/jupyter/labextensions/%s" % labext_name, HERE, "install.json"),("etc/jupyter/jupyter_server_config.d",
"jupyter-config", "jlab_ext_example.json"),

]
Expand All @@ -541,7 +544,7 @@ cmdclass = create_cmdclass("jsdeps",
)

cmdclass["jsdeps"] = combine_commands(
install_npm(HERE, build_cmd="build", npm=["jlpm"]),
install_npm(HERE, build_cmd="build:prod", npm=["jlpm"]),
ensure_targets(jstargets),
)

Expand Down Expand Up @@ -590,35 +593,35 @@ the frontend NPM package needs to be built and inserted in the Python package. T
done using a special `cmdclass`:
```py
# setup.py#L42-L50
# setup.py#L45-L53

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

cmdclass["jsdeps"] = combine_commands(
install_npm(HERE, build_cmd="build", npm=["jlpm"]),
install_npm(HERE, build_cmd="build:prod", npm=["jlpm"]),
ensure_targets(jstargets),
)
```
Basically it will build the frontend NPM package:
```py
# setup.py#L48-L48
# setup.py#L51-L51

install_npm(HERE, build_cmd="build", npm=["jlpm"]),
install_npm(HERE, build_cmd="build:prod", npm=["jlpm"]),
```
It will ensure one of the generated JS files is `lib/jlabextexample.js`:
```py
# setup.py#L23-L26
# setup.py#L25-L28

jstargets = [
os.path.join(HERE, "lib", "index.js"),
os.path.join(HERE, name, "static", "package.json"),
os.path.join(lab_path, "package.json"),
]
```
Expand Down Expand Up @@ -663,9 +666,8 @@ user about that dependency by adding the `discovery` metadata to your `package.j
file:
```json5
// package.json#L68-L78
// package.json#L70-L80

],
"jupyterlab": {
"discovery": {
"server": {
Expand All @@ -676,20 +678,21 @@ file:
"name": "jlab_ext_example"
}
}
},
```
In this example, the extension requires a `server` extension:
```json5
// package.json#L70-L70
// package.json#L71-L71

"discovery": {
```

And that server extension is available through `pip`:

```json5
// package.json#L71-L73
// package.json#L72-L74

"server": {
"managers": [
Expand Down
2 changes: 1 addition & 1 deletion basics/hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ package is declared in the file `package.json`:
```json5
// package.json#L44-L46

"watch:src": "tsc -w"
},
"dependencies": {
"@jupyterlab/application": "^3.0.0-rc.7"
```
With this basic import setup, you can move on to construct a new instance
Expand Down
2 changes: 1 addition & 1 deletion main-menu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ After the execution of that command, `package.json` should list them in the
```json5
// package.json#L44-L48

"watch:src": "tsc -w"
},
"dependencies": {
"@jupyterlab/application": "^3.0.0-rc.7",
"@jupyterlab/mainmenu": "^3.0.0-rc.7",
"@lumino/widgets": "^1.14.0"
```
With this extension installed, a new menu _Main Menu Example_ should be present. And when
Expand Down
2 changes: 1 addition & 1 deletion settings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ the `package.json` file in the `jupyterlab` section (here `schema`):
```json5
// package.json#L68-L70

"style/*.css"
],
"jupyterlab": {
"extension": true,
```
<!-- prettier-ignore-end -->
Expand Down

0 comments on commit bfcc2da

Please sign in to comment.