Skip to content

Commit

Permalink
Merge pull request #551 from ajbozarth/lab3
Browse files Browse the repository at this point in the history
Update to Jupyterlab 3.0
  • Loading branch information
vidartf authored Jan 14, 2021
2 parents 75363a0 + 8c52de8 commit a0726e5
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ MANIFEST
.coverage
.cache
.pytest_cache
.idea


.spyderproject
Expand Down
10 changes: 7 additions & 3 deletions docs/source/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ Installing Jupyter extensions
If you want to use the development version of the notebook and lab extensions,
you will also have to run the following commands after the pip dev install::

jupyter serverextension enable --py nbdime [--sys-prefix/--user/--system]
> Note: only run one of the following two server commands, running both can cause issues in some cases

jupyter nbextension install --py nbdime [--sym-link] [--sys-prefix/--user/--system]
jupyter nbextension enable --py nbdime [--sys-prefix/--user/--system]
jupyter serverextension enable --py nbdime --sys-prefix # if developing for jupyter notebook

jupyter server extension enable nbdime # if developing for jupyter lab or nbclassic

jupyter nbextension install --py nbdime --sys-prefix [--sym-link]
jupyter nbextension enable --py nbdime --sys-prefix

jupyter labextension link ./packages/nbdime --no-build
jupyter labextension install ./packages/labextension
Expand Down
2 changes: 1 addition & 1 deletion docs/source/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Dependencies

Install the test dependencies::

pip install "nbdime[test]"
pip install .[test]

Running tests locally
---------------------
Expand Down
7 changes: 7 additions & 0 deletions jupyter-config/jupyter_server_config.d/nbdime.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ServerApp": {
"jpserver_extensions": {
"nbdime": true
}
}
}
9 changes: 9 additions & 0 deletions nbdime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ def load_jupyter_server_extension(nb_server_app):
_load_jupyter_server_extension(nb_server_app)


_load_jupyter_server_extension = load_jupyter_server_extension


def _jupyter_server_extension_paths():
return [{
"module": "nbdime"
}]


_jupyter_server_extension_points = _jupyter_server_extension_paths


