def _default_conf_d_language_servers(self): language_servers = {} # type: KeyedLanguageServerSpecs manager = ConfigManager(read_config_path=jupyter_config_path()) for app in APP_CONFIG_D_SECTIONS: language_servers.update(**manager.get(f"jupyter{app}config").get( self.__class__.__name__, {}).get("language_servers", {})) return language_servers
def _default_config_dict(self): """load merged config from more jupyter_*_config.d files re-uses notebook loading machinery to look through more locations """ manager = ConfigManager(read_config_path=jupyter_config_path()) conf = {} for app in ["_", "_notebook_", "_server_"]: conf.update(**manager.get(f"jupyter{app}config").get("StarterManager", {})) return conf
def _default_config_dict(self): """load merged config from more jupyter_*_config.d files re-uses notebook loading machinery to look through more locations """ config_path = jupyter_config_path() cwd = str(Path.cwd()) if cwd not in config_path: config_path = [cwd, *config_path] manager = ConfigManager(read_config_path=config_path) conf = {} for app in ["_", "_notebook_", "_server_"]: more_conf = manager.get(f"jupyter{app}config").get("StarterManager", {}) conf.update(**more_conf) return conf
def get_bundler(self, bundler_id): """ Get bundler metadata from config given a bundler ID. Parameters ---------- bundler_id: str Unique bundler ID within the jupyter_server/bundlerextensions config section Returns ------- dict Bundler metadata with label, group, and module_name attributes Raises ------ KeyError If the bundler ID is unknown """ cm = ConfigManager() return cm.get('jupyter_server').get('bundlerextensions', {})[bundler_id]
def start(self): self.connection_dir = tempfile.mkdtemp(prefix='voila_', dir=self.connection_dir_root) self.log.info('Storing connection files in %s.' % self.connection_dir) self.log.info('Serving static files from %s.' % self.static_root) self.kernel_spec_manager = KernelSpecManager(parent=self) self.kernel_manager = MappingKernelManager( parent=self, connection_dir=self.connection_dir, kernel_spec_manager=self.kernel_spec_manager, allowed_message_types=[ 'comm_open', 'comm_close', 'comm_msg', 'comm_info_request', 'kernel_info_request', 'shutdown_request' ]) jenv_opt = { "autoescape": True } # we might want extra options via cmd line like notebook server env = jinja2.Environment(loader=jinja2.FileSystemLoader( self.template_paths), extensions=['jinja2.ext.i18n'], **jenv_opt) nbui = gettext.translation('nbui', localedir=os.path.join(ROOT, 'i18n'), fallback=True) env.install_gettext_translations(nbui, newstyle=False) self.contents_manager = LargeFileManager(parent=self) # we create a config manager that load both the serverconfig and nbconfig (classical notebook) read_config_path = [ os.path.join(p, 'serverconfig') for p in jupyter_config_path() ] read_config_path += [ os.path.join(p, 'nbconfig') for p in jupyter_config_path() ] self.config_manager = ConfigManager(parent=self, read_config_path=read_config_path) # default server_url to base_url self.server_url = self.server_url or self.base_url self.app = tornado.web.Application( base_url=self.base_url, server_url=self.server_url or self.base_url, kernel_manager=self.kernel_manager, kernel_spec_manager=self.kernel_spec_manager, allow_remote_access=True, autoreload=self.autoreload, voila_jinja2_env=env, jinja2_env=env, static_path='/', server_root_dir='/', contents_manager=self.contents_manager, config_manager=self.config_manager) self.app.settings.update(self.tornado_settings) handlers = [] handlers.extend([ (url_path_join(self.server_url, r'/api/kernels/%s' % _kernel_id_regex), KernelHandler), (url_path_join(self.server_url, r'/api/kernels/%s/channels' % _kernel_id_regex), ZMQChannelsHandler), (url_path_join(self.server_url, r'/voila/static/(.*)'), MultiStaticFileHandler, { 'paths': self.static_paths, 'default_filename': 'index.html' }) ]) # Serving notebook extensions if self.voila_configuration.enable_nbextensions: handlers.append(( url_path_join(self.server_url, r'/voila/nbextensions/(.*)'), FileFindHandler, { 'path': self.nbextensions_path, 'no_cache_paths': ['/'], # don't cache anything in nbextensions }, )) handlers.append(( url_path_join(self.server_url, r'/voila/files/(.*)'), WhiteListFileHandler, { 'whitelist': self.voila_configuration.file_whitelist, 'blacklist': self.voila_configuration.file_blacklist, 'path': self.root_dir, }, )) tree_handler_conf = {'voila_configuration': self.voila_configuration} if self.notebook_path: handlers.append( (url_path_join(self.server_url, r'/(.*)'), VoilaHandler, { 'notebook_path': os.path.relpath(self.notebook_path, self.root_dir), 'nbconvert_template_paths': self.nbconvert_template_paths, 'config': self.config, 'voila_configuration': self.voila_configuration })) else: self.log.debug('serving directory: %r', self.root_dir) handlers.extend([ (self.server_url, VoilaTreeHandler, tree_handler_conf), (url_path_join(self.server_url, r'/voila/tree' + path_regex), VoilaTreeHandler, tree_handler_conf), (url_path_join(self.server_url, r'/voila/render/(.*)'), VoilaHandler, { 'nbconvert_template_paths': self.nbconvert_template_paths, 'config': self.config, 'voila_configuration': self.voila_configuration }), ]) self.app.add_handlers('.*$', handlers) self.listen()
def start(self): self.connection_dir = tempfile.mkdtemp(prefix='voila_', dir=self.connection_dir_root) self.log.info('Storing connection files in %s.' % self.connection_dir) self.log.info('Serving static files from %s.' % self.static_root) kernel_manager = MappingKernelManager( connection_dir=self.connection_dir, allowed_message_types=[ 'comm_msg', 'comm_info_request', 'kernel_info_request', 'shutdown_request' ]) jenv_opt = { "autoescape": True } # we might want extra options via cmd line like notebook server env = jinja2.Environment(loader=jinja2.FileSystemLoader( self.template_paths), extensions=['jinja2.ext.i18n'], **jenv_opt) nbui = gettext.translation('nbui', localedir=os.path.join(ROOT, 'i18n'), fallback=True) env.install_gettext_translations(nbui, newstyle=False) contents_manager = LargeFileManager( parent=self) # TODO: make this configurable like notebook # we create a config manager that load both the serverconfig and nbconfig (classical notebook) read_config_path = [ os.path.join(p, 'serverconfig') for p in jupyter_config_path() ] read_config_path += [ os.path.join(p, 'nbconfig') for p in jupyter_config_path() ] self.config_manager = ConfigManager(parent=self, read_config_path=read_config_path) self.app = tornado.web.Application(kernel_manager=kernel_manager, allow_remote_access=True, autoreload=self.autoreload, voila_jinja2_env=env, jinja2_env=env, static_path='/', server_root_dir='/', contents_manager=contents_manager, config_manager=self.config_manager) base_url = self.app.settings.get('base_url', '/') handlers = [] handlers.extend([ (url_path_join(base_url, r'/api/kernels/%s' % _kernel_id_regex), KernelHandler), (url_path_join(base_url, r'/api/kernels/%s/channels' % _kernel_id_regex), ZMQChannelsHandler), (url_path_join(base_url, r'/voila/static/(.*)'), MultiStaticFileHandler, { 'paths': self.static_paths, 'default_filename': 'index.html' }) ]) # this handler serves the nbextensions similar to the classical notebook handlers.append(( url_path_join(base_url, r'/voila/nbextensions/(.*)'), FileFindHandler, { 'path': self.nbextensions_path, 'no_cache_paths': ['/'], # don't cache anything in nbextensions }, )) if self.notebook_path: handlers.append((url_path_join(base_url, r'/'), VoilaHandler, { 'notebook_path': os.path.relpath(self.notebook_path, self.root_dir), 'strip_sources': self.strip_sources, 'nbconvert_template_paths': self.nbconvert_template_paths, 'config': self.config })) else: handlers.extend([ (base_url, VoilaTreeHandler), (url_path_join(base_url, r'/voila/tree' + path_regex), VoilaTreeHandler), (url_path_join(base_url, r'/voila/render' + path_regex), VoilaHandler, { 'strip_sources': self.strip_sources }), ]) self.app.add_handlers('.*$', handlers) self.listen()