Bläddra i källkod

clean up handling of app metadata

Steven Silvester 8 år sedan
förälder
incheckning
bef4999bf5
4 ändrade filer med 48 tillägg och 12 borttagningar
  1. 13 3
      jupyterlab/commands.py
  2. 0 2
      jupyterlab/extension.py
  3. 33 6
      jupyterlab/labapp.py
  4. 2 1
      jupyterlab/webpack.config.js

+ 13 - 3
jupyterlab/commands.py

@@ -7,6 +7,7 @@ import json
 import pipes
 import os
 import glob
+from uuid import uuid4
 from os import path as osp
 from os.path import join as pjoin
 from subprocess import check_output, CalledProcessError
@@ -15,6 +16,7 @@ import sys
 import tarfile
 from jupyter_core.paths import ENV_JUPYTER_PATH
 
+from ._version import __version__
 
 if sys.platform == 'win32':
     from subprocess import list2cmdline
@@ -149,11 +151,11 @@ def clean(app_dir=None):
             shutil.rmtree(target)
 
 
-def build(app_dir=None):
+def build(app_dir=None, name=None, version=None, publicPath=None):
     """Build the JupyterLab application."""
     # Set up the build directory.
     app_dir = app_dir or get_app_dir()
-    _ensure_package(app_dir)
+    _ensure_package(app_dir, name, version, publicPath)
     staging = pjoin(app_dir, 'staging')
 
     # Make sure packages are installed.
@@ -173,7 +175,7 @@ def build(app_dir=None):
     shutil.copytree(pjoin(staging, 'build'), static)
 
 
-def _ensure_package(app_dir):
+def _ensure_package(app_dir, name='JupyterLab', version=None, publicPath=None):
     """Make sure the build dir is set up.
     """
     if not os.path.exists(pjoin(app_dir, 'extensions')):
@@ -201,6 +203,14 @@ def _ensure_package(app_dir):
     for (key, value) in extensions.items():
         data['dependencies'][key] = value
         data['jupyterlab']['extensions'].append(key)
+
+    data['name'] = name
+    data['version'] = version or __version__
+
+    publicPath = publicPath or uuid4().hex
+    if not publicPath.endswith('/'):
+        publicPath += '/'
+    data['jupyterlab']['publicPath'] = publicPath
     data['scripts']['build'] = 'webpack'
 
     pkg_path = pjoin(staging, 'package.json')

+ 0 - 2
jupyterlab/extension.py

@@ -47,9 +47,7 @@ def load_jupyter_server_extension(nbapp):
     config.assets_dir = os.path.join(app_dir, 'static')
     config.settings_dir = os.path.join(app_dir, 'settings')
     config.page_title = 'JupyterLab Alpha Preview'
-    config.name = 'JupyterLab'
     config.page_url = '/lab'
-    config.version = __version__
     config.dev_mode = False
 
     # Check for core mode.

+ 33 - 6
jupyterlab/labapp.py

@@ -5,7 +5,7 @@
 # Distributed under the terms of the Modified BSD License.
 
 from notebook.notebookapp import NotebookApp, aliases, flags
-from jupyter_core.application import JupyterApp
+from jupyter_core.application import JupyterApp, base_aliases
 
 from traitlets import Bool, Unicode
 
@@ -14,22 +14,53 @@ from .extension import load_jupyter_server_extension
 from .commands import build, clean
 
 
+build_aliases = dict(base_aliases)
+build_aliases['app-dir'] = 'LabBuildApp.app_dir'
+build_aliases['name'] = 'LabBuildApp.name'
+build_aliases['version'] = 'LabBuildApp.version'
+build_aliases['publicPath'] = 'LabBuildApp.publicPath'
+
+
 class LabBuildApp(JupyterApp):
     version = __version__
     description = "Build the JupyterLab application"
+    aliases = build_aliases
+
+    app_dir = Unicode('', config=True,
+        help="The app directory to build in")
+
+    name = Unicode('JupyterLab', config=True,
+        help="The name of the built application")
+
+    version = Unicode('', config=True,
+        help="The version of the built application")
+
+    publicPath = Unicode('', config=True,
+        help="The public path for assets in the built application")
 
     def start(self):
-        build(self.app_dir)
+        build(self.app_dir, self.name, self.version, self.publicPath)
+
+
+clean_aliases = dict(base_aliases)
+clean_aliases['app-dir'] = 'LabCleanApp.app_dir'
 
 
 class LabCleanApp(JupyterApp):
     version = __version__
     description = "Clean the JupyterLab application"
+    aliases = clean_aliases
+
+    app_dir = Unicode('', config=True,
+        help="The app directory to clean")
 
     def start(self):
         clean(self.app_dir)
 
 
+lab_aliases = dict(aliases)
+lab_aliases['app-dir'] = 'LabApp.app_dir'
+
 lab_flags = dict(flags)
 lab_flags['core-mode'] = (
     {'LabApp': {'core_mode': True}},
@@ -37,10 +68,6 @@ lab_flags['core-mode'] = (
 )
 
 
-lab_aliases = dict(aliases)
-lab_aliases['app-dir'] = 'LabApp.app_dir'
-
-
 class LabApp(NotebookApp):
     version = __version__
 

+ 2 - 1
jupyterlab/webpack.config.js

@@ -11,6 +11,7 @@ var buildDir = './build';
 fs.removeSync(buildDir);
 fs.ensureDirSync(buildDir);
 
+fs.copySync('./package.json', './build/package.json');
 
 // Create the entry point file.
 var source = fs.readFileSync('index.template.js').toString();
@@ -44,7 +45,7 @@ module.exports = {
   output: {
     path: path.resolve(buildDir),
     filename: '[name].bundle.js',
-    publicPath: digest + '/'
+    publicPath: package_data['jupyterlab']['publicPath']
   },
   module: {
     rules: [