Skip to content

Commit a38b622

Browse files
authored
Merge pull request #33 from fcollonval/ft/jlab3
Port to JupyterLab 3
2 parents e0f2f34 + 5125c0f commit a38b622

28 files changed

+354
-874
lines changed

Diff for: .eslintignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
coverage
4+
**/*.d.ts
5+
tests

Diff for: .eslintrc.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module.exports = {
2+
extends: [
3+
'eslint:recommended',
4+
'plugin:@typescript-eslint/eslint-recommended',
5+
'plugin:@typescript-eslint/recommended',
6+
'plugin:prettier/recommended'
7+
],
8+
parser: '@typescript-eslint/parser',
9+
parserOptions: {
10+
project: 'tsconfig.json',
11+
sourceType: 'module'
12+
},
13+
plugins: ['@typescript-eslint'],
14+
rules: {
15+
'@typescript-eslint/naming-convention': [
16+
'error',
17+
{
18+
'selector': 'interface',
19+
'format': ['PascalCase'],
20+
'custom': {
21+
'regex': '^I[A-Z]',
22+
'match': true
23+
}
24+
}
25+
],
26+
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
27+
'@typescript-eslint/no-explicit-any': 'off',
28+
'@typescript-eslint/no-namespace': 'off',
29+
'@typescript-eslint/no-use-before-define': 'off',
30+
'@typescript-eslint/quotes': [
31+
'error',
32+
'single',
33+
{ avoidEscape: true, allowTemplateLiterals: false }
34+
],
35+
curly: ['error', 'all'],
36+
eqeqeq: 'error',
37+
'prefer-arrow-callback': 'error'
38+
}
39+
};

Diff for: .github/workflows/build.yml

+34-8
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,48 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v1
14+
uses: actions/checkout@v2
1515
- name: Install node
1616
uses: actions/setup-node@v1
1717
with:
18-
node-version: '10.x'
18+
node-version: '12.x'
1919
- name: Install Python
20-
uses: actions/setup-python@v1
20+
uses: actions/setup-python@v2
2121
with:
2222
python-version: '3.7'
2323
architecture: 'x64'
24+
25+
26+
- name: Setup pip cache
27+
uses: actions/cache@v2
28+
with:
29+
path: ~/.cache/pip
30+
key: pip-3.7-${{ hashFiles('package.json') }}
31+
restore-keys: |
32+
pip-3.7-
33+
pip-
34+
35+
- name: Get yarn cache directory path
36+
id: yarn-cache-dir-path
37+
run: echo "::set-output name=dir::$(yarn cache dir)"
38+
- name: Setup yarn cache
39+
uses: actions/cache@v2
40+
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
41+
with:
42+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
43+
key: yarn-${{ hashFiles('**/yarn.lock') }}
44+
restore-keys: |
45+
yarn-
46+
2447
- name: Install dependencies
25-
run: python -m pip install jupyterlab
48+
run: python -m pip install -U jupyterlab~=3.0 jupyter_packaging~=0.7.9
2649
- name: Build the extension
2750
run: |
28-
pip install .
29-
jupyter lab build
30-
jupyter serverextension list
31-
jupyter labextension list
51+
jlpm
52+
jlpm run eslint:check
53+
python -m pip install .
54+
55+
jupyter server extension list 2>&1 | grep -ie "jupyterlab_snippets.*OK"
56+
jupyter labextension list 2>&1 | grep -ie "jupyterlab-snippets.*OK"
57+
3258
python -m jupyterlab.browser_check

Diff for: .gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
*.bundle.*
22
lib/
33
node_modules/
4+
*.egg-info/
45
.ipynb_checkpoints
56
*.tsbuildinfo
7+
jupyterlab_snippets/labextension
68

79
# Created by https://www.gitignore.io/api/python
810
# Edit at https://www.gitignore.io/?templates=python
@@ -32,7 +34,6 @@ var/
3234
wheels/
3335
pip-wheel-metadata/
3436
share/python-wheels/
35-
*.egg-info/
3637
.installed.cfg
3738
*.egg
3839
MANIFEST
@@ -107,5 +108,8 @@ dmypy.json
107108

108109
# End of https://www.gitignore.io/api/python
109110

111+
# OSX files
112+
.DS_Store
113+
110114
yarn.lock
111115
.vscode

Diff for: .prettierignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
**/node_modules
3+
**/lib
4+
**/package.json
5+
jupyterlab-snippets

Diff for: .prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "none",
4+
"arrowParens": "avoid"
5+
}

Diff for: MANIFEST.in

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
include LICENSE
22
include README.md
3-
4-
include setupbase.py
3+
include pyproject.toml
54
include jupyter-config/jupyterlab-snippets.json
65

