Skip to content

Commit

Permalink
Merge pull request #79 from datalayer-contrib/jupyter_server
Browse files Browse the repository at this point in the history
JupyterLab Server as Server Extension
  • Loading branch information
Zsailer authored Aug 4, 2020
2 parents e4afa81 + a052cfb commit db02cf4
Show file tree
Hide file tree
Showing 22 changed files with 753 additions and 637 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ jobs:
PLATFORM: 'windows-latest'
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v1
- name: Cache pip
uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-py-${{ matrix.PYTHON_VERSION }}-pip-${{ hashFiles('**/setup.py') }}
- name: Setup python
- name: Setup python ${{ matrix.PYTHON_VERSION }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.PYTHON_VERSION }}
architecture: 'x64'
- name: Install python dependencies
run: |
pip install setuptools pip --upgrade
pip install setuptools pip --upgrade --user
pip install -v -e ".[test]"
- name: Show python environment
run: |
Expand All @@ -50,7 +51,7 @@ jobs:
- name: Run python tests
# See `setup.cfg` for full test options
run: |
pytest --cov-fail-under 71
pytest
- name: Upload coverage
run: |
codecov
1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest_plugins = ['pytest_jupyter_server']
8 changes: 8 additions & 0 deletions jupyterlab_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@
'SETTINGS_EXTENSION',
'WORKSPACE_EXTENSION'
]

def _jupyter_server_extension_points():
return [
{
'module': 'jupyterlab_server',
'app': LabServerApp
}
]
37 changes: 30 additions & 7 deletions jupyterlab_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,34 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

import os, jinja2
from traitlets import Unicode
from jinja2 import Environment, FileSystemLoader
from traitlets import Bool, Unicode, default
from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin
from traitlets import Unicode, Integer, Dict

from .server import ServerApp
from ._version import __version__
from .server import url_path_join as ujoin
from .handlers import add_handlers, LabConfig


class LabServerApp(ServerApp):
class LabServerApp(ExtensionAppJinjaMixin, LabConfig, ExtensionApp):
"""A Lab Server Application that runs out-of-the-box"""
name = "jupyterlab_server"
extension_url = "/lab"
app_name = "JupyterLab Server Application"
app_version = __version__

@property
def app_namespace(self):
return self.name

default_url = Unicode('/lab',
help='The default URL to redirect to from `/`')

lab_config = LabConfig()
# Should your extension expose other server extensions when launched directly?
load_other_extensions = True

blacklist_uris = Unicode('', config=True,
help="A list of comma-separated URIs to get the blacklist")
Expand All @@ -30,9 +46,16 @@ class LabServerApp(ServerApp):
help="The optional kwargs to use for the listings HTTP requests \
as described on https://2.python-requests.org/en/v2.7.0/api/#requests.request")

def start(self):
add_handlers(self.web_app, self.lab_config)
super().start()
def initialize_templates(self):
self.static_paths = [self.static_dir]
self.template_paths = [self.templates_dir]

def initialize_settings(self):
settings = self.serverapp.web_app.settings
# By default, make terminals available.
settings.setdefault('terminals_available', True)

def initialize_handlers(self):
add_handlers(self.handlers, self)

main = LabServerApp.launch_instance
main = launch_new_instance = LabServerApp.launch_instance
Loading

0 comments on commit db02cf4

Please sign in to comment.