Skip to content

Commit 295d0b6

Browse files
committed
rename IDOM_WED_MODULES_DIR to IDOM_WEB_MODULES_DIR
1 parent 64b567d commit 295d0b6

File tree

9 files changed

+44
-15
lines changed

9 files changed

+44
-15
lines changed

src/idom/_option.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import os
4+
import warnings
45
from logging import getLogger
56
from typing import Any, Callable, Generic, TypeVar, cast
67

@@ -89,3 +90,22 @@ def unset(self) -> None:
8990

9091
def __repr__(self) -> str:
9192
return f"Option({self._name}={self.current!r})"
93+
94+
95+
class DeprecatedOption(Option[_O]): # pragma: no cover
96+
def __init__(self, new_name: str | None, *args: Any, **kwargs: Any) -> None:
97+
self.new_name = new_name
98+
with warnings.catch_warnings():
99+
warnings.simplefilter("ignore", DeprecationWarning)
100+
super().__init__(*args, **kwargs)
101+
102+
@property
103+
def current(self) -> _O:
104+
if self.new_name is None:
105+
warnings.warn(f"{self.name!r} has been removed", DeprecationWarning)
106+
else:
107+
warnings.warn(
108+
f"{self.name!r} has been renamed to {self.new_name!r}",
109+
DeprecationWarning,
110+
)
111+
return super().current

src/idom/config.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pathlib import Path
77
from tempfile import TemporaryDirectory
88

9+
from ._option import DeprecatedOption as _DeprecatedOption
910
from ._option import Option as _Option
1011

1112

@@ -43,8 +44,16 @@
4344
# Because these web modules will be linked dynamically at runtime this can be temporary
4445
_DEFAULT_WEB_MODULES_DIR = TemporaryDirectory()
4546