def _jupyter_nbextension_paths():
return [dict(
section="notebook",
Expand All @@ -41,4 +47,7 @@ def _jupyter_nbextension_paths():
"patch", "patch_notebook",
"decide_merge", "merge_notebooks", "apply_decisions",
"load_jupyter_server_extension",
"_load_jupyter_server_extension",
"_jupyter_server_extension_points",
"_jupyter_server_extension_paths",
]
2 changes: 1 addition & 1 deletion nbdime/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version_info = (2, 1, 1, 'dev')
version_info = (3, 0, 0, 'dev0')
__version__ = ".".join(map(str, version_info))
22 changes: 14 additions & 8 deletions nbdime/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,25 +441,31 @@ def _term():



def create_server_extension_config(tmpdir_factory):
def create_server_extension_config(tmpdir_factory, cmd):
appname = 'NotebookApp' if cmd == 'notebook' else 'ServerApp'
filename = 'jupyter_notebook_config.json' if cmd == 'notebook' else 'jupyter_server_config.json'
config_entry = 'nbserver_extensions' if cmd == 'notebook' else 'jpserver_extensions'
path = tmpdir_factory.mktemp('server-extension-config')
config = {
"NotebookApp": {
"nbserver_extensions": {
appname: {
config_entry: {
"nbdime": True
}
}
}
config_str = json.dumps(config)
if isinstance(config_str, bytes):
config_str = unicode(config_str)
path.join('jupyter_notebook_config.json').write_text(config_str, 'utf-8')
path.join(filename).write_text(config_str, 'utf-8')
return str(path)



@fixture(scope='module')
@fixture(scope='module', params=('notebook', 'jupyter_server'))
def server_extension_app(tmpdir_factory, request):
cmd = request.param

appname = 'NotebookApp' if cmd == 'notebook' else 'ServerApp'

def _kill_nb_app():
try:
Expand All @@ -469,7 +475,7 @@ def _kill_nb_app():
pass
popen_wait(process, 10)

config_dir = create_server_extension_config(tmpdir_factory)
config_dir = create_server_extension_config(tmpdir_factory, cmd)
env = os.environ.copy()
env.update({'JUPYTER_CONFIG_DIR': config_dir})

Expand All @@ -478,10 +484,10 @@ def _kill_nb_app():

os.chdir(root_dir)
process = Popen([
sys.executable, '-m', 'notebook',
sys.executable, '-m', cmd,
'--port=%i' % port,
'--ip=127.0.0.1',
'--no-browser', '--NotebookApp.token=%s' % TEST_TOKEN],
'--no-browser', '--%s.token=%s' % (appname, TEST_TOKEN)],
env=env)

request.addfinalizer(_kill_nb_app)
Expand Down
6 changes: 1 addition & 5 deletions nbdime/tests/test_git_filter_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ def test_apply_filter_invalid_filter(git_repo):


def test_apply_filter_valid_filter(git_repo):
try:
call('cat --help')
filter_cmd = 'cat'
except (CalledProcessError, FileNotFoundError):
filter_cmd = 'findstr x*'
filter_cmd = 'findstr x*' if os.name == 'nt' else 'cat'
path = pjoin(git_repo, 'diff.ipynb')
gitattr = locate_gitattributes()
with io.open(gitattr, 'a', encoding="utf8") as f:
Expand Down
7 changes: 4 additions & 3 deletions nbdime/tests/test_server_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
import requests
import shutil
import uuid

import pytest

Expand Down Expand Up @@ -149,7 +150,6 @@ def test_diff_api_checkpoint(tmpdir, filespath, server_extension_app):
if os.sep == '\\':
url_path = url_path.replace('\\', '/')


# Create checkpoint
url = 'http://127.0.0.1:%i/api/contents/%s/checkpoints' % (
server_extension_app['port'],
Expand All @@ -164,7 +164,8 @@ def test_diff_api_checkpoint(tmpdir, filespath, server_extension_app):

url = 'http://127.0.0.1:%i/nbdime/api/diff' % server_extension_app['port']
r = requests.post(
url, headers=auth_header,
url,
headers=auth_header,
data=json.dumps({
'base': 'checkpoint:' + url_path,
}))
Expand All @@ -178,7 +179,7 @@ def test_diff_api_checkpoint(tmpdir, filespath, server_extension_app):
@pytest.mark.timeout(timeout=WEB_TEST_TIMEOUT)
def test_diff_api_symlink(git_repo2, server_extension_app, needs_symlink):
root = server_extension_app['path']
subdir = pjoin(root, 'has space', 'subdir')
subdir = pjoin(root, str(uuid.uuid4()), 'has space', 'subdir')
os.makedirs(subdir)
symlink = pjoin(subdir, 'link')
with pushd(subdir):
Expand Down
32 changes: 27 additions & 5 deletions nbdime/webapp/nb_server_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,31 @@

from jinja2 import ChoiceLoader, FileSystemLoader

from notebook.utils import url_path_join, to_os_path
from notebook.services.contents.checkpoints import GenericCheckpointsMixin
from notebook.services.contents.filecheckpoints import FileCheckpoints
from jupyter_server.utils import url_path_join, to_os_path

generic_checkpoint_mixin_types = []
file_checkpoint_mixin_types = []

try:
from jupyter_server.services.contents.checkpoints import GenericCheckpointsMixin as jpserver_GenericCheckpointsMixin
from jupyter_server.services.contents.filecheckpoints import FileCheckpoints as jpserver_FileCheckpoints
generic_checkpoint_mixin_types.append(jpserver_GenericCheckpointsMixin)
file_checkpoint_mixin_types.append(jpserver_FileCheckpoints)
except ModuleNotFoundError:
pass

try:
from notebook.services.contents.checkpoints import GenericCheckpointsMixin as nbserver_GenericCheckpointsMixin
from notebook.services.contents.filecheckpoints import FileCheckpoints as nbserver_FileCheckpoints
generic_checkpoint_mixin_types.append(nbserver_GenericCheckpointsMixin)
file_checkpoint_mixin_types.append(nbserver_FileCheckpoints)
except ModuleNotFoundError:
pass

generic_checkpoint_mixin_types = tuple(generic_checkpoint_mixin_types)
file_checkpoint_mixin_types = tuple(file_checkpoint_mixin_types)


from tornado.web import HTTPError, escape, authenticated, gen

from ..args import process_diff_flags
Expand Down Expand Up @@ -148,11 +170,11 @@ def _get_checkpoint_notebooks(self, base):
raise gen.Return((remote_nb, remote_nb))
self.log.debug('Checkpoints: %r', checkpoints)
checkpoint = checkpoints[0]
if isinstance(cm.checkpoints, GenericCheckpointsMixin):
if isinstance(cm.checkpoints, generic_checkpoint_mixin_types):
checkpoint_model = yield gen.maybe_future(
cm.checkpoints.get_notebook_checkpoint(checkpoint, base))
base_nb = checkpoint_model['content']
elif isinstance(cm.checkpoints, FileCheckpoints):
elif isinstance(cm.checkpoints, file_checkpoint_mixin_types):
path = yield gen.maybe_future(
cm.checkpoints.checkpoint_path(checkpoint['id'], base))
base_nb = read_notebook(path, on_null='minimal')
Expand Down
10 changes: 5 additions & 5 deletions nbdime/webapp/nbdimeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

from jinja2 import FileSystemLoader, Environment
import nbformat
from notebook.base.handlers import IPythonHandler, APIHandler
from notebook import DEFAULT_STATIC_FILES_PATH
from notebook.utils import url_path_join
from notebook.log import log_request
from jupyter_server.base.handlers import JupyterHandler, APIHandler
from jupyter_server import DEFAULT_STATIC_FILES_PATH
from jupyter_server.utils import url_path_join
from jupyter_server.log import log_request
import requests
from six import string_types
from tornado import ioloop, web, escape, netutil, httpserver
Expand Down Expand Up @@ -43,7 +43,7 @@
template_path = os.path.join(here, 'templates')


class NbdimeHandler(IPythonHandler):
class NbdimeHandler(JupyterHandler):
def initialize(self, **params):
self.params = params

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"watch": "tsc --build --watch"
},
"devDependencies": {
"@jupyterlab/buildutils": "^2.0.0",
"@jupyterlab/buildutils": "^3.0.0",
"lerna": "^3.14.1",
"rimraf": "^2.6.3"
}
Expand Down
22 changes: 11 additions & 11 deletions packages/labextension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nbdime-jupyterlab",
"version": "2.0.1",
"version": "2.1.0",
"description": "A JupyterLab extension for showing Notebook diffs.",
"keywords": [
"jupyter",
Expand Down Expand Up @@ -38,22 +38,22 @@
"watch": "tsc --build --watch"
},
"dependencies": {
"@jupyterlab/apputils": "^2.0.0",
"@jupyterlab/coreutils": "^4.0.0",
"@jupyterlab/nbformat": "^2.0.0",
"@jupyterlab/notebook": "^2.0.0",
"@jupyterlab/rendermime": "^2.0.0",
"@jupyterlab/services": "^5.0.0",
"@jupyterlab/settingregistry": "^2.0.0",
"@jupyterlab/apputils": "^2 || ^3",
"@jupyterlab/coreutils": "^4 || ^5",
"@jupyterlab/nbformat": "^2 || ^3",
"@jupyterlab/notebook": "^2 || ^3",
"@jupyterlab/rendermime": "^2 || ^3",
"@jupyterlab/services": "^5 || ^6",
"@jupyterlab/settingregistry": "^2 || ^3",
"@lumino/algorithm": "^1.1.2",
"@lumino/coreutils": "^1.3.0",
"@lumino/disposable": "^1.1.2",
"@lumino/widgets": "^1.6.0",
"nbdime": "^6.0.0"
"nbdime": "^6.1.0"
},
"devDependencies": {
"@jupyterlab/application": "^2.0.0",
"@jupyterlab/docregistry": "^2.0.0",
"@jupyterlab/application": "^2 || ^3",
"@jupyterlab/docregistry": "^2 || ^3",
"@lumino/commands": "^1.6.1",
"mkdirp": "^0.5.1",
"rimraf": "^2.6.3",
Expand Down
34 changes: 16 additions & 18 deletions packages/nbdime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nbdime",
"version": "6.0.0",
"version": "6.1.0",
"description": "Diff and merge of Jupyter Notebooks",
"repository": {
"type": "git",
Expand All @@ -19,17 +19,16 @@
"test:chrome": "karma start --browsers=Chrome test/karma.conf.js",
"test:debug": "karma start --browsers=Chrome --singleRun=false --debug=true test/karma-nocov.conf.js",
"test:firefox": "karma start --browsers=Firefox test/karma.conf.js",
"test:ie": "karma start --browsers=IE test/karma.conf.js",
"watch": "tsc --build --watch"
},
"dependencies": {
"@jupyterlab/codeeditor": "^2.0.0",
"@jupyterlab/codemirror": "^2.0.0",
"@jupyterlab/coreutils": "^4.0.0",
"@jupyterlab/nbformat": "^2.0.0",
"@jupyterlab/outputarea": "^2.0.0",
"@jupyterlab/rendermime": "^2.0.0",
"@jupyterlab/services": "^5.0.0",
"@jupyterlab/codeeditor": "^2 || ^3",
"@jupyterlab/codemirror": "^2 || ^3",
"@jupyterlab/coreutils": "^4 || ^5",
"@jupyterlab/nbformat": "^2 || ^3",
"@jupyterlab/outputarea": "^2 || ^3",
"@jupyterlab/rendermime": "^2 || ^3",
"@jupyterlab/services": "^5 || ^6",
"@lumino/algorithm": "^1.1.2",
"@lumino/coreutils": "^1.3.0",
"@lumino/dragdrop": "^1.3.0",
Expand All @@ -38,24 +37,23 @@
"json-stable-stringify": "^1.0.1"
},
"devDependencies": {
"@jupyterlab/apputils": "^2.0.0",
"@jupyterlab/apputils": "^2 || ^3",
"@lumino/messaging": "^1.2.2",
"@types/expect.js": "^0.3.29",
"@types/json-stable-stringify": "^1.0.32",
"@types/mocha": "^5.2.6",
"@types/node": "^12.0.10",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.13",
"@types/sanitizer": "^0.0.28",
"expect.js": "^0.3.1",
"fs-extra": "^8.1.0",
"karma": "^4.0.1",
"karma-chrome-launcher": "^2.2.0",
"karma-firefox-launcher": "^1.1.0",
"karma-ie-launcher": "^1.0.0",
"karma-mocha": "^1.3.0",
"karma": "^5.2.3",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^2.1.0",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-typescript": "^4.0.0",
"karma-typescript-es6-transform": "^4.0.0",
"mocha": "^6.0.2",
"mocha": "^8.2.1",
"rimraf": "^2.6.3",
"typescript": "^3.7.2"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/nbdime/test/src/common/flexpanel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ import {
*/
function combinatorialTest(
description: string,
steps: ((done: MochaDone) => void)[] | { [key: string]: ((done?: MochaDone) => void) },
beforeEach?: (done: MochaDone) => void,
afterEach?: (done: MochaDone) => void) {
steps: ((done: Mocha.Done) => void)[] | { [key: string]: ((done?: Mocha.Done) => void) },
beforeEach?: (done: Mocha.Done) => void,
afterEach?: (done: Mocha.Done) => void) {
let stepNames: string[];
if (Array.isArray(steps)) {
stepNames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
} else {
stepNames = Object.keys(steps);
let stepArray: ((done?: MochaDone) => void)[] = [];
let stepArray: ((done?: Mocha.Done) => void)[] = [];
for (let key of stepNames) {
stepArray.push(steps[key]);
}
Expand Down
Loading

0 comments on commit a0726e5

Please sign in to comment.