فهرست منبع

Merge pull request #3586 from blink1073/workspaces-folder

Switch default workspaces location and make it configurable
Afshin Darian 7 سال پیش
والد
کامیت
2fd2b577df
3فایلهای تغییر یافته به همراه33 افزوده شده و 5 حذف شده
  1. 11 1
      jupyterlab/commands.py
  2. 11 3
      jupyterlab/extension.py
  3. 11 1
      jupyterlab/labapp.py

+ 11 - 1
jupyterlab/commands.py

@@ -43,7 +43,7 @@ def pjoin(*args):
 
 
 def get_user_settings_dir():
-    """Get the configured JupyterLab app directory.
+    """Get the configured JupyterLab user settings directory.
     """
     settings_dir = os.environ.get('JUPYTERLAB_SETTINGS_DIR')
     settings_dir = settings_dir or pjoin(
@@ -52,6 +52,16 @@ def get_user_settings_dir():
     return osp.realpath(settings_dir)
 
 
+def get_workspaces_dir():
+    """Get the configured JupyterLab workspaces directory.
+    """
+    workspaces_dir = os.environ.get('JUPYTERLAB_WORKSPACES_DIR')
+    workspaces_dir = workspaces_dir or pjoin(
+        jupyter_config_path()[0], 'lab', 'workspaces'
+    )
+    return osp.realpath(workspaces_dir)
+
+
 def get_app_dir():
     """Get the configured JupyterLab app directory.
     """

+ 11 - 3
jupyterlab/extension.py

@@ -35,13 +35,19 @@ def load_jupyter_server_extension(nbapp):
     from .build_handler import build_path, Builder, BuildHandler
     from .commands import (
         get_app_dir, get_user_settings_dir, watch, ensure_dev, watch_dev,
-        pjoin, DEV_DIR, HERE, get_app_info, ensure_core
+        pjoin, DEV_DIR, HERE, get_app_info, ensure_core, get_workspaces_dir
     )
 
     web_app = nbapp.web_app
     logger = nbapp.log
     config = LabConfig()
     app_dir = getattr(nbapp, 'app_dir', get_app_dir())
+    user_settings_dir = getattr(
+        nbapp, 'user_settings_dir', get_user_settings_dir()
+    )
+    workspaces_dir = getattr(
+        nbapp, 'workspaces_dir', get_workspaces_dir()
+    )
 
     # Print messages.
     logger.info('JupyterLab beta preview extension loaded from %s' % HERE)
@@ -101,7 +107,7 @@ def load_jupyter_server_extension(nbapp):
     config.app_settings_dir = pjoin(app_dir, 'settings')
     config.schemas_dir = pjoin(app_dir, 'schemas')
     config.themes_dir = pjoin(app_dir, 'themes')
-    config.workspaces_dir = pjoin(app_dir, 'workspaces')
+    config.workspaces_dir = workspaces_dir
     info = get_app_info(app_dir)
     config.app_version = info['version']
     public_url = info['publicUrl']
@@ -110,7 +116,9 @@ def load_jupyter_server_extension(nbapp):
     else:
         config.static_dir = pjoin(app_dir, 'static')
 
-    config.user_settings_dir = get_user_settings_dir()
+    config.user_settings_dir = user_settings_dir
+
+    # The templates end up in the built static directory.
     config.templates_dir = pjoin(app_dir, 'static')
 
     if watch_mode:

+ 11 - 1
jupyterlab/labapp.py

@@ -13,7 +13,7 @@ from ._version import __version__
 from .extension import load_jupyter_server_extension
 from .commands import (
     build, clean, get_app_dir, get_user_settings_dir, get_app_version,
-    ensure_dev
+    get_workspaces_dir
 )
 
 
@@ -83,11 +83,15 @@ class LabPathApp(JupyterApp):
     The user settings path can be configured using the JUPYTERLAB_SETTINGS_DIR
         environment variable or it will fall back to
         `/lab/user-settings` in the default Jupyter configuration directory.
+    The workspaces path can be configured using the JUPYTERLAB_WORKSPACES_DIR
+        environment variable or it will fall back to
+        '/lab/workspaces' in the default Jupyter configuration directory.
     """
 
     def start(self):
         print('Application directory:   %s' % get_app_dir())
         print('User Settings directory: %s' % get_user_settings_dir())
+        print('Workspaces directory %s' % get_workspaces_dir())
 
 
 lab_aliases = dict(aliases)
@@ -156,6 +160,12 @@ class LabApp(NotebookApp):
     app_dir = Unicode(get_app_dir(), config=True,
         help="The app directory to launch JupyterLab from.")
 
+    user_settings_dir = Unicode(get_user_settings_dir(), config=True,
+        help="The directory for user settings.")
+
+    workspaces_dir = Unicode(get_workspaces_dir(), config=True,
+        help="The directory for workspaces")
+
     core_mode = Bool(False, config=True,
         help="""Whether to start the app in core mode. In this mode, JupyterLab
         will run using the JavaScript assets that are within the installed