def load_jupyter_server_extension(nbapp): """Load the JupyterLab server extension. """ # Print messages. here = os.path.dirname(__file__) nbapp.log.info('JupyterLab alpha preview extension loaded from %s' % here) app_dir = get_app_dir() if hasattr(nbapp, 'app_dir'): app_dir = get_app_dir(nbapp.app_dir) web_app = nbapp.web_app config = LabConfig() config.assets_dir = os.path.join(app_dir, 'static') config.settings_dir = os.path.join(app_dir, 'settings') config.page_title = 'JupyterLab Alpha Preview' config.page_url = '/lab' config.dev_mode = False # Check for core mode. core_mode = '' if hasattr(nbapp, 'core_mode'): core_mode = nbapp.core_mode # Check for an app dir that is local. if app_dir == here or app_dir == os.path.join(here, 'build'): 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']['token'] = nbapp.token if not core_mode: build_needed, msg = should_build(app_dir) if build_needed: nbapp.log.warn('Build required: %s' % msg) web_app.settings['page_config_data']['buildRequired'] = msg if core_mode or fallback: config.assets_dir = os.path.join(here, 'build') if not os.path.exists(config.assets_dir): msg = 'Static assets not built, please see CONTRIBUTING.md' nbapp.log.error(msg) else: sentinel = os.path.join(here, 'build', 'release_data.json') config.dev_mode = not os.path.exists(sentinel) if config.dev_mode: nbapp.log.info(DEV_NOTE_NPM) elif core_mode or fallback: nbapp.log.info(CORE_NOTE.strip()) add_handlers(web_app, config)
def load_jupyter_server_extension(nbapp): """Load the JupyterLab server extension. """ # Print messages. here = os.path.dirname(__file__) nbapp.log.info('JupyterLab alpha preview extension loaded from %s' % here) app_dir = get_app_dir() if hasattr(nbapp, 'app_dir'): app_dir = get_app_dir(nbapp.app_dir) web_app = nbapp.web_app config = LabConfig() config.assets_dir = os.path.join(app_dir, 'static') config.settings_dir = os.path.join(app_dir, 'settings') config.page_title = 'JupyterLab Alpha Preview' config.page_url = '/lab' config.dev_mode = False # Check for core mode. core_mode = '' if hasattr(nbapp, 'core_mode'): core_mode = nbapp.core_mode # Check for an app dir that is local. if app_dir == here or app_dir == os.path.join(here, 'build'): 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) if core_mode or fallback: config.assets_dir = os.path.join(here, 'build') if not os.path.exists(config.assets_dir): msg = 'Static assets not built, please see CONTRIBUTING.md' nbapp.log.error(msg) else: sentinel = os.path.join(here, 'build', 'release_data.json') config.dev_mode = not os.path.exists(sentinel) if config.dev_mode: nbapp.log.info(DEV_NOTE_NPM) elif core_mode or fallback: nbapp.log.info(CORE_NOTE.strip()) add_handlers(web_app, config)
def start(self): self.io_loop = ioloop.IOLoop.current() config = LabConfig() if self.core_mode: config.assets_dir = os.path.join(here, 'build') elif self.app_dir: config.assets_dir = os.path.join(self.app_dir, 'static') else: config.assets_dir = os.path.join(get_app_dir(), 'static') print('****Testing assets dir %s' % config.assets_dir) config.settings_dir = '' add_handlers(self.web_app, config) self.io_loop.call_later(1, self._run_selenium) super(TestApp, self).start()
def start(self): self.io_loop = ioloop.IOLoop.current() config = LabConfig() if self.core_mode: config.assets_dir = os.path.join(here, 'build') elif self.app_dir: config.assets_dir = os.path.join(self.app_dir, 'static') else: config.assets_dir = os.path.join(get_app_dir(), 'static') print('****Testing assets dir %s' % config.assets_dir) config.settings_dir = '' add_handlers(self.web_app, config) self.io_loop.call_later(1, self._run_selenium) super(TestApp, self).start()
def load_jupyter_server_extension(nbapp): """Load the JupyterLab server extension. """ # Print messages. here = os.path.dirname(__file__) nbapp.log.info('JupyterLab alpha preview extension loaded from %s' % here) app_dir = get_app_dir() if hasattr(nbapp, 'app_dir'): app_dir = get_app_dir(nbapp.app_dir) web_app = nbapp.web_app config = LabConfig() config.name = 'JupyterLab' config.assets_dir = os.path.join(app_dir, 'static') config.settings_dir = os.path.join(app_dir, 'settings') config.page_title = 'JupyterLab Alpha Preview' config.page_url = '/lab' config.dev_mode = False # Check for core mode. core_mode = '' if hasattr(nbapp, 'core_mode'): core_mode = nbapp.core_mode # Check for watch. watch_mode = False if hasattr(nbapp, 'watch'): watch_mode = nbapp.watch # Check for an app dir that is local. if app_dir == here or app_dir == os.path.join(here, 'build'): core_mode = True config.settings_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: config.assets_dir = os.path.join(here, 'build') config.version = __version__ if not os.path.exists(config.assets_dir): msg = 'Static assets not built, please see CONTRIBUTING.md' nbapp.log.error(msg) else: sentinel = os.path.join(here, 'build', 'release_data.json') config.dev_mode = not os.path.exists(sentinel) if config.dev_mode: nbapp.log.info(DEV_NOTE_NPM) elif core_mode: nbapp.log.info(CORE_NOTE.strip()) if core_mode: schemas_dir = os.path.join(here, 'schemas') config.themes_dir = os.path.join(here, 'themes') else: schemas_dir = os.path.join(app_dir, 'schemas') config.themes_dir = os.path.join(app_dir, 'themes') config.schemas_dir = schemas_dir config.user_settings_dir = get_user_settings_dir() if watch_mode: if core_mode: watch(here, nbapp.log) else: config.assets_dir = os.path.join(app_dir, 'staging', 'build') build(app_dir=app_dir, logger=nbapp.log) watch(os.path.join(app_dir, 'staging'), nbapp.log) add_handlers(web_app, config) base_url = web_app.settings['base_url'] build_url = ujoin(base_url, build_path) builder = Builder(nbapp.log, core_mode, app_dir) build_handler = (build_url, BuildHandler, {'builder': builder}) web_app.add_handlers(".*$", [build_handler])
def load_jupyter_server_extension(nbapp): """Load the JupyterLab server extension. """ # Print messages. here = os.path.dirname(__file__) nbapp.log.info('JupyterLab alpha preview extension loaded from %s' % here) app_dir = get_app_dir() if hasattr(nbapp, 'app_dir'): app_dir = get_app_dir(nbapp.app_dir) web_app = nbapp.web_app config = LabConfig() config.assets_dir = os.path.join(app_dir, 'static') config.settings_dir = os.path.join(app_dir, 'settings') config.page_title = 'JupyterLab Alpha Preview' config.page_url = '/lab' config.dev_mode = False # Check for core mode. core_mode = '' if hasattr(nbapp, 'core_mode'): core_mode = nbapp.core_mode # Check for an app dir that is local. if app_dir == here or app_dir == os.path.join(here, 'build'): 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: config.assets_dir = os.path.join(here, 'build') config.version = __version__ if not os.path.exists(config.assets_dir): msg = 'Static assets not built, please see CONTRIBUTING.md' nbapp.log.error(msg) else: sentinel = os.path.join(here, 'build', 'release_data.json') config.dev_mode = not os.path.exists(sentinel) if config.dev_mode: nbapp.log.info(DEV_NOTE_NPM) elif core_mode or fallback: nbapp.log.info(CORE_NOTE.strip()) if core_mode or fallback: schemas_dir = os.path.join(here, 'schemas') else: schemas_dir = os.path.join(app_dir, 'schemas') config.schemas_dir = schemas_dir config.user_settings_dir = get_user_settings_dir() config.themes_dir = os.path.join(here, 'themes') add_handlers(web_app, config) base_url = web_app.settings['base_url'] build_url = ujoin(base_url, build_path) builder = Builder(nbapp.log, core_mode, app_dir) build_handler = (build_url, BuildHandler, {'builder': builder}) web_app.add_handlers(".*$", [build_handler])
def load_jupyter_server_extension(nbapp): """Load the JupyterLab server extension. """ # Delay imports to speed up jlpmapp import os from jupyterlab_launcher import add_handlers, LabConfig from notebook.utils import url_path_join as ujoin from tornado.ioloop import IOLoop from .build_handler import build_path, Builder, BuildHandler from .commands import (get_app_dir, get_user_settings_dir, watch, watch_dev) from ._version import __version__ # Print messages. here = os.path.dirname(__file__) nbapp.log.info('JupyterLab alpha preview extension loaded from %s' % here) if hasattr(nbapp, 'app_dir'): app_dir = nbapp.app_dir or get_app_dir() else: app_dir = get_app_dir() web_app = nbapp.web_app config = LabConfig() config.name = 'JupyterLab' config.assets_dir = os.path.join(app_dir, 'static') config.settings_dir = os.path.join(app_dir, 'settings') config.page_title = 'JupyterLab Alpha Preview' config.page_url = '/lab' config.dev_mode = False # Check for core mode. core_mode = '' if hasattr(nbapp, 'core_mode'): core_mode = nbapp.core_mode # Check for watch. watch_mode = False if hasattr(nbapp, 'watch'): watch_mode = nbapp.watch # Check for an app dir that is local. if app_dir == here or app_dir == os.path.join(here, 'build'): core_mode = True config.settings_dir = '' page_config = web_app.settings.setdefault('page_config_data', dict()) page_config['buildAvailable'] = not core_mode page_config['buildCheck'] = not core_mode page_config['token'] = nbapp.token if core_mode: config.assets_dir = os.path.join(here, 'build') config.version = __version__ if not os.path.exists(config.assets_dir) and not watch_mode: msg = 'Static assets not built, please see CONTRIBUTING.md' nbapp.log.error(msg) else: sentinel = os.path.join(here, 'build', 'release_data.json') config.dev_mode = not os.path.exists(sentinel) if config.dev_mode and not watch_mode: nbapp.log.info(DEV_NOTE_NPM) elif core_mode: nbapp.log.info(CORE_NOTE.strip()) if core_mode: schemas_dir = os.path.join(here, 'schemas') config.themes_dir = os.path.join(here, 'themes') else: schemas_dir = os.path.join(app_dir, 'schemas') config.themes_dir = os.path.join(app_dir, 'themes') config.schemas_dir = schemas_dir config.user_settings_dir = get_user_settings_dir() if watch_mode: # Set the ioloop in case the watch fails. nbapp.ioloop = IOLoop.current() if config.dev_mode: watch_dev(nbapp.log) else: watch(app_dir, nbapp.log) page_config['buildAvailable'] = False add_handlers(web_app, config) base_url = web_app.settings['base_url'] build_url = ujoin(base_url, build_path) builder = Builder(nbapp.log, core_mode, app_dir) build_handler = (build_url, BuildHandler, {'builder': builder}) web_app.add_handlers(".*$", [build_handler])
def load_jupyter_server_extension(nbapp): """Load the JupyterLab server extension. """ # Print messages. here = os.path.dirname(__file__) nbapp.log.info('JupyterLab alpha preview extension loaded from %s' % here) app_dir = get_app_dir() if hasattr(nbapp, 'app_dir'): app_dir = get_app_dir(nbapp.app_dir) web_app = nbapp.web_app config = LabConfig() config.assets_dir = os.path.join(app_dir, 'static') config.settings_dir = os.path.join(app_dir, 'settings') config.page_title = 'JupyterLab Alpha Preview' config.page_url = '/lab' config.dev_mode = False # Check for core mode. core_mode = '' if hasattr(nbapp, 'core_mode'): core_mode = nbapp.core_mode # Check for an app dir that is local. if app_dir == here or app_dir == os.path.join(here, 'build'): 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) base_url = web_app.settings['base_url'] theme_url = ujoin(base_url, 'lab/api/themes') web_app.settings.setdefault('page_config_data', dict()) web_app.settings['page_config_data']['token'] = nbapp.token web_app.settings['page_config_data']['themePath'] = theme_url if core_mode or fallback: config.assets_dir = os.path.join(here, 'build') config.version = __version__ if not os.path.exists(config.assets_dir): msg = 'Static assets not built, please see CONTRIBUTING.md' nbapp.log.error(msg) else: sentinel = os.path.join(here, 'build', 'release_data.json') config.dev_mode = not os.path.exists(sentinel) if config.dev_mode: nbapp.log.info(DEV_NOTE_NPM) elif core_mode or fallback: nbapp.log.info(CORE_NOTE.strip()) add_handlers(web_app, config) user_settings_dir = get_user_settings_dir() if core_mode or fallback: schemas_dir = os.path.join(here, 'schemas') else: schemas_dir = os.path.join(app_dir, 'schemas') settings_url = ujoin(base_url, settings_path) settings_handler = (settings_url, SettingsHandler, { 'schemas_dir': schemas_dir, 'settings_dir': user_settings_dir }) theme_handler = (ujoin(theme_url, "(.*)"), FileFindHandler, { 'path': os.path.join(here, 'themes') }) build_url = ujoin(base_url, build_path) builder = Builder(nbapp.log, core_mode, app_dir) build_handler = (build_url, BuildHandler, {'builder': builder}) web_app.add_handlers(".*$", [settings_handler, build_handler, theme_handler])
def load_jupyter_server_extension(nbapp): """Load the JupyterLab server extension. """ # Delay imports to speed up jlpmapp from jupyterlab_launcher import add_handlers, LabConfig from notebook.utils import url_path_join as ujoin from tornado.ioloop import IOLoop 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_version ) from ._version import __version__ web_app = nbapp.web_app logger = nbapp.log config = LabConfig() app_dir = getattr(nbapp, 'app_dir', get_app_dir()) # Print messages. logger.info('JupyterLab alpha preview extension loaded from %s' % HERE) logger.info('JupyterLab application directory is %s' % app_dir) config.name = 'JupyterLab' config.page_title = 'JupyterLab Alpha Preview' config.page_url = '/lab' # Check for core mode. core_mode = False if getattr(nbapp, 'core_mode', False) or app_dir.startswith(HERE): core_mode = True logger.info('Running JupyterLab in core mode') # Check for dev mode. dev_mode = False if getattr(nbapp, 'dev_mode', False) or app_dir.startswith(DEV_DIR): dev_mode = True logger.info('Running JupyterLab in dev mode') # Check for watch. watch_mode = getattr(nbapp, 'watch', False) if watch_mode and core_mode: logger.warn('Cannot watch in core mode, did you mean --dev-mode?') watch_mode = False if core_mode and dev_mode: logger.warn('Conflicting modes, choosing dev_mode over core_mode') core_mode = False page_config = web_app.settings.setdefault('page_config_data', dict()) page_config['buildAvailable'] = not core_mode and not dev_mode page_config['buildCheck'] = not core_mode and not dev_mode page_config['token'] = nbapp.token if core_mode: config.assets_dir = pjoin(HERE, 'static') config.schemas_dir = pjoin(HERE, 'schemas') config.settings_dir = '' config.themes_dir = pjoin(HERE, 'themes') config.version = get_app_version() logger.info(CORE_NOTE.strip()) if not os.path.exists(config.assets_dir): msg = 'Static assets not built, please see CONTRIBUTING.md' logger.error(msg) elif dev_mode: config.assets_dir = pjoin(DEV_DIR, 'build') config.schemas_dir = pjoin(DEV_DIR, 'schemas') config.settings_dir = '' config.themes_dir = pjoin(DEV_DIR, 'themes') config.version = __version__ ensure_dev(logger) if not watch_mode: logger.info(DEV_NOTE) else: config.assets_dir = pjoin(app_dir, 'static') config.schemas_dir = pjoin(app_dir, 'schemas') config.settings_dir = pjoin(app_dir, 'settings') config.themes_dir = pjoin(app_dir, 'themes') config.version = get_app_version() config.dev_mode = dev_mode config.user_settings_dir = get_user_settings_dir() if watch_mode: logger.info('Starting JupyterLab watch mode...') # Set the ioloop in case the watch fails. nbapp.ioloop = IOLoop.current() if config.dev_mode: watch_dev(logger) else: watch(app_dir, logger) page_config['buildAvailable'] = False add_handlers(web_app, config) base_url = web_app.settings['base_url'] build_url = ujoin(base_url, build_path) builder = Builder(logger, core_mode, app_dir) build_handler = (build_url, BuildHandler, {'builder': builder}) web_app.add_handlers(".*$", [build_handler])