Преглед на файлове

Add some of the labextension pieces

Steven Silvester преди 8 години
родител
ревизия
b72af1c1b9
променени са 3 файла, в които са добавени 28 реда и са изтрити 9 реда
  1. 16 8
      jupyterlab/__init__.py
  2. 11 1
      jupyterlab/labapp.py
  3. 1 0
      setup.py

+ 16 - 8
jupyterlab/__init__.py

@@ -9,7 +9,6 @@ from notebook.base.handlers import IPythonHandler, FileFindHandler
 from jinja2 import FileSystemLoader
 from notebook.utils import url_path_join as ujoin
 
-
 #-----------------------------------------------------------------------------
 # Module globals
 #-----------------------------------------------------------------------------
@@ -19,9 +18,9 @@ If you're working on the TypeScript sources of JupyterLab, try running
 
     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 @@ class LabHandler(IPythonHandler):
 
 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])

+ 11 - 1
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
 #-----------------------------------------------------------------------------

+ 1 - 0
setup.py

@@ -154,6 +154,7 @@ setup_args = {
     'entry_points': {
         'console_scripts': [
             'jupyter-lab = jupyterlab.labapp:main',
+            'jupyter-labextension = jupyterlab.labextensions:main',
         ]
     },
     'author': 'Jupyter Development Team',