Skip to content

Commit

Permalink
rename IDOM_WED_MODULES_DIR to IDOM_WEB_MODULES_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed Feb 2, 2022
1 parent 64b567d commit 295d0b6
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 15 deletions.
20 changes: 20 additions & 0 deletions src/idom/_option.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
import warnings
from logging import getLogger
from typing import Any, Callable, Generic, TypeVar, cast

Expand Down Expand Up @@ -89,3 +90,22 @@ 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
13 changes: 11 additions & 2 deletions src/idom/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path
from tempfile import TemporaryDirectory

from ._option import DeprecatedOption as _DeprecatedOption
from ._option import Option as _Option


Expand Down Expand Up @@ -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 = _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,
)
Expand Down
4 changes: 2 additions & 2 deletions src/idom/server/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -152,7 +152,7 @@ def send_client_dir(path: str) -> Any:

@blueprint.route("/modules/<path:path>")
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"]:

Expand Down
4 changes: 2 additions & 2 deletions src/idom/server/sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"]:

Expand Down
4 changes: 2 additions & 2 deletions src/idom/server/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
),
Expand Down
4 changes: 2 additions & 2 deletions src/idom/server/tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]:
Expand Down
4 changes: 2 additions & 2 deletions src/idom/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
4 changes: 2 additions & 2 deletions src/idom/web/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 295d0b6

Please sign in to comment.