diff --git a/src/idom/_option.py b/src/idom/_option.py index 8bb7712b8..b405e3e1a 100644 --- a/src/idom/_option.py +++ b/src/idom/_option.py @@ -1,6 +1,7 @@ from __future__ import annotations import os +import warnings from logging import getLogger from typing import Any, Callable, Generic, TypeVar, cast @@ -89,3 +90,34 @@ def unset(self) -> None: def __repr__(self) -> str: return f"Option({self._name}={self.current!r})" + + +class DeprecatedOption(Option[_O]): # pragma: no cover + def __init__(self, new_name: str | None, *args: Any, **kwargs: Any) -> None: + self.new_name = new_name + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + super().__init__(*args, **kwargs) + + @property + def current(self) -> _O: + if self.new_name is None: + warnings.warn(f"{self.name!r} has been removed", DeprecationWarning) + else: + warnings.warn( + f"{self.name!r} has been renamed to {self.new_name!r}", + DeprecationWarning, + ) + return super().current + + @current.setter + def current(self, new: _O) -> None: + if self.new_name is None: + warnings.warn(f"{self.name!r} has been removed", DeprecationWarning) + else: + warnings.warn( + f"{self.name!r} has been renamed to {self.new_name!r}", + DeprecationWarning, + ) + self.set_current(new) + return None diff --git a/src/idom/config.py b/src/idom/config.py index c4d73ff96..11a493713 100644 --- a/src/idom/config.py +++ b/src/idom/config.py @@ -6,6 +6,7 @@ from pathlib import Path from tempfile import TemporaryDirectory +from ._option import DeprecatedOption as _DeprecatedOption from ._option import Option as _Option @@ -43,8 +44,16 @@ # Because these web modules will be linked dynamically at runtime this can be temporary _DEFAULT_WEB_MODULES_DIR = TemporaryDirectory() -IDOM_WED_MODULES_DIR = _Option( - "IDOM_WED_MODULES_DIR", +IDOM_WED_MODULES_DIR: _Option[Path] = _DeprecatedOption( + new_name="IDOM_WEB_MODULES_DIR", + name="IDOM_WED_MODULES_DIR", + default=Path(_DEFAULT_WEB_MODULES_DIR.name), + validator=Path, +) +"""This has been renamed to :data:`IDOM_WEB_MODULES_DIR`""" + +IDOM_WEB_MODULES_DIR = _Option( + "IDOM_WEB_MODULES_DIR", default=Path(_DEFAULT_WEB_MODULES_DIR.name), validator=Path, ) diff --git a/src/idom/server/flask.py b/src/idom/server/flask.py index 895735c2a..87ab88c6c 100644 --- a/src/idom/server/flask.py +++ b/src/idom/server/flask.py @@ -19,7 +19,7 @@ from typing_extensions import TypedDict import idom -from idom.config import IDOM_DEBUG_MODE, IDOM_WED_MODULES_DIR +from idom.config import IDOM_DEBUG_MODE, IDOM_WEB_MODULES_DIR from idom.core.dispatcher import dispatch_single_view from idom.core.layout import LayoutEvent, LayoutUpdate from idom.core.proto import ComponentConstructor, ComponentType @@ -152,7 +152,7 @@ def send_client_dir(path: str) -> Any: @blueprint.route("/modules/") def send_modules_dir(path: str) -> Any: - return send_from_directory(str(IDOM_WED_MODULES_DIR.current), path) + return send_from_directory(str(IDOM_WEB_MODULES_DIR.current), path) if config["redirect_root_to_index"]: diff --git a/src/idom/server/sanic.py b/src/idom/server/sanic.py index aba81e63e..53740b832 100644 --- a/src/idom/server/sanic.py +++ b/src/idom/server/sanic.py @@ -13,7 +13,7 @@ from sanic_cors import CORS from websockets import WebSocketCommonProtocol -from idom.config import IDOM_WED_MODULES_DIR +from idom.config import IDOM_WEB_MODULES_DIR from idom.core.dispatcher import ( RecvCoroutine, SendCoroutine, @@ -186,7 +186,7 @@ def _setup_common_routes(blueprint: Blueprint, config: Config) -> None: if config["serve_static_files"]: blueprint.static("/client", str(CLIENT_BUILD_DIR)) - blueprint.static("/modules", str(IDOM_WED_MODULES_DIR.current)) + blueprint.static("/modules", str(IDOM_WEB_MODULES_DIR.current)) if config["redirect_root_to_index"]: diff --git a/src/idom/server/starlette.py b/src/idom/server/starlette.py index 5b751e140..63c105b1a 100644 --- a/src/idom/server/starlette.py +++ b/src/idom/server/starlette.py @@ -20,7 +20,7 @@ from uvicorn.supervisors.multiprocess import Multiprocess from uvicorn.supervisors.statreload import StatReload as ChangeReload -from idom.config import IDOM_DEBUG_MODE, IDOM_WED_MODULES_DIR +from idom.config import IDOM_DEBUG_MODE, IDOM_WEB_MODULES_DIR from idom.core.dispatcher import ( RecvCoroutine, SendCoroutine, @@ -211,7 +211,7 @@ def _setup_common_routes(config: Config, app: Starlette) -> None: app.mount( f"{url_prefix}/modules", StaticFiles( - directory=str(IDOM_WED_MODULES_DIR.current), + directory=str(IDOM_WEB_MODULES_DIR.current), html=True, check_dir=False, ), diff --git a/src/idom/server/tornado.py b/src/idom/server/tornado.py index b8cb21f1c..d7daa7476 100644 --- a/src/idom/server/tornado.py +++ b/src/idom/server/tornado.py @@ -13,7 +13,7 @@ from tornado.websocket import WebSocketHandler from typing_extensions import TypedDict -from idom.config import IDOM_WED_MODULES_DIR +from idom.config import IDOM_WEB_MODULES_DIR from idom.core.dispatcher import VdomJsonPatch, dispatch_single_view from idom.core.layout import Layout, LayoutEvent from idom.core.proto import ComponentConstructor @@ -133,7 +133,7 @@ def _setup_common_routes(config: Config) -> _RouteHandlerSpecs: ( r"/modules/(.*)", StaticFileHandler, - {"path": str(IDOM_WED_MODULES_DIR.current)}, + {"path": str(IDOM_WEB_MODULES_DIR.current)}, ) ) if config["redirect_root_to_index"]: diff --git a/src/idom/testing.py b/src/idom/testing.py index e310e4fe8..7c4f1c2fb 100644 --- a/src/idom/testing.py +++ b/src/idom/testing.py @@ -28,7 +28,7 @@ from selenium.webdriver import Chrome from selenium.webdriver.remote.webdriver import WebDriver -from idom.config import IDOM_WED_MODULES_DIR +from idom.config import IDOM_WEB_MODULES_DIR from idom.core.events import EventHandler, to_event_handler_function from idom.core.hooks import LifeCycleHook, current_hook from idom.server.prefab import hotswap_server @@ -433,5 +433,5 @@ def use( def clear_idom_web_modules_dir() -> None: - for path in IDOM_WED_MODULES_DIR.current.iterdir(): + for path in IDOM_WEB_MODULES_DIR.current.iterdir(): shutil.rmtree(path) if path.is_dir() else path.unlink() diff --git a/src/idom/web/module.py b/src/idom/web/module.py index e35fee681..a113d0274 100644 --- a/src/idom/web/module.py +++ b/src/idom/web/module.py @@ -12,7 +12,7 @@ from typing_extensions import Protocol -from idom.config import IDOM_DEBUG_MODE, IDOM_WED_MODULES_DIR +from idom.config import IDOM_DEBUG_MODE, IDOM_WEB_MODULES_DIR from idom.core.proto import ( EventHandlerMapping, ImportSourceDict, @@ -391,6 +391,6 @@ def _make_export( def _web_module_path(name: str) -> Path: - directory = IDOM_WED_MODULES_DIR.current + directory = IDOM_WEB_MODULES_DIR.current path = directory.joinpath(*name.split("/")) return path.with_suffix(path.suffix) diff --git a/tests/test_html.py b/tests/test_html.py index fbc888627..e61ef9c22 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -117,7 +117,7 @@ def HasScript(): display(HasScript) for i in range(1, 4): - script_file = config.IDOM_WED_MODULES_DIR.current / file_name_template.format( + script_file = config.IDOM_WEB_MODULES_DIR.current / file_name_template.format( src_id=i ) script_file.write_text(