class ExampleApp(LabServerApp): default_url = Unicode('/example', help='The default URL to redirect to from `/`') lab_config = LabConfig( app_name = 'JupyterLab Example App', app_settings_dir = os.path.join(HERE, 'build', 'application_settings'), page_url = 'example', schemas_dir = os.path.join(HERE, 'build', 'schemas'), settings_dir = os.path.join(HERE, 'build', 'settings'), static_dir = os.path.join(HERE, 'build'), templates_dir = os.path.join(HERE, 'templates'), themes_dir = os.path.join(HERE, 'build', 'themes'), user_settings_dir = os.path.join(HERE, 'build', 'user_settings'), workspaces_dir = os.path.join(HERE, 'build', 'workspaces'), ) def start(self): settings = self.web_app.settings # By default, make terminals available. settings.setdefault('terminals_available', True) super().start()
class TestLabApp(LabApp): base_url = '/lab' extension_url = '/lab' default_url = Unicode( '/', help='The default URL to redirect to from `/`') lab_config = LabConfig( app_name='JupyterLab Test App', static_dir=str(root_dir), templates_dir=str(template_dir), app_url='/lab', app_settings_dir=str(app_settings_dir), user_settings_dir=str(user_settings_dir), schemas_dir=str(schemas_dir), workspaces_dir=str(workspaces_dir), )
class TestLabApp(LabApp): base_url = "/lab" extension_url = "/lab" default_url = Unicode( "/", help="The default URL to redirect to from `/`") lab_config = LabConfig( app_name="JupyterLab Test App", static_dir=str(jp_root_dir), templates_dir=str(jp_template_dir), app_url="/lab", app_settings_dir=str(app_settings_dir), user_settings_dir=str(user_settings_dir), schemas_dir=str(schemas_dir), workspaces_dir=str(workspaces_dir), )
def load_jupyter_server_extension(nb_server_app): """ Called when the extension is loaded. Args: nb_server_app (NotebookWebApplication): handle to the Notebook webserver instance. """ lab_config = LabConfig(config=nb_server_app.config) web_app = nb_server_app.web_app base_url = web_app.settings["base_url"] lab_path = url_path_join(base_url) omnisci_session_endpoint = url_path_join(lab_path, "omnisci/session") print(omnisci_session_endpoint) handlers = [(omnisci_session_endpoint, OmniSciSessionHandler)] web_app.add_handlers(".*$", handlers)
def load_jupyter_server_extension(nb_server_app): """ Called when the extension is loaded. Args: nb_server_app (NotebookWebApplication): handle to the Notebook webserver instance. """ web_app = nb_server_app.web_app immerse_config = ImmerseConfig(config=nb_server_app.config) lab_config = LabConfig(config=nb_server_app.config) # Holy traitlets base_url = web_app.settings["base_url"] workspaces_dir = nb_server_app.workspaces_dir settings_dir = nb_server_app.user_settings_dir workspaces_url = lab_config.workspaces_url lab_url = lab_config.page_url immerse_endpoint = url_path_join(base_url, "immerse") servers_endpoint = url_path_join(base_url, "immerse", "servers.json") lab_redirect_endpoint = url_path_join(base_url, "immerse", "lab") handlers = [ (servers_endpoint, ImmerseServersHandler), ( lab_redirect_endpoint, ImmerseLabRedirectHandler, { "base_url": base_url, "lab_url": lab_url, "settings_dir": settings_dir, "workspaces_dir": workspaces_dir, "workspaces_url": workspaces_url, }, ), ( immerse_endpoint + "(.*)", ImmerseHandler, { "path": immerse_config.immerse_dir, "default_filename": "index.html" }, ), ] web_app.add_handlers(".*$", handlers)
class MambaNavigator(LabServerApp): default_url = Unicode('/navigator', help='The default URL to redirect to from `/`') lab_config = LabConfig( app_name='Mamba Navigator', app_settings_dir=os.path.join(HERE, 'build', 'application_settings'), app_version=version, app_url='/navigator', schemas_dir=os.path.join(HERE, 'build', 'schemas'), static_dir=os.path.join(HERE, 'build'), templates_dir=os.path.join(HERE, 'templates'), themes_dir=os.path.join(HERE, 'build', 'themes'), user_settings_dir=os.path.join(HERE, 'build', 'user_settings'), workspaces_dir=os.path.join(HERE, 'build', 'workspaces'), ) def start(self): load_jupyter_server_extension(self) super().start()
class ExampleApp(LabServerApp): base_url = '/foo' default_url = Unicode('/example', help='The default URL to redirect to from `/`') lab_config = LabConfig( app_name='JupyterLab Example Federated App', app_settings_dir=os.path.join(HERE, 'build', 'application_settings'), app_version=version, app_url='/example', schemas_dir=os.path.join(HERE, 'core_package', 'build', 'schemas'), static_dir=os.path.join(HERE, 'core_package', 'build'), templates_dir=os.path.join(HERE, 'templates'), themes_dir=os.path.join(HERE, 'core_package', 'build', 'themes'), user_settings_dir=os.path.join(HERE, 'core_package', 'build', 'user_settings'), workspaces_dir=os.path.join(HERE, 'core_package', 'build', 'workspaces'), ) def init_webapp(self): super().init_webapp() # Handle md ext assets web_app = self.web_app base_url = web_app.settings['base_url'] static_path = ujoin(base_url, 'example', 'ext', 'mdext', '(.*)') static_dir = os.path.join(HERE, 'md_package', 'build') web_app.add_handlers('.*$', [(static_path, FileFindHandler, { 'path': static_dir, })]) def start(self): settings = self.web_app.settings # By default, make terminals available. settings.setdefault('terminals_available', True) super().start()
def load_config(nbapp): """Load the JupyterLab configuration and defaults for a given application. """ from jupyterlab_server import LabConfig from .commands import ( get_app_dir, get_app_info, get_workspaces_dir, get_user_settings_dir, pjoin ) app_dir = getattr(nbapp, 'app_dir', get_app_dir()) info = get_app_info(app_dir) static_url = info['staticUrl'] user_settings_dir = getattr( nbapp, 'user_settings_dir', get_user_settings_dir() ) workspaces_dir = getattr(nbapp, 'workspaces_dir', get_workspaces_dir()) config = LabConfig() config.app_dir = app_dir config.app_name = 'JupyterLab' config.app_namespace = 'jupyterlab' config.app_settings_dir = pjoin(app_dir, 'settings') config.app_version = info['version'] config.cache_files = True config.schemas_dir = pjoin(app_dir, 'schemas') config.templates_dir = pjoin(app_dir, 'static') config.themes_dir = pjoin(app_dir, 'themes') config.user_settings_dir = user_settings_dir config.workspaces_dir = workspaces_dir if getattr(nbapp, 'override_static_url', ''): static_url = nbapp.override_static_url if getattr(nbapp, 'override_theme_url', ''): config.themes_url = nbapp.override_theme_url config.themes_dir = '' if static_url: config.static_url = static_url else: config.static_dir = pjoin(app_dir, 'static') return config
class ExampleApp(LabServerApp): base_url = '/foo' default_url = Unicode('/example', help='The default URL to redirect to from `/`') extra_labextensions_path = List(Unicode(), config=True, help="""extra paths to look for Javascript notebook extensions""" ) lab_config = LabConfig( app_name = 'JupyterLab Example Federated App', app_settings_dir = os.path.join(HERE, 'build', 'application_settings'), app_version = version, app_url = '/example', schemas_dir = os.path.join(HERE, 'core_package', 'build', 'schemas'), static_dir = os.path.join(HERE, 'core_package', 'build'), templates_dir = os.path.join(HERE, 'templates'), themes_dir = os.path.join(HERE, 'core_package', 'build', 'themes'), user_settings_dir = os.path.join(HERE, 'core_package', 'build', 'user_settings'), workspaces_dir = os.path.join(HERE, 'core_package', 'build', 'workspaces'), ) def init_webapp(self): super().init_webapp() # Handle labextension assets web_app = self.web_app base_url = web_app.settings['base_url'] handlers = [] # Temporary addition for testing self.extra_labextensions_path += [os.path.join(HERE, 'labextensions')] labextensions_path = self.extra_labextensions_path + jupyter_path('labextensions') labextensions_url = ujoin(base_url, "example", r"labextensions/(.*)") handlers.append( (labextensions_url, FileFindHandler, { 'path': labextensions_path, 'no_cache_paths': ['/'], # don't cache anything in labextensions })) # Handle requests for the list of settings. Make slash optional. settings_path = ujoin(base_url, 'example', 'api', 'settings') settings_config = { 'app_settings_dir': self.lab_config.app_settings_dir, 'schemas_dir': self.lab_config.schemas_dir, 'settings_dir': self.lab_config.user_settings_dir, 'labextensions_path': labextensions_path } handlers.append((ujoin(settings_path, '?'), SettingsHandler, settings_config)) # Handle requests for an individual set of settings. setting_path = ujoin( settings_path, '(?P<schema_name>.+)') handlers.append((setting_path, SettingsHandler, settings_config)) # Handle requests for themes themes_path = ujoin(base_url, 'example', 'api', 'themes', '(.*)') handlers.append(( themes_path, ThemesHandler, { 'themes_url': themes_path, 'path': self.lab_config.themes_dir, 'labextensions_path': labextensions_path, 'no_cache_paths': ['/'] } )) web_app.add_handlers('.*$', handlers) def start(self): settings = self.web_app.settings # By default, make terminals available. settings.setdefault('terminals_available', True) super().start()
def setup_class(cls): cls.tmp_dir = TemporaryDirectory() def tmp(*parts): path = os.path.join(cls.tmp_dir.name, *parts) try: os.makedirs(path) except OSError as e: if e.errno != errno.EEXIST: raise return path cls.home_dir = tmp('home') cls.data_dir = tmp('data') cls.config_dir = tmp('config') cls.runtime_dir = tmp('runtime') cls.lab_dir = tmp('lab') cls.app_settings_dir = tmp('appsettings') cls.lab_schemas = tmp('labschemas') cls.lab_settings = tmp('labsettings') cls.lab_workspaces = tmp('labworkspaces') cls.env_patch = patch.dict('os.environ', { 'HOME': cls.home_dir, 'PYTHONPATH': os.pathsep.join(sys.path), 'IPYTHONDIR': pjoin(cls.home_dir, '.ipython'), 'JUPYTER_NO_CONFIG': '1', # needed in the future 'JUPYTER_CONFIG_DIR': cls.config_dir, 'JUPYTER_DATA_DIR': cls.data_dir, 'JUPYTER_RUNTIME_DIR': cls.runtime_dir, 'JUPYTERLAB_DIR': cls.lab_dir, 'JUPYTERLAB_SETTINGS_DIR': cls.lab_settings }) cls.env_patch.start() cls.lab_config = LabConfig( app_settings_dir=cls.app_settings_dir, schemas_dir=cls.lab_schemas, user_settings_dir=cls.lab_settings, workspaces_dir=cls.lab_workspaces) cls.notebook_dir = tmp('notebooks') cls.path_patch = patch.multiple( jupyter_core.paths, SYSTEM_JUPYTER_PATH=[tmp('share', 'jupyter')], ENV_JUPYTER_PATH=[tmp('env', 'share', 'jupyter')], SYSTEM_CONFIG_PATH=[tmp('etc', 'jupyter')], ENV_CONFIG_PATH=[tmp('env', 'etc', 'jupyter')], ) cls.path_patch.start() cls.config = cls.config or Config() cls.config.NotebookNotary.db_file = ':memory:' cls.token = hexlify(os.urandom(4)).decode('ascii') started = Event() def start_thread(): if 'asyncio' in sys.modules: import asyncio asyncio.set_event_loop(asyncio.new_event_loop()) app = cls.notebook = cls.Application( app_dir=cls.lab_dir, port=cls.port, port_retries=0, open_browser=False, config_dir=cls.config_dir, data_dir=cls.data_dir, runtime_dir=cls.runtime_dir, notebook_dir=cls.notebook_dir, base_url=cls.url_prefix, config=cls.config, allow_root=True, token=cls.token, lab_config=cls.lab_config ) # don't register signal handler during tests app.init_signal = lambda: None # clear log handlers and propagate to root for nose to capture it # needs to be redone after initialize, which reconfigures logging app.log.propagate = True app.log.handlers = [] app.initialize(argv=[]) app.log.propagate = True app.log.handlers = [] loop = IOLoop.current() loop.add_callback(started.set) try: app.start() finally: # set the event, so failure to start doesn't cause a hang started.set() app.session_manager.close() cls.notebook_thread = Thread(target=start_thread) cls.notebook_thread.daemon = True cls.notebook_thread.start() started.wait() cls.wait_until_alive()
def load_config(nbapp): """Load the JupyterLab configuration and defaults for a given application. """ from jupyterlab_server import LabConfig from .commands import ( get_app_dir, get_app_info, get_workspaces_dir, get_user_settings_dir, pjoin ) app_dir = getattr(nbapp, 'app_dir', get_app_dir()) info = get_app_info(app_dir) public_url = info['publicUrl'] user_settings_dir = getattr( nbapp, 'user_settings_dir', get_user_settings_dir() ) workspaces_dir = getattr(nbapp, 'workspaces_dir', get_workspaces_dir()) config = LabConfig() config.app_dir = app_dir config.app_name = 'JupyterLab' config.app_namespace = 'jupyterlab' config.app_settings_dir = pjoin(app_dir, 'settings') config.app_version = info['version'] config.cache_files = True config.schemas_dir = pjoin(app_dir, 'schemas') config.templates_dir = pjoin(app_dir, 'static') config.themes_dir = pjoin(app_dir, 'themes') config.user_settings_dir = user_settings_dir config.workspaces_dir = workspaces_dir if public_url: config.public_url = public_url else: config.static_dir = pjoin(app_dir, 'static') return config