76
include package.json
7+
include install.json
88
include ts*.json
9-
include jupyterlab-snippets/labextension/*.tgz
9+
include yarn.lock
10+
11+
graft jupyterlab_snippets/labextension
1012

1113
# Javascript files
1214
graft src

Diff for: README.md

+19-27
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Using pip:
3030
pip install jupyterlab-snippets
3131
```
3232

33-
Rebuild JupyterLab:
33+
If you use JupyterLab 2.x, you will have to rebuild JupyterLab with:
3434

3535
```bash
3636
jupyter lab build
@@ -93,52 +93,44 @@ jupyter lab clean
9393
jupyter lab build
9494
```
9595

96-
## Contributing
96+
## Development Install
9797

98-
### Development Install
98+
Note: You will need NodeJS to build the extension package.
9999

100100
The `jlpm` command is JupyterLab's pinned version of
101101
[yarn](https://yarnpkg.com/) that is installed with JupyterLab. You may use
102102
`yarn` or `npm` in lieu of `jlpm` below.
103103

104104
```bash
105105
# Clone the repo to your local environment
106-
# Move to jupyterlab-snippets directory
107-
# Install the server extension
106+
# Change directory to the jupyterlab-snippets directory
107+
# Install package in development mode
108108
pip install -e .
109-
110-
# Register the server extension
111-
jupyter serverextension enable --py jupyterlab-snippets
112-
113-
# Install the dependencies
114-
jlpm
115-
116-
# Build the TypeScript source
117-
jlpm build
118-
119109
# Link your development version of the extension with JupyterLab
120-
jupyter labextension link .
110+
jupyter labextension develop . --overwrite
111+
# Rebuild extension Typescript source after making changes
112+
jlpm run build
113+
```
121114

122-
# Rebuild the TypeScript source after making changes
123-
jlpm build
115+
You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.
124116

125-
# Rebuild JupyterLab after making any changes
126-
jupyter lab build
117+
```bash
118+
# Watch the source directory in one terminal, automatically rebuilding when needed
119+
jlpm run watch
120+
# Run JupyterLab in another terminal
121+
jupyter lab
127122
```
128123

129-
You can watch the source directory and run JupyterLab in watch mode to watch for changes in the extension's source and automatically rebuild the extension and application.
124+
With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).
130125

131-
```bash
132-
# Watch the source directory in another terminal tab
133-
jlpm watch
126+
By default, the `jlpm run build` command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:
134127

135-
# Run jupyterlab in watch mode in one terminal tab
136-
jupyter lab --watch
128+
```bash
129+
jupyter lab build --minimize=False
137130
```
138131

139132
### Uninstall
140133

141134
```bash
142135
pip uninstall jupyterlab-snippets
143-
jupyter labextension uninstall jupyterlab-snippets
144136
```

Diff for: binder/environment.yml

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
name: jupyterlan-snippets
1+
# a mybinder.org-ready environment for demoing jupyterlab-snippets
2+
# this environment may also be used locally on Linux/MacOS/Windows, e.g.
3+
#
4+
# conda env update --file binder/environment.yml
5+
# conda activate jupyterlab-snippets-demo
6+
#
7+
name: jupyterlab-snippets-demo
8+
29
channels:
310
- conda-forge
11+
412
dependencies:
5-
- jupyterlab-snippets=0.3.2
6-
- jupyterlab >=2
7-
- nodejs
13+
# runtime dependencies
14+
- python >=3.8,<3.9.0a0
15+
- jupyterlab >=3,<4.0.0a0
16+
# labextension build dependencies
17+
- nodejs >=14,<15
18+
- pip
19+
- wheel

Diff for: binder/postBuild

100644100755
+23-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
#!/bin/bash
1+
#!/usr/bin/env sh
2+
""" perform a development install of jupyterlab-snippets
23
3-
# install snippets
4+
On Binder, this will run _after_ the environment has been fully created from
5+
the environment.yml in this directory.
6+
"""
47

58
cd jupyter-boilerplate-converter
69
git clone git://github.com/moble/jupyter_boilerplate
@@ -23,7 +26,23 @@ cd ../binder
2326

2427
ln -s $SNIPPET_DIR snippets_symlink
2528

26-
# prepare Jupyter Lab
29+
cd ..
2730

28-
jupyter lab build
31+
# verify the environment is self-consistent before even starting
32+
python -m pip check
2933

34+
# install the labextension
35+
python -m pip install -e .
36+
37+
# verify the environment the extension didn't break anything
38+
python -m pip check
39+
40+
# list the extensions
41+
jupyter server extension list
42+
43+
# initially list installed extensions to determine if there are any surprises
44+
jupyter labextension list
45+
46+
47+
echo "JupyterLab with jupyterlab-snippets is ready to run with:"
48+
echo " jupyter lab"

Diff for: install.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"packageManager": "python",
3+
"packageName": "jupyterlab-snippets",
4+
"uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package jupyterlab-snippets"
5+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"NotebookApp": {
33
"nbserver_extensions": {
4-
"jupyterlab-snippets": true
4+
"jupyterlab_snippets": true
55
}
66
}
7-
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ServerApp": {
3+
"jpserver_extensions": {
4+
"jupyterlab_snippets": true
5+
}
6+
}
7+
}

Diff for: jupyterlab-snippets/__init__.py

-21
This file was deleted.

Diff for: jupyterlab-snippets/_version.py

-2
This file was deleted.

Diff for: jupyterlab_snippets/__init__.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import json
2+
from pathlib import Path
3+
4+
from ._version import __version__
5+
from .handlers import setup_handlers
6+
from .loader import SnippetsLoader
7+
8+
HERE = Path(__file__).parent.resolve()
9+
10+
with (HERE / "labextension" / "package.json").open() as fid:
11+
data = json.load(fid)
12+
13+
14+
def _jupyter_labextension_paths():
15+
return [{"src": "labextension", "dest": data["name"]}]
16+
17+
18+
def _jupyter_server_extension_points():
19+
return [{"module": "jupyterlab_snippets"}]
20+
21+
22+
def _load_jupyter_server_extension(server_app):
23+
"""Registers the API handler to receive HTTP requests from the frontend extension.
24+
25+
Parameters
26+
----------
27+
server_app: jupyterlab.labapp.LabApp
28+
JupyterLab application instance
29+
"""
30+
loader = SnippetsLoader()
31+
setup_handlers(server_app.web_app, loader)
32+
33+
34+
# For backward compatibility with the classical notebook
35+
load_jupyter_server_extension = _load_jupyter_server_extension

0 commit comments

Comments
 (0)