Browse Source

Always build when install/uninstall for now, refactor describe function

Steven Silvester 8 years ago
parent
commit
8dbc7f5075
4 changed files with 27 additions and 18 deletions
  1. 17 1
      jupyterlab/commands.py
  2. 1 1
      jupyterlab/extension.py
  3. 2 15
      jupyterlab/labapp.py
  4. 7 1
      jupyterlab/webpack.config.js

+ 17 - 1
jupyterlab/commands.py

@@ -36,6 +36,7 @@ def install_extension(extension):
     data['jupyterlab']['extensions'].sort()
     with open(_get_pkg_path(), 'w') as fid:
         json.dump(data, fid)
+    build()
 
 
 def uninstall_extension(extension):
@@ -46,6 +47,7 @@ def uninstall_extension(extension):
     del data['dependencies'][extension]
     with open(_get_pkg_path(), 'w') as fid:
         json.dump(data, fid)
+    build()
 
 
 def list_extensions():
@@ -88,6 +90,20 @@ def build():
                cwd=_get_root_dir(), shell=_shell, env=_env)
 
 
+def describe():
+    """Get the git description of the JupyterLab application.
+    """
+    description = 'unknown'
+    try:
+        cwd = os.path.dirname(os.path.dirname(__file__))
+        description = check_output(['git', 'describe'],
+                                   cwd=cwd, shell=_shell, env=_env)
+        description = description.decode('utf8').strip()
+    except Exception:
+        pass
+    return description
+
+
 def _ensure_package():
     """Make sure there is a package.json file."""
     cache_dir = _get_cache_dir()
@@ -96,7 +112,7 @@ def _ensure_package():
         os.makedirs(cache_dir)
     for name in ['package.json', 'index.template.js', 'webpack.config.js']:
         dest = pjoin(root_dir, name)
-        if not osp.exists(dest):
+        if not osp.exists(dest) or name != 'package.json':
             shutil.copy2(pjoin(here, name), dest)
     if not osp.exists(pjoin(root_dir, 'node_modules')):
         check_call(['npm', 'install'],

+ 1 - 1
jupyterlab/extension.py

@@ -12,7 +12,6 @@ from notebook.utils import url_path_join as ujoin
 from jupyter_core.paths import ENV_JUPYTER_PATH
 
 
-
 #-----------------------------------------------------------------------------
 # Module globals
 #-----------------------------------------------------------------------------
@@ -47,6 +46,7 @@ class LabHandler(IPythonHandler):
     def _get_lab_config(self):
         """Get the config data for the page template."""
         static_prefix = ujoin(self.base_url, PREFIX)
+
         bundles = [ujoin(static_prefix, name + '.bundle.js') for name in
                    ['main']]
 

+ 2 - 15
jupyterlab/labapp.py

@@ -3,9 +3,6 @@
 
 # Copyright (c) Jupyter Development Team.
 # Distributed under the terms of the Modified BSD License.
-import os
-from subprocess import check_output
-import sys
 
 from notebook.notebookapp import NotebookApp
 from jupyter_core.application import JupyterApp
@@ -14,7 +11,7 @@ from traitlets import Unicode
 
 from ._version import __version__
 from .extension import load_jupyter_server_extension
-from .commands import build
+from .commands import build, describe
 
 
 class LabBuildApp(JupyterApp):
@@ -30,17 +27,7 @@ class LabDescribeApp(JupyterApp):
     description = "Git description the JupyterLab application"
 
     def start(self):
-        description = 'unknown'
-        try:
-            cwd = os.path.dirname(os.path.dirname(__file__))
-            shell = sys.platform == 'win32'
-            description = check_output(['git', 'describe'],
-                                       cwd=cwd, shell=shell)
-            description = description.decode('utf8').strip()
-        except Exception:
-            pass
-        print(description)
-        return
+        print(describe())
 
 
 class LabApp(NotebookApp):

+ 7 - 1
jupyterlab/webpack.config.js

@@ -5,9 +5,9 @@ var path = require('path');
 var fs = require('fs-extra');
 var ExtractTextPlugin = require('extract-text-webpack-plugin');
 var Handlebars = require('handlebars');
+var crypto = require('crypto');
 var package_data = require('./package.json');
 
-
 // Ensure a clear build directory.
 fs.removeSync('./build');
 fs.ensureDirSync('./build');
@@ -21,6 +21,12 @@ var result = template(data);
 fs.writeFileSync('build/index.out.js', result);
 
 
+// Create the hash
+var hash = crypto.createHash('md5');
+hash.update(fs.readFileSync('./package.json'));
+fs.writeFileSync('build/hash.md5', hash.digest('hex'));
+
+
 // Get the git description.
 try {
   var notice = childProcess.execSync('jupyter lab describe', { encoding: 'utf8' });