def test_puller_ext(): from jupyter_core.paths import jupyter_config_path from jupyter_server.extension.config import ExtensionConfigManager from jupyter_server.extension.manager import ExtensionManager m = ExtensionManager(config_manager=ExtensionConfigManager( read_config_path=jupyter_config_path())) for name, ext in m.extensions.items(): print(f"Validating extension {name}") # workaround for ep_name, extension_point in ext.extension_points.items(): print(f"Validating extension {name}.{ep_name}") assert extension_point.validate() in {None, True} ext.validate() assert "pull_server_ext" in m.extensions
def _get_extmanager_for_context(user=False, sys_prefix=False): """Get an extension manager pointing at the current context Returns the path to the current context and an ExtensionManager object. Parameters ---------- user : bool [default: False] Get the user's .jupyter config directory sys_prefix : bool [default: False] Get sys.prefix, i.e. ~/.envs/my-env/etc/jupyter """ config_dir = _get_config_dir(user=user, sys_prefix=sys_prefix) config_manager = ExtensionConfigManager( read_config_path=[config_dir], write_config_dir=os.path.join(config_dir, "jupyter_server_config.d"), ) extension_manager = ExtensionManager(config_manager=config_manager, ) return config_dir, extension_manager
def toggle_server_extension_python(import_name, enabled=None, parent=None, user=False, sys_prefix=True): """Toggle the boolean setting for a given server extension in a Jupyter config file. """ sys_prefix = False if user else sys_prefix config_dir = _get_config_dir(user=user, sys_prefix=sys_prefix) manager = ExtensionConfigManager(read_config_path=[config_dir], write_config_dir=os.path.join( config_dir, "jupyter_server_config.d")) if enabled: manager.enable(import_name) else: manager.disable(import_name)
def test_list_extension_from_configd(ext1_config, ext2_config): manager = ExtensionConfigManager(read_config_path=jupyter_config_path()) extensions = manager.get_jpserver_extensions() assert "ext2_config" in extensions assert "ext1_config" in extensions