浏览代码

Merge pull request #1167 from blink1073/extension-check

Server Extension Cleanup
Afshin Darian 8 年之前
父节点
当前提交
02b0439ed2
共有 6 个文件被更改,包括 85 次插入7 次删除
  1. 12 0
      jupyterlab/__init__.py
  2. 56 0
      jupyterlab/error.html
  3. 1 0
      jupyterlab/index.js
  4. 1 2
      jupyterlab/lab.html
  5. 12 2
      jupyterlab/webpack.config.js
  6. 3 3
      package.json

+ 12 - 0
jupyterlab/__init__.py

@@ -6,6 +6,7 @@
 import glob
 import json
 import os
+import sys
 from tornado import web
 from notebook.base.handlers import IPythonHandler, FileFindHandler
 from jinja2 import FileSystemLoader
@@ -64,6 +65,17 @@ class LabHandler(IPythonHandler):
         static_prefix = ujoin(self.base_url, PREFIX)
         labextensions = self.application.labextensions
         data = get_labextension_manifest_data_by_folder(BUILT_FILES)
+        if 'main' not in data or 'extensions' not in data:
+            msg = ('JupyterLab build artifacts not detected, please see ' + 
+                   'CONTRIBUTING.md for build instructions.')
+            self.log.error(msg)
+            self.write(self.render_template('error.html', 
+                       status_code=500, 
+                       status_message='JupyterLab Error',
+                       page_title='JupyterLab Error',
+                       message=msg))
+            return
+
         main = data['main']['entry']
         bundles = [ujoin(static_prefix, name + '.bundle.js') for name in
                    ['loader', 'main', 'extensions']]

+ 56 - 0
jupyterlab/error.html

@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<!--
+Copyright (c) Jupyter Development Team.
+Distributed under the terms of the Modified BSD License.
+-->
+<html>
+
+<head>
+  <meta charset="utf-8">
+
+  <title>{% block title %}{{page_title}}{% endblock %}</title>
+
+  {% block favicon %}<link rel="shortcut icon" type="image/x-icon" href="/static/base/images/favicon.ico">{% endblock %}
+
+</head>
+
+<body>
+
+{% block stylesheet %}
+<style type="text/css">
+/* disable initial hide */
+div#header, div#site {
+    display: block;
+}
+</style>
+{% endblock %}
+{% block site %}
+
+<div class="error">
+    {% block h1_error %}
+    <h1>{{status_code}} : {{status_message}}</h1>
+    {% endblock h1_error %}
+    {% block error_detail %}
+    {% if message %}
+    <p>The error was:</p>
+    <div class="traceback-wrapper">
+    <pre class="traceback">{{message}}</pre>
+    </div>
+    {% endif %}
+    {% endblock %}
+</header>
+
+{% endblock %}
+
+{% block script %}
+<script type='text/javascript'>
+window.onload = function () {
+  var tb = document.getElementsByClassName('traceback')[0];
+  tb.scrollTop = tb.scrollHeight;
+};
+</script>
+{% endblock script %}
+
+</body>
+
+</html>

+ 1 - 0
jupyterlab/index.js

@@ -30,5 +30,6 @@ function getEntryPoint(entryPoint) {
 jupyter.lab = new JupyterLab();
 jupyter.getEntryPoint = getEntryPoint;
 jupyter.version = require('../package.json').version;
+jupyter.gitDescription = process.env.GIT_DESCRIPTION;
 
 module.exports = jupyter.lab;

+ 1 - 2
jupyterlab/lab.html

@@ -1,9 +1,8 @@
+<!DOCTYPE html>
 <!--
 Copyright (c) Jupyter Development Team.
 Distributed under the terms of the Modified BSD License.
 -->
-
-<!DOCTYPE HTML>
 <html>
 
 <head>

+ 12 - 2
jupyterlab/webpack.config.js

@@ -5,11 +5,14 @@
 // See https://github.com/webpack/css-loader/issues/144
 require('es6-promise').polyfill();
 
+var childProcess = require('child_process');
 var buildExtension = require('@jupyterlab/extension-builder/lib/builder').buildExtension;
+var webpack = require('webpack');
 
 
 console.log('Generating bundles...');
 
+var notice = childProcess.execSync('git describe', { encoding: 'utf8' });
 
 buildExtension({
   name: 'main',
@@ -17,8 +20,15 @@ buildExtension({
   outputDir: './build',
   config: {
     output: {
-      publicPath: 'lab/'
-    }
+      publicPath: 'lab/',
+    },
+    plugins: [
+      new webpack.DefinePlugin({
+        'process.env': {
+          'GIT_DESCRIPTION': JSON.stringify(notice.trim())
+        }
+      })
+    ]
   }
 });
 

+ 3 - 3
package.json

@@ -67,9 +67,9 @@
     "build": "npm run build:src",
     "build:all": "npm run build:src && npm run build:serverextension",
     "build:examples": "node scripts/buildexamples.js",
-    "build:src": "tsc --project src && node scripts/copyfiles.js",
-    "build:test": "webpack --config test/webpack.conf.js",
-    "build:serverextension": "cd jupyterlab && webpack",
+    "build:src": "rimraf build && tsc --project src && node scripts/copyfiles.js",
+    "build:test": "rimraf test/build && webpack --config test/webpack.conf.js",
+    "build:serverextension": "cd jupyterlab && rimraf build && webpack",
     "clean": "rimraf docs && rimraf lib && rimraf test/build && rimraf test/coverage && rimraf jupyterlab/build",
     "clean:examples": "node scripts/cleanexamples.js",
     "clean:slate": "npm run clean && npm run clean:examples && rimraf jupyterlab/node_modules && rimraf node_modules && npm install",