From e740379b3f95716e2f0f46a933cee3125cb13705 Mon Sep 17 00:00:00 2001 From: Ronan Coutinho <119519068+cronan03@users.noreply.github.com> Date: Sun, 9 Jun 2024 00:36:52 +0530 Subject: [PATCH] Update jupyter_builder/federated_extensions_requirements.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Frédéric Collonval --- .../federated_extensions_requirements.py | 312 ------------------ 1 file changed, 312 deletions(-) diff --git a/jupyter_builder/federated_extensions_requirements.py b/jupyter_builder/federated_extensions_requirements.py index 7198069..841adfa 100644 --- a/jupyter_builder/federated_extensions_requirements.py +++ b/jupyter_builder/federated_extensions_requirements.py @@ -71,315 +71,3 @@ def get_federated_extensions(labextensions_path: list[str]) -> dict[str, Any]: data["install"] = json.load(fid) federated_extensions[data["name"]] = data return federated_extensions - - -# def get_static_page_config( -# app_settings_dir: str | None = None, # noqa: ARG001 -# logger: Logger | None = None, # noqa: ARG001 -# level: str = "all", -# ) -> dict[str, Any]: -# """Get the static page config for JupyterLab - -# Parameters -# ---------- -# logger: logger, optional -# An optional logging object -# level: string, optional ['all'] -# The level at which to get config: can be 'all', 'user', 'sys_prefix', or 'system' -# """ -# cm = _get_config_manager(level) -# return cm.get("page_config") # type:ignore[no-untyped-call] - - -# def load_config(path: str) -> Any: -# """Load either a json5 or a json config file. - -# Parameters -# ---------- -# path : str -# Path to the file to be loaded - -# Returns -# ------- -# Dict[Any, Any] -# Dictionary of json or json5 data -# """ -# with open(path, encoding="utf-8") as fid: -# if path.endswith(".json5"): -# return json5.load(fid) -# return json.load(fid) - - -# def get_page_config( -# labextensions_path: list[str], app_settings_dir: str | None = None, logger: Logger | None = None -# ) -> dict[str, Any]: -# """Get the page config for the application handler""" -# # Build up the full page config -# page_config: dict = {} - -# disabled_key = "disabledExtensions" - -# # Start with the app_settings_dir as lowest priority -# if app_settings_dir: -# config_paths = [ -# pjoin(app_settings_dir, "page_config.json5"), -# pjoin(app_settings_dir, "page_config.json"), -# ] -# for path in config_paths: -# if osp.exists(path): -# data = load_config(path) -# # Convert lists to dicts -# for key in [disabled_key, "deferredExtensions"]: -# if key in data: -# data[key] = {key: True for key in data[key]} - -# recursive_update(page_config, data) -# break - -# # Get the traitlets config -# static_page_config = get_static_page_config(logger=logger, level="all") -# recursive_update(page_config, static_page_config) - -# # Handle federated extensions that disable other extensions -# disabled_by_extensions_all = {} -# extensions = page_config["federated_extensions"] = [] - -# federated_exts = get_federated_extensions(labextensions_path) - -# # Ensure there is a disabled key -# page_config.setdefault(disabled_key, {}) - -# for _, ext_data in federated_exts.items(): -# if "_build" not in ext_data["jupyterlab"]: -# if logger: -# logger.warning("%s is not a valid extension", ext_data["name"]) -# continue -# extbuild = ext_data["jupyterlab"]["_build"] -# extension = {"name": ext_data["name"], "load": extbuild["load"]} - -# if "extension" in extbuild: -# extension["extension"] = extbuild["extension"] -# if "mimeExtension" in extbuild: -# extension["mimeExtension"] = extbuild["mimeExtension"] -# if "style" in extbuild: -# extension["style"] = extbuild["style"] -# extensions.append(extension) - -# # If there is disabledExtensions metadata, consume it. -# name = ext_data["name"] - -# if ext_data["jupyterlab"].get(disabled_key): -# disabled_by_extensions_all[ext_data["name"]] = ext_data["jupyterlab"][disabled_key] - -# # Handle source extensions that disable other extensions -# # Check for `jupyterlab`:`extensionMetadata` in the built application directory's package.json -# if app_settings_dir: -# app_dir = osp.dirname(app_settings_dir) -# package_data_file = pjoin(app_dir, "static", "package.json") -# if osp.exists(package_data_file): -# with open(package_data_file, encoding="utf-8") as fid: -# app_data = json.load(fid) -# all_ext_data = app_data["jupyterlab"].get("extensionMetadata", {}) -# for ext, ext_data in all_ext_data.items(): -# if ext in disabled_by_extensions_all: -# continue -# if ext_data.get(disabled_key): -# disabled_by_extensions_all[ext] = ext_data[disabled_key] - -# disabled_by_extensions = {} -# for name in sorted(disabled_by_extensions_all): -# # skip if the extension itself is disabled by other config -# if page_config[disabled_key].get(name) is True: -# continue - -# disabled_list = disabled_by_extensions_all[name] -# for item in disabled_list: -# disabled_by_extensions[item] = True - -# rollup_disabled = disabled_by_extensions -# rollup_disabled.update(page_config.get(disabled_key, [])) -# page_config[disabled_key] = rollup_disabled - -# # Convert dictionaries to lists to give to the front end -# for key, value in page_config.items(): -# if isinstance(value, dict): -# page_config[key] = [subkey for subkey in value if value[subkey]] - -# return page_config - - -# def write_page_config(page_config: dict[str, Any], level: str = "all") -> None: -# """Write page config to disk""" -# cm = _get_config_manager(level) -# cm.set("page_config", page_config) # type:ignore[no-untyped-call] - - -# class LabConfig(HasTraits): -# """The lab application configuration object.""" - -# app_name = Unicode("", help="The name of the application.").tag(config=True) - -# app_version = Unicode("", help="The version of the application.").tag(config=True) - -# app_namespace = Unicode("", help="The namespace of the application.").tag(config=True) - -# app_url = Unicode("/lab", help="The url path for the application.").tag(config=True) - -# app_settings_dir = Unicode("", help="The application settings directory.").tag(config=True) - -# extra_labextensions_path = List( -# Unicode(), help="""Extra paths to look for federated JupyterLab extensions""" -# ).tag(config=True) - -# labextensions_path = List( -# Unicode(), help="The standard paths to look in for federated JupyterLab extensions" -# ).tag(config=True) - -# templates_dir = Unicode("", help="The application templates directory.").tag(config=True) - -# static_dir = Unicode( -# "", -# help=( -# "The optional location of local static files. " -# "If given, a static file handler will be " -# "added." -# ), -# ).tag(config=True) - -# labextensions_url = Unicode("", help="The url for federated JupyterLab extensions").tag( -# config=True -# ) - -# settings_url = Unicode(help="The url path of the settings handler.").tag(config=True) - -# user_settings_dir = Unicode( -# "", help=("The optional location of the user settings directory.") -# ).tag(config=True) - -# schemas_dir = Unicode( -# "", -# help=( -# "The optional location of the settings " -# "schemas directory. If given, a handler will " -# "be added for settings." -# ), -# ).tag(config=True) - -# workspaces_api_url = Unicode(help="The url path of the workspaces API.").tag(config=True) - -# workspaces_dir = Unicode( -# "", -# help=( -# "The optional location of the saved " -# "workspaces directory. If given, a handler " -# "will be added for workspaces." -# ), -# ).tag(config=True) - -# listings_url = Unicode(help="The listings url.").tag(config=True) - -# themes_url = Unicode(help="The theme url.").tag(config=True) - -# licenses_url = Unicode(help="The third-party licenses url.") - -# themes_dir = Unicode( -# "", -# help=( -# "The optional location of the themes " -# "directory. If given, a handler will be added " -# "for themes." -# ), -# ).tag(config=True) - -# translations_api_url = Unicode(help="The url path of the translations handler.").tag( -# config=True -# ) - -# tree_url = Unicode(help="The url path of the tree handler.").tag(config=True) - -# cache_files = Bool( -# True, -# help=("Whether to cache files on the server. This should be `True` except in dev mode."), -# ).tag(config=True) - -# notebook_starts_kernel = Bool( -# True, help="Whether a notebook should start a kernel automatically." -# ).tag(config=True) - -# copy_absolute_path = Bool( -# False, -# help="Whether getting a relative (False) or absolute (True) path when copying a path.", -# ).tag(config=True) - -# @default("template_dir") -# def _default_template_dir(self) -> str: -# return DEFAULT_TEMPLATE_PATH - -# @default("labextensions_url") -# def _default_labextensions_url(self) -> str: -# return ujoin(self.app_url, "extensions/") - -# @default("labextensions_path") -# def _default_labextensions_path(self) -> list[str]: -# return jupyter_path("labextensions") - -# @default("workspaces_url") -# def _default_workspaces_url(self) -> str: -# return ujoin(self.app_url, "workspaces/") - -# @default("workspaces_api_url") -# def _default_workspaces_api_url(self) -> str: -# return ujoin(self.app_url, "api", "workspaces/") - -# @default("settings_url") -# def _default_settings_url(self) -> str: -# return ujoin(self.app_url, "api", "settings/") - -# @default("listings_url") -# def _default_listings_url(self) -> str: -# return ujoin(self.app_url, "api", "listings/") - -# @default("themes_url") -# def _default_themes_url(self) -> str: -# return ujoin(self.app_url, "api", "themes/") - -# @default("licenses_url") -# def _default_licenses_url(self) -> str: -# return ujoin(self.app_url, "api", "licenses/") - -# @default("tree_url") -# def _default_tree_url(self) -> str: -# return ujoin(self.app_url, "tree/") - -# @default("translations_api_url") -# def _default_translations_api_url(self) -> str: -# return ujoin(self.app_url, "api", "translations/") - - -# def _get_config_manager(level: str) -> ConfigManager: -# """Get the location of config files for the current context -# Returns the string to the environment -# """ -# allowed = ["all", "user", "sys_prefix", "system", "app", "extension"] -# if level not in allowed: -# msg = f"Page config level must be one of: {allowed}" -# raise ValueError(msg) - -# config_name = "labconfig" - -# if level == "all": -# return ConfigManager(config_dir_name=config_name) - -# if level == "user": -# config_dir = jupyter_config_dir() -# elif level == "sys_prefix": -# # Delayed import since this gets monkey-patched in tests -# from jupyter_core.paths import ENV_CONFIG_PATH - -# config_dir = ENV_CONFIG_PATH[0] -# else: -# config_dir = SYSTEM_CONFIG_PATH[0] - -# full_config_path = osp.join(config_dir, config_name) - -# return ConfigManager(read_config_path=[full_config_path], write_config_dir=full_config_path)