From b72af1c1b99d0563ca501ac7175c82faff3790ba Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 7 Sep 2016 06:20:38 -0500 Subject: [PATCH] Add some of the labextension pieces --- jupyterlab/__init__.py | 24 ++++++++++++++++-------- jupyterlab/labapp.py | 12 +++++++++++- setup.py | 1 + 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/jupyterlab/__init__.py b/jupyterlab/__init__.py index c760f9806d87..45efe54d65a5 100644 --- a/jupyterlab/__init__.py +++ b/jupyterlab/__init__.py @@ -9,7 +9,6 @@ from jinja2 import FileSystemLoader from notebook.utils import url_path_join as ujoin - #----------------------------------------------------------------------------- # Module globals #----------------------------------------------------------------------------- @@ -19,9 +18,9 @@ npm run watch -from the JupyterLab repo directory in another terminal window to have the system -incrementally watch and build JupyterLab's TypeScript for you, as you make -changes. +from the JupyterLab repo directory in another terminal window to have the +system incrementally watch and build JupyterLab's TypeScript for you, as you +make changes. """ HERE = os.path.dirname(__file__) @@ -54,9 +53,10 @@ def get_template(self, name): default_handlers = [ (PREFIX + r'/?', LabHandler), - (PREFIX+r"/(.+)", FileFindHandler, + (PREFIX + r"/(.*)", FileFindHandler, {'path': BUILT_FILES}), - ] +] + def _jupyter_server_extension_paths(): return [{ @@ -69,7 +69,15 @@ def load_jupyter_server_extension(nbapp): dev_mode = os.path.exists(os.path.join(base_dir, '.git')) if dev_mode: nbapp.log.info(DEV_NOTE_NPM) - nbapp.log.info('JupyterLab alpha preview extension loaded from %s'%HERE) + nbapp.log.info('JupyterLab alpha preview extension loaded from %s' % HERE) webapp = nbapp.web_app base_url = webapp.settings['base_url'] - webapp.add_handlers(".*$", [(ujoin(base_url, h[0]),) + h[1:] for h in default_handlers]) + webapp.add_handlers(".*$", + [(ujoin(base_url, h[0]),) + h[1:] for h in default_handlers]) + lab_extension_handler = ( + r"/labextensions/(.*)", FileFindHandler, { + 'path': nbapp.labextensions_path, + 'no_cache_paths': ['/'], # don't cache anything in labbextensions + } + ) + webapp.add_handlers(".*$", [lab_extension_handler]) diff --git a/jupyterlab/labapp.py b/jupyterlab/labapp.py index 5a52171b2bf3..53d652f8f4c7 100644 --- a/jupyterlab/labapp.py +++ b/jupyterlab/labapp.py @@ -5,8 +5,9 @@ # Distributed under the terms of the Modified BSD License. # TODO: import base server app +from jupyter_core.paths import jupyter_path from notebook.notebookapp import NotebookApp -from traitlets import Unicode +from traitlets import List, Unicode class LabApp(NotebookApp): @@ -15,6 +16,15 @@ class LabApp(NotebookApp): help="The default URL to redirect to from `/`" ) + extra_labextensions_path = List(Unicode(), config=True, + help="""extra paths to look for JupyterLab extensions""" + ) + + @property + def labextensions_path(self): + """The path to look for JupyterLab extensions""" + return self.extra_labextensions_path + jupyter_path('labextensions') + #----------------------------------------------------------------------------- # Main entry point #----------------------------------------------------------------------------- diff --git a/setup.py b/setup.py index 87a95cdf8caa..c4656006870d 100644 --- a/setup.py +++ b/setup.py @@ -154,6 +154,7 @@ def run(self): 'entry_points': { 'console_scripts': [ 'jupyter-lab = jupyterlab.labapp:main', + 'jupyter-labextension = jupyterlab.labextensions:main', ] }, 'author': 'Jupyter Development Team',