Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to JupyterLab 3 #33

Merged
merged 6 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
coverage
**/*.d.ts
tests
39 changes: 39 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended'
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module'
},
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/naming-convention': [
'error',
{
'selector': 'interface',
'format': ['PascalCase'],
'custom': {
'regex': '^I[A-Z]',
'match': true
}
}
],
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/quotes': [
'error',
'single',
{ avoidEscape: true, allowTemplateLiterals: false }
],
curly: ['error', 'all'],
eqeqeq: 'error',
'prefer-arrow-callback': 'error'
}
};
42 changes: 34 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,48 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: Install node
uses: actions/setup-node@v1
with:
node-version: '10.x'
node-version: '12.x'
- name: Install Python
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: '3.7'
architecture: 'x64'


- name: Setup pip cache
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: pip-3.7-${{ hashFiles('package.json') }}
restore-keys: |
pip-3.7-
pip-

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Setup yarn cache
uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
yarn-

- name: Install dependencies
run: python -m pip install jupyterlab
run: python -m pip install -U jupyterlab~=3.0 jupyter_packaging~=0.7.9
- name: Build the extension
run: |
pip install .
jupyter lab build
jupyter serverextension list
jupyter labextension list
jlpm
jlpm run eslint:check
python -m pip install .

jupyter server extension list 2>&1 | grep -ie "jupyterlab_snippets.*OK"
jupyter labextension list 2>&1 | grep -ie "jupyterlab-snippets.*OK"

python -m jupyterlab.browser_check
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
*.bundle.*
lib/
node_modules/
*.egg-info/
.ipynb_checkpoints
*.tsbuildinfo
jupyterlab_snippets/labextension

# Created by https://www.gitignore.io/api/python
# Edit at https://www.gitignore.io/?templates=python
Expand Down Expand Up @@ -32,7 +34,6 @@ var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
Expand Down Expand Up @@ -107,5 +108,8 @@ dmypy.json

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

# OSX files
.DS_Store

yarn.lock
.vscode
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
**/node_modules
**/lib
**/package.json
jupyterlab-snippets
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "none",
"arrowParens": "avoid"
}
8 changes: 5 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
include LICENSE
include README.md

include setupbase.py
include pyproject.toml
include jupyter-config/jupyterlab-snippets.json

include package.json
include install.json
include ts*.json
include jupyterlab-snippets/labextension/*.tgz
include yarn.lock

graft jupyterlab_snippets/labextension

# Javascript files
graft src
Expand Down
46 changes: 19 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Using pip:
pip install jupyterlab-snippets
```

Rebuild JupyterLab:
If you use JupyterLab 2.x, you will have to rebuild JupyterLab with:

```bash
jupyter lab build
Expand Down Expand Up @@ -93,52 +93,44 @@ jupyter lab clean
jupyter lab build
```

## Contributing
## Development Install

### Development Install
Note: You will need NodeJS to build the extension package.

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

```bash
# Clone the repo to your local environment
# Move to jupyterlab-snippets directory
# Install the server extension
# Change directory to the jupyterlab-snippets directory
# Install package in development mode
pip install -e .

# Register the server extension
jupyter serverextension enable --py jupyterlab-snippets

# Install the dependencies
jlpm

# Build the TypeScript source
jlpm build

# Link your development version of the extension with JupyterLab
jupyter labextension link .
jupyter labextension develop . --overwrite
# Rebuild extension Typescript source after making changes
jlpm run build
```

# Rebuild the TypeScript source after making changes
jlpm build
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.

# Rebuild JupyterLab after making any changes
jupyter lab build
```bash
# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm run watch
# Run JupyterLab in another terminal
jupyter lab
```

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.
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).

```bash
# Watch the source directory in another terminal tab
jlpm watch
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:

# Run jupyterlab in watch mode in one terminal tab
jupyter lab --watch
```bash
jupyter lab build --minimize=False
```

### Uninstall

```bash
pip uninstall jupyterlab-snippets
jupyter labextension uninstall jupyterlab-snippets
```
20 changes: 16 additions & 4 deletions binder/environment.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
name: jupyterlan-snippets
# a mybinder.org-ready environment for demoing jupyterlab-snippets
# this environment may also be used locally on Linux/MacOS/Windows, e.g.
#
# conda env update --file binder/environment.yml
# conda activate jupyterlab-snippets-demo
#
name: jupyterlab-snippets-demo

channels:
- conda-forge

dependencies:
- jupyterlab-snippets=0.3.2
- jupyterlab >=2
- nodejs
# runtime dependencies
- python >=3.8,<3.9.0a0
- jupyterlab >=3,<4.0.0a0
# labextension build dependencies
- nodejs >=14,<15
- pip
- wheel
27 changes: 23 additions & 4 deletions binder/postBuild
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash
#!/usr/bin/env sh
""" perform a development install of jupyterlab-snippets

# install snippets
On Binder, this will run _after_ the environment has been fully created from
the environment.yml in this directory.
"""

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

ln -s $SNIPPET_DIR snippets_symlink

# prepare Jupyter Lab
cd ..

jupyter lab build
# verify the environment is self-consistent before even starting
python -m pip check

# install the labextension
python -m pip install -e .

# verify the environment the extension didn't break anything
python -m pip check

# list the extensions
jupyter server extension list

# initially list installed extensions to determine if there are any surprises
jupyter labextension list


echo "JupyterLab with jupyterlab-snippets is ready to run with:"
echo " jupyter lab"
5 changes: 5 additions & 0 deletions install.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"packageManager": "python",
"packageName": "jupyterlab-snippets",
"uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package jupyterlab-snippets"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"NotebookApp": {
"nbserver_extensions": {
"jupyterlab-snippets": true
"jupyterlab_snippets": true
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ServerApp": {
"jpserver_extensions": {
"jupyterlab_snippets": true
}
}
}
21 changes: 0 additions & 21 deletions jupyterlab-snippets/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions jupyterlab-snippets/_version.py

This file was deleted.

35 changes: 35 additions & 0 deletions jupyterlab_snippets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import json
from pathlib import Path

from ._version import __version__
from .handlers import setup_handlers
from .loader import SnippetsLoader

HERE = Path(__file__).parent.resolve()

with (HERE / "labextension" / "package.json").open() as fid:
data = json.load(fid)


def _jupyter_labextension_paths():
return [{"src": "labextension", "dest": data["name"]}]


def _jupyter_server_extension_points():
return [{"module": "jupyterlab_snippets"}]


def _load_jupyter_server_extension(server_app):
"""Registers the API handler to receive HTTP requests from the frontend extension.

Parameters
----------
server_app: jupyterlab.labapp.LabApp
JupyterLab application instance
"""
loader = SnippetsLoader()
setup_handlers(server_app.web_app, loader)


# For backward compatibility with the classical notebook
load_jupyter_server_extension = _load_jupyter_server_extension
Loading