update: optimize config.py
This commit is contained in:
@@ -3,12 +3,24 @@ try:
|
||||
except ImportError:
|
||||
# Fallback when using the package in dev mode without installing
|
||||
# in editable mode with pip. It is highly recommended to install
|
||||
# the package from a stable release or in editable mode: https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs
|
||||
# the package from a stable release or in editable mode: https://pip.pypa.io/en/stable/topics/local-project-install/
|
||||
import warnings
|
||||
warnings.warn("Importing 'opencode_bridge' outside a proper installation.")
|
||||
__version__ = "dev"
|
||||
from .config import OpencodeConfig
|
||||
from .routes import setup_route_handlers
|
||||
|
||||
# Re-export OpencodeConfig at module level so the JupyterApp CLI parser
|
||||
# (which auto-discovers Configurable subclasses from extension-point
|
||||
# modules) recognises ``--OpencodeConfig.<trait>`` flags.
|
||||
__all__ = [
|
||||
"OpencodeConfig",
|
||||
"setup_route_handlers",
|
||||
"_jupyter_labextension_paths",
|
||||
"_jupyter_server_extension_points",
|
||||
"_load_jupyter_server_extension",
|
||||
]
|
||||
|
||||
|
||||
def _jupyter_labextension_paths():
|
||||
return [{
|
||||
@@ -26,11 +38,25 @@ def _jupyter_server_extension_points():
|
||||
def _load_jupyter_server_extension(server_app):
|
||||
"""Registers the API handler to receive HTTP requests from the frontend extension.
|
||||
|
||||
Also instantiates the :class:`OpencodeConfig` configurable (with the
|
||||
server app as parent so CLI / config-file overrides take effect) and
|
||||
exposes it to request handlers via
|
||||
``web_app.settings["opencode_bridge"]``.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
server_app: jupyterlab.labapp.LabApp
|
||||
JupyterLab application instance
|
||||
"""
|
||||
# Belt-and-suspenders: ensure the CLI parser recognises --OpencodeConfig.*
|
||||
# even on JupyterApp versions that don't auto-discover Configurable
|
||||
# subclasses from extension-point modules.
|
||||
if OpencodeConfig not in server_app.classes:
|
||||
server_app.classes.append(OpencodeConfig)
|
||||
|
||||
cfg = OpencodeConfig(parent=server_app)
|
||||
server_app.web_app.settings["opencode_bridge"] = cfg
|
||||
|
||||
setup_route_handlers(server_app.web_app)
|
||||
name = "opencode_bridge"
|
||||
server_app.log.info(f"Registered {name} server extension")
|
||||
|
||||
Reference in New Issue
Block a user