Browse Source

Merge pull request #2077 from blink1073/env-config

Simplify config directory handling for now
Afshin Darian 8 years ago
parent
commit
dd83a2e4be
4 changed files with 33 additions and 46 deletions
  1. 24 24
      jupyterlab/commands.py
  2. 3 8
      jupyterlab/extension.py
  3. 1 5
      jupyterlab/labapp.py
  4. 5 9
      jupyterlab/labextensions.py

+ 24 - 24
jupyterlab/commands.py

@@ -24,8 +24,8 @@ else:
 
 
 here = osp.dirname(osp.abspath(__file__))
-DEFAULT_CONFIG_PATH = ENV_CONFIG_PATH[0]
-DEFAULT_BUILD_PATH = ENV_JUPYTER_PATH[0]
+CONFIG_PATH = os.environ.get('JUPYTERLAB_CONFIG_DIR', ENV_CONFIG_PATH[0])
+BUILD_PATH = ENV_JUPYTER_PATH[0]
 
 
 def run(cmd, **kwargs):
@@ -37,7 +37,7 @@ def run(cmd, **kwargs):
     return check_output(cmd, **kwargs)
 
 
-def install_extension(extension, config_dir=None):
+def install_extension(extension):
     """Install an extension package into JupyterLab.
 
     Follows the semantics of https://docs.npmjs.com/cli/install.
@@ -47,16 +47,16 @@ def install_extension(extension, config_dir=None):
     If link is true, the source directory is linked using `npm link`.
     """
     tar_name, pkg_name = validate_extension(extension)
-    config = _get_config(config_dir)
+    config = _get_config()
     path = pjoin(_get_cache_dir(config), tar_name)
     run(['npm', 'install', '--save', path], cwd=_get_root_dir(config))
     config['installed_extensions'][pkg_name] = path
     if pkg_name in config['linked_extensions']:
         del config['linked_extensions'][pkg_name]
-    _write_config(config, config_dir)
+    _write_config(config)
 
 
-def link_extension(extension, config_dir=None):
+def link_extension(extension):
     """Link an extension against the JupyterLab build.
     """
     path = _normalize_path(extension)
@@ -73,19 +73,19 @@ def link_extension(extension, config_dir=None):
     _validate_package(data, path)
 
     # Update JupyterLab metadata.
-    config = _get_config(config_dir)
+    config = _get_config()
     name = data['name']
     config['linked_extensions'][name] = path
     if name in config['installed_extensions']:
         del config['installed_extensions'][name]
-    _write_config(config, config_dir)
+    _write_config(config)
 
 
-def unlink_extension(extension, config_dir=None):
+def unlink_extension(extension):
     """Unlink an extension from JupyterLab by path or name.
     """
     extension = _normalize_path(extension)
-    config = _get_config(config_dir)
+    config = _get_config()
 
     name = None
     for (key, value) in config['linked_extensions'].items():
@@ -95,40 +95,40 @@ def unlink_extension(extension, config_dir=None):
 
     if name:
         del config['linked_extensions'][name]
-        _write_config(config, config_dir)
+        _write_config(config)
         return True
 
     print('No labextension matching "%s" is linked' % extension)
     return False
 
 
-def uninstall_extension(name, config_dir=None):
+def uninstall_extension(name):
     """Uninstall an extension by name.
     """
-    config = _get_config(config_dir)
+    config = _get_config()
 
     if name in config['installed_extensions']:
         del config['installed_extensions'][name]
-        _write_config(config, config_dir)
+        _write_config(config)
         return True
 
     print('No labextension named "%s" installed' % name)
     return False
 
 
-def list_extensions(config_dir=None):
+def list_extensions():
     """List installed extensions.
     """
-    config = _get_config(config_dir)
+    config = _get_config()
     installed = list(config['installed_extensions'])
     linked = list(config['linked_extensions'])
     return sorted(installed + linked)
 
 
-def validate_extension(extension, config_dir=None):
+def validate_extension(extension):
     """Verify that a JupyterLab extension is valid.
     """
-    config = _get_config(config_dir)
+    config = _get_config()
     extension = _normalize_path(extension)
     _ensure_package(config)
     cache_dir = _get_cache_dir(config)
@@ -143,19 +143,19 @@ def validate_extension(extension, config_dir=None):
     return name, data['name']
 
 
-def clean(config_dir=None):
+def clean():
     """Clean the JupyterLab application directory."""
-    config = _get_config(config_dir)
+    config = _get_config()
     for name in ['node_modules', 'build']:
         target = pjoin(_get_root_dir(config), name)
         if osp.exists(target):
             shutil.rmtree(target)
 
 
-def build(config_dir=None):
+def build():
     """Build the JupyterLab application."""
     # Set up the build directory.
-    config = _get_config(config_dir)
+    config = _get_config()
     _ensure_package(config)
     root = _get_root_dir(config)
 
@@ -229,7 +229,7 @@ def _get_config(config_dir=None):
     else:
         with open(file) as fid:
             data = json.load(fid)
