浏览代码

Remove fallback mode by creating an app directory on install

Steven Silvester 7 年之前
父节点
当前提交
da354c5043
共有 3 个文件被更改,包括 67 次插入10 次删除
  1. 6 9
      jupyterlab/extension.py
  2. 3 0
      setup.py
  3. 58 1
      setupbase.py

+ 6 - 9
jupyterlab/extension.py

@@ -68,16 +68,11 @@ def load_jupyter_server_extension(nbapp):
         core_mode = True
         config.settings_dir = ''
 
-    # Run core mode if explicit or there is no static dir and no
-    # installed extensions.
-    installed = list_extensions(app_dir)
-    fallback = not installed and not os.path.exists(config.assets_dir)
-
     web_app.settings.setdefault('page_config_data', dict())
     web_app.settings['page_config_data']['buildAvailable'] = True
     web_app.settings['page_config_data']['token'] = nbapp.token
 
-    if core_mode or fallback:
+    if core_mode:
         config.assets_dir = os.path.join(here, 'build')
         config.version = __version__
         if not os.path.exists(config.assets_dir):
@@ -86,13 +81,16 @@ def load_jupyter_server_extension(nbapp):
         else:
             sentinel = os.path.join(here, 'build', 'release_data.json')
             config.dev_mode = not os.path.exists(sentinel)
+    elif not os.path.exists(config.assets_dir):
+        msg = 'JupyterLab assets dir does not exist: %s' % config.assets_dir
+        raise ValueError(msg + '\nYou may need to run `jupyter lab build`')
 
     if config.dev_mode:
         nbapp.log.info(DEV_NOTE_NPM)
-    elif core_mode or fallback:
+    elif core_mode:
         nbapp.log.info(CORE_NOTE.strip())
 
-    if core_mode or fallback:
+    if core_mode:
         schemas_dir = os.path.join(here, 'schemas')
         config.themes_dir = os.path.join(here, 'themes')
     else:
@@ -101,7 +99,6 @@ def load_jupyter_server_extension(nbapp):
 
     config.schemas_dir = schemas_dir
     config.user_settings_dir = get_user_settings_dir()
-    
 
     add_handlers(web_app, config)
 

+ 3 - 0
setup.py

@@ -45,6 +45,7 @@ from setupbase import (
     bdist_egg_disabled,
     find_packages,
     find_package_data,
+    find_data_files,
     js_prerelease,
     CheckAssets,
     version_ns,
@@ -67,6 +68,8 @@ setup_args = dict(
     scripts          = glob(pjoin('scripts', '*')),
     packages         = find_packages(),
     package_data     = find_package_data(),
+    data_files       = find_data_files(),
+    include_package_data = True,
     author           = 'Jupyter Development Team',
     author_email     = 'jupyter@googlegroups.com',
     url              = 'http://jupyter.org',

+ 58 - 1
setupbase.py

@@ -90,10 +90,67 @@ def find_package_data():
     return {
         'jupyterlab': ['build/*', 'index.app.js',
                        'webpack.config.js', 'package.app.json',
-                       'released_packages.txt', 'node-version-check.js'] + theme_dirs + schema_dirs
+                       'released_packages.txt', 'node-version-check.js'
+                       ] + theme_dirs + schema_dirs
     }
 
 
+def find_data_files():
+    """
+    Find data_files.
+    """
+    files = []
+    static_files = os.listdir(pjoin('jupyterlab', 'build'))
+    files.append(('share/jupyter/lab/static',
+        ['jupyterlab/build/%s' % f for f in static_files]))
+
+    for dir, subdirs, fnames in os.walk(pjoin('jupyterlab', 'schemas')):
+        dir = dir.replace(os.sep, '/')
+        schema_files = []
+        for fname in fnames:
+            schema_files.append('%s/%s' % (dir, fname))
+        slice_len = len('jupyterlab/')
+        files.append(('share/jupyter/lab/%s' % dir[slice_len:], schema_files))
+
+    for dir, subdirs, fnames in os.walk(pjoin('jupyterlab', 'themes')):
+        dir = dir.replace(os.sep, '/')
+        themes_files = []
+        for fname in fnames:
+            themes_files.append('%s/%s' % (dir, fname))
+        slice_len = len('jupyterlab/')
+        files.append(('share/jupyter/lab/%s' % dir[slice_len:], themes_files))
+
+    return files
+
+
+def ensure_core_data(command):
+    """decorator for building minified js/css prior to another command"""
+    class DecoratedCommand(command):
+
+        def run(self):
+            coredeps = self.distribution.get_command_obj('coredeps')
+            if not is_repo and all(osp.exists(t) for t in coredeps.targets):
+                # build_py or build_ext, nothing to do
+                command.run(self)
+                return
+
+            try:
+                self.distribution.run_command('coredeps')
+            except Exception as e:
+                missing = [t for t in coredeps.targets if not osp.exists(t)]
+                if missing:
+                    log.warn('file check failed')
+                    if missing:
+                        log.error('missing files: %s' % missing)
+                    raise e
+                else:
+                    log.warn('core deps check failed (not a problem)')
+                    log.warn(str(e))
+            command.run(self)
+    return DecoratedCommand
+
+
+>>>>>>> fcfcecec0... Remove fallback mode by creating an app directory on install
 def js_prerelease(command, strict=False):
     """decorator for building minified js/css prior to another command"""
     class DecoratedCommand(command):