46-
IDOM_WED_MODULES_DIR = _Option(
47-
"IDOM_WED_MODULES_DIR",
47+
IDOM_WED_MODULES_DIR = _DeprecatedOption(
48+
new_name="IDOM_WEB_MODULES_DIR",
49+
name="IDOM_WED_MODULES_DIR",
50+
default=Path(_DEFAULT_WEB_MODULES_DIR.name),
51+
validator=Path,
52+
)
53+
"""This has been renamed to :data:`IDOM_WEB_MODULES_DIR`"""
54+
55+
IDOM_WEB_MODULES_DIR = _Option(
56+
"IDOM_WEB_MODULES_DIR",
4857
default=Path(_DEFAULT_WEB_MODULES_DIR.name),
4958
validator=Path,
5059
)

src/idom/server/flask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from typing_extensions import TypedDict
2020

2121
import idom
22-
from idom.config import IDOM_DEBUG_MODE, IDOM_WED_MODULES_DIR
22+
from idom.config import IDOM_DEBUG_MODE, IDOM_WEB_MODULES_DIR
2323
from idom.core.dispatcher import dispatch_single_view
2424
from idom.core.layout import LayoutEvent, LayoutUpdate
2525
from idom.core.proto import ComponentConstructor, ComponentType
@@ -152,7 +152,7 @@ def send_client_dir(path: str) -> Any:
152152

153153
@blueprint.route("/modules/<path:path>")
154154
def send_modules_dir(path: str) -> Any:
155-
return send_from_directory(str(IDOM_WED_MODULES_DIR.current), path)
155+
return send_from_directory(str(IDOM_WEB_MODULES_DIR.current), path)
156156

157157
if config["redirect_root_to_index"]:
158158

src/idom/server/sanic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from sanic_cors import CORS
1414
from websockets import WebSocketCommonProtocol
1515

16-
from idom.config import IDOM_WED_MODULES_DIR
16+
from idom.config import IDOM_WEB_MODULES_DIR
1717
from idom.core.dispatcher import (
1818
RecvCoroutine,
1919
SendCoroutine,
@@ -186,7 +186,7 @@ def _setup_common_routes(blueprint: Blueprint, config: Config) -> None:
186186

187187
if config["serve_static_files"]:
188188
blueprint.static("/client", str(CLIENT_BUILD_DIR))
189-
blueprint.static("/modules", str(IDOM_WED_MODULES_DIR.current))
189+
blueprint.static("/modules", str(IDOM_WEB_MODULES_DIR.current))
190190

191191
if config["redirect_root_to_index"]:
192192

src/idom/server/starlette.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from uvicorn.supervisors.multiprocess import Multiprocess
2121
from uvicorn.supervisors.statreload import StatReload as ChangeReload
2222

23-
from idom.config import IDOM_DEBUG_MODE, IDOM_WED_MODULES_DIR
23+
from idom.config import IDOM_DEBUG_MODE, IDOM_WEB_MODULES_DIR
2424
from idom.core.dispatcher import (
2525
RecvCoroutine,
2626
SendCoroutine,
@@ -211,7 +211,7 @@ def _setup_common_routes(config: Config, app: Starlette) -> None:
211211
app.mount(
212212
f"{url_prefix}/modules",
213213
StaticFiles(
214-
directory=str(IDOM_WED_MODULES_DIR.current),
214+
directory=str(IDOM_WEB_MODULES_DIR.current),
215215
html=True,
216216
check_dir=False,
217217
),

src/idom/server/tornado.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from tornado.websocket import WebSocketHandler
1414
from typing_extensions import TypedDict
1515

16-
from idom.config import IDOM_WED_MODULES_DIR
16+
from idom.config import IDOM_WEB_MODULES_DIR
1717
from idom.core.dispatcher import VdomJsonPatch, dispatch_single_view
1818
from idom.core.layout import Layout, LayoutEvent
1919
from idom.core.proto import ComponentConstructor
@@ -133,7 +133,7 @@ def _setup_common_routes(config: Config) -> _RouteHandlerSpecs:
133133
(
134134
r"/modules/(.*)",
135135
StaticFileHandler,
136-
{"path": str(IDOM_WED_MODULES_DIR.current)},
136+
{"path": str(IDOM_WEB_MODULES_DIR.current)},
137137
)
138138
)
139139
if config["redirect_root_to_index"]:

src/idom/testing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from selenium.webdriver import Chrome
2929
from selenium.webdriver.remote.webdriver import WebDriver
3030

31-
from idom.config import IDOM_WED_MODULES_DIR
31+
from idom.config import IDOM_WEB_MODULES_DIR
3232
from idom.core.events import EventHandler, to_event_handler_function
3333
from idom.core.hooks import LifeCycleHook, current_hook
3434
from idom.server.prefab import hotswap_server
@@ -433,5 +433,5 @@ def use(
433433

434434

435435
def clear_idom_web_modules_dir() -> None:
436-
for path in IDOM_WED_MODULES_DIR.current.iterdir():
436+
for path in IDOM_WEB_MODULES_DIR.current.iterdir():
437437
shutil.rmtree(path) if path.is_dir() else path.unlink()

src/idom/web/module.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from typing_extensions import Protocol
1414

15-
from idom.config import IDOM_DEBUG_MODE, IDOM_WED_MODULES_DIR
15+
from idom.config import IDOM_DEBUG_MODE, IDOM_WEB_MODULES_DIR
1616
from idom.core.proto import (
1717
EventHandlerMapping,
1818
ImportSourceDict,
@@ -391,6 +391,6 @@ def _make_export(
391391

392392

393393
def _web_module_path(name: str) -> Path:
394-
directory = IDOM_WED_MODULES_DIR.current
394+
directory = IDOM_WEB_MODULES_DIR.current
395395
path = directory.joinpath(*name.split("/"))
396396
return path.with_suffix(path.suffix)

tests/test_html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def HasScript():
117117
display(HasScript)
118118

119119
for i in range(1, 4):
120-
script_file = config.IDOM_WED_MODULES_DIR.current / file_name_template.format(
120+
script_file = config.IDOM_WEB_MODULES_DIR.current / file_name_template.format(
121121
src_id=i
122122
)
123123
script_file.write_text(

0 commit comments

Comments
 (0)