-    data.setdefault('location', pjoin(DEFAULT_BUILD_PATH, 'lab'))
+    data.setdefault('location', pjoin(BUILD_PATH, 'lab'))
     data.setdefault('installed_extensions', dict())
     data.setdefault('linked_extensions', dict())
     return data
@@ -257,7 +257,7 @@ def _normalize_path(extension):
 
 
 def _get_config_dir():
-    return pjoin(DEFAULT_CONFIG_PATH, 'labconfig')
+    return pjoin(CONFIG_PATH, 'labconfig')
 
 
 def _get_root_dir(config=None):

+ 3 - 8
jupyterlab/extension.py

@@ -10,7 +10,7 @@ from tornado import web
 from notebook.base.handlers import IPythonHandler, FileFindHandler
 from jinja2 import FileSystemLoader
 from notebook.utils import url_path_join as ujoin
-from .commands import _get_build_dir, _get_config, DEFAULT_CONFIG_PATH
+from .commands import _get_build_dir, _get_config, _get_config_dir
 
 
 #-----------------------------------------------------------------------------
@@ -88,14 +88,9 @@ def add_handlers(app):
     prefix = ujoin(base_url, PREFIX)
 
     # Handle page config data.
-    config_dir = getattr(app, 'lab_config_dir', DEFAULT_CONFIG_PATH)
-    if 'LabApp' in app.config:
-        if 'lab_config_dir' in app.config['LabApp']:
-            config_dir = app.config['LabApp']['lab_config_dir']
-
-    config = _get_config(config_dir)
+    config = _get_config()
     page_config_data = web_app.settings.get('page_config_data', {})
-    page_config_file = os.path.join(config_dir, 'page_config_data.json')
+    page_config_file = os.path.join(_get_config_dir(), 'page_config_data.json')
     if os.path.exists(page_config_file):
         with open(page_config_file) as fid:
             page_config_data.update(json.load(fid))

+ 1 - 5
jupyterlab/labapp.py

@@ -6,13 +6,12 @@
 
 from notebook.notebookapp import NotebookApp, flags
 from jupyter_core.application import JupyterApp
-from jupyter_core.paths import ENV_CONFIG_PATH
 
 from traitlets import Bool, Unicode
 
 from ._version import __version__
 from .extension import load_jupyter_server_extension
-from .commands import build, clean, describe, DEFAULT_CONFIG_PATH
+from .commands import build, clean, describe
 
 
 class LabBuildApp(JupyterApp):
@@ -75,9 +74,6 @@ class LabApp(NotebookApp):
     dev_mode = Bool(False, config=True,
         help="Whether to start the app in dev mode")
 
-    lab_config_dir = Unicode(DEFAULT_CONFIG_PATH, config=True,
-        help="The lab configuration directory")
-
     def init_server_extensions(self):
         """Load any extensions specified by config.
 

+ 5 - 9
jupyterlab/labextensions.py

@@ -7,8 +7,7 @@ import os
 import sys
 
 from jupyter_core.application import JupyterApp, base_flags
-from jupyter_core.paths import ENV_CONFIG_PATH
-from traitlets import Bool, Unicode
+from traitlets import Bool
 
 from ._version import __version__
 from .commands import (
@@ -28,9 +27,6 @@ class BaseExtensionApp(JupyterApp):
     version = __version__
     flags = flags
 
-    lab_config_dir = Unicode(ENV_CONFIG_PATH[0], config=True,
-        help="The lab configuration directory")
-
     should_build = Bool(True, config=True,
         help="Whether to build the app after the action")
 
@@ -40,7 +36,7 @@ class InstallLabExtensionApp(BaseExtensionApp):
 
     def start(self):
         self.extra_args = self.extra_args or [os.getcwd()]
-        [install_extension(arg, self.config_dir) for arg in self.extra_args]
+        [install_extension(arg) for arg in self.extra_args]
         if self.should_build:
             build()
 
@@ -50,7 +46,7 @@ class LinkLabExtensionApp(BaseExtensionApp):
 
     def start(self):
         self.extra_args = self.extra_args or [os.getcwd()]
-        [link_extension(arg, self.config_dir) for arg in self.extra_args]
+        [link_extension(arg) for arg in self.extra_args]
         if self.should_build:
             build()
 
@@ -60,7 +56,7 @@ class UnlinkLabExtensionApp(BaseExtensionApp):
 
     def start(self):
         self.extra_args = self.extra_args or [os.getcwd()]
-        ans = any([unlink_extension(arg, self.config_dir)
+        ans = any([unlink_extension(arg)
                    for arg in self.extra_args])
         if ans and self.should_build:
             build()
@@ -71,7 +67,7 @@ class UninstallLabExtensionApp(BaseExtensionApp):
 
     def start(self):
         self.extra_args = self.extra_args or [os.getcwd()]
-        ans = any([uninstall_extension(arg, self.config_dir)
+        ans = any([uninstall_extension(arg)
                    for arg in self.extra_args])
         if ans and self.should_build:
             build()