Skip to content

Commit 3132ddd

Browse files
Frédéric Collonvaljtpio
authored andcommitted
Port to JupyterLab 3
1 parent e0f2f34 commit 3132ddd

File tree

25 files changed

+308
-821
lines changed

25 files changed

+308
-821
lines changed

.eslintignore

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

.eslintrc.js

Lines changed: 39 additions & 0 deletions
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+
};

.github/workflows/build.yml

Lines changed: 34 additions & 8 deletions
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+
57+
jupyter labextension list 2>&1 | grep -ie "jupyterlab-snippets.*OK"
3258
python -m jupyterlab.browser_check

.gitignore

Lines changed: 5 additions & 1 deletion
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

.prettierignore

Lines changed: 5 additions & 0 deletions
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

.prettierrc

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

MANIFEST.in

Lines changed: 5 additions & 3 deletions
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

binder/environment.yml

Lines changed: 16 additions & 4 deletions
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

binder/postBuild

100644100755
Lines changed: 23 additions & 4 deletions
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"

install.json

Lines changed: 5 additions & 0 deletions
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+
}
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+
"jupyterlab_snippets": true
5+
}
6+
}
7+
}

jupyterlab-snippets/__init__.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

jupyterlab-snippets/_version.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

jupyterlab_snippets/__init__.py

Lines changed: 35 additions & 0 deletions
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

jupyterlab_snippets/_version.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import json
2+
from pathlib import Path
3+
4+
__all__ = ["__version__"]
5+
6+
def _fetchVersion():
7+
HERE = Path(__file__).parent.resolve()
8+
9+
for settings in HERE.rglob("package.json"):
10+
try:
11+
with settings.open() as f:
12+
return json.load(f)["version"]
13+
except FileNotFoundError:
14+
pass
15+
16+
raise FileNotFoundError(f"Could not find package.json under dir {HERE!s}")
17+
18+
__version__ = _fetchVersion()
19+
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)