Skip to content

Commit

Permalink
Update mesop version and remove mesop patch (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaranvpl authored Oct 21, 2024
1 parent d50e04d commit 0cb6012
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 145 deletions.
73 changes: 15 additions & 58 deletions fastagency/ui/mesop/timer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import os
import os.path
import sys
from collections.abc import Iterator
from contextlib import contextmanager
from pathlib import Path
from typing import Any, Callable, Optional, SupportsIndex, Union
from typing import Any, Callable, Optional

import mesop.labs as mel
import mesop.server.static_file_serving
Expand Down Expand Up @@ -61,57 +56,19 @@ def serve_web_components_fast_agency(path: str) -> Response:


MEL_WEB_COMPONENT_PATH = "/__fast_agency_internal__/javascript/wakeup_component.js"
WINDOWS_MEL_WEB_COMPONENT_PATH = MEL_WEB_COMPONENT_PATH.replace("/", "\\")


# Extended subclass
class _MyPatchedStr(str):
def startswith(
self,
prefix: Union[str, tuple[str, ...]],
start: Optional[SupportsIndex] = None,
end: Optional[SupportsIndex] = None,
) -> bool:
return (
super().startswith("\\", start, end) and prefix == "/"
) or super().startswith(prefix, start, end)


_original_os_path_normpath = os.path.normpath


def _os_path_normpath_patch(path: str) -> str:
path = _original_os_path_normpath(path)
if path == WINDOWS_MEL_WEB_COMPONENT_PATH:
return _MyPatchedStr(path)
return path


@contextmanager
def _patch_os_path_normpath_for_win32() -> Iterator[None]:
if sys.platform == "win32":
os.path.normpath = _os_path_normpath_patch # type: ignore[assignment]
try:
yield
finally:
os.path.normpath = _original_os_path_normpath
else:
yield


with _patch_os_path_normpath_for_win32():

@mel.web_component(path=MEL_WEB_COMPONENT_PATH) # type: ignore[misc]
def wakeup_component(
*,
on_wakeup: Callable[[mel.WebEvent], Any],
key: Optional[str] = None,
) -> Any:
return mel.insert_web_component(
name="wakeup-component",
key=key,
events={
"wakeupEvent": on_wakeup,
},
properties={},
)
@mel.web_component(path=MEL_WEB_COMPONENT_PATH) # type: ignore[misc]
def wakeup_component(
*,
on_wakeup: Callable[[mel.WebEvent], Any],
key: Optional[str] = None,
) -> Any:
return mel.insert_web_component(
name="wakeup-component",
key=key,
events={
"wakeupEvent": on_wakeup,
},
properties={},
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies = [
# public distributions

mesop = [
"mesop>=0.12.5, <1; python_version >= '3.10'"
"mesop>=0.12.7, <1; python_version >= '3.10'"
]

pyautogen = [
Expand Down
86 changes: 0 additions & 86 deletions tests/ui/mesop/test_str_patch.py

This file was deleted.

0 comments on commit 0cb6012

Please sign in to comment.