From 7b0bfb8a48ca7cd196686f1c8fd8d16a7745b761 Mon Sep 17 00:00:00 2001 From: Josh Birlingmair Date: Thu, 7 Mar 2024 00:16:03 -0600 Subject: [PATCH 01/13] Remove `reactpy.backend.hooks` module --- src/py/reactpy/reactpy/__init__.py | 4 ++- src/py/reactpy/reactpy/backend/flask.py | 15 ++++++----- src/py/reactpy/reactpy/backend/hooks.py | 30 --------------------- src/py/reactpy/reactpy/backend/sanic.py | 4 +-- src/py/reactpy/reactpy/backend/starlette.py | 4 +-- src/py/reactpy/reactpy/backend/tornado.py | 4 +-- src/py/reactpy/reactpy/core/hooks.py | 25 +++++++++++++++++ 7 files changed, 43 insertions(+), 43 deletions(-) delete mode 100644 src/py/reactpy/reactpy/backend/hooks.py diff --git a/src/py/reactpy/reactpy/__init__.py b/src/py/reactpy/reactpy/__init__.py index 49e357441..c47142cd8 100644 --- a/src/py/reactpy/reactpy/__init__.py +++ b/src/py/reactpy/reactpy/__init__.py @@ -1,5 +1,4 @@ from reactpy import backend, config, html, logging, sample, svg, types, web, widgets -from reactpy.backend.hooks import use_connection, use_location, use_scope from reactpy.backend.utils import run from reactpy.core import hooks from reactpy.core.component import component @@ -7,12 +6,15 @@ from reactpy.core.hooks import ( create_context, use_callback, + use_connection, use_context, use_debug_value, use_effect, + use_location, use_memo, use_reducer, use_ref, + use_scope, use_state, ) from reactpy.core.layout import Layout diff --git a/src/py/reactpy/reactpy/backend/flask.py b/src/py/reactpy/reactpy/backend/flask.py index faa979aa9..c8bf520d9 100644 --- a/src/py/reactpy/reactpy/backend/flask.py +++ b/src/py/reactpy/reactpy/backend/flask.py @@ -35,8 +35,8 @@ safe_client_build_dir_path, safe_web_modules_dir_path, ) -from reactpy.backend.hooks import ConnectionContext -from reactpy.backend.hooks import use_connection as _use_connection +from reactpy.core.hooks import ConnectionContext +from reactpy.core.hooks import use_connection as _use_connection from reactpy.backend.types import Connection, Location from reactpy.core.serve import serve_layout from reactpy.core.types import ComponentType, RootComponentConstructor @@ -70,7 +70,8 @@ def configure( """ options = options or Options() - api_bp = Blueprint(f"reactpy_api_{id(app)}", __name__, url_prefix=str(PATH_PREFIX)) + api_bp = Blueprint(f"reactpy_api_{id(app)}", + __name__, url_prefix=str(PATH_PREFIX)) spa_bp = Blueprint( f"reactpy_spa_{id(app)}", __name__, url_prefix=options.url_prefix ) @@ -192,14 +193,15 @@ def recv() -> Any: _dispatch_in_thread( ws, # remove any url prefix from path - path[len(options.url_prefix) :], + path[len(options.url_prefix):], constructor(), send, recv, ) sock.route(STREAM_PATH.name, endpoint="without_path")(model_stream) - sock.route(f"{STREAM_PATH.name}/", endpoint="with_path")(model_stream) + sock.route(f"{STREAM_PATH.name}/", + endpoint="with_path")(model_stream) def _dispatch_in_thread( @@ -260,7 +262,8 @@ async def main() -> None: Thread(target=run_dispatcher, daemon=True).start() dispatch_thread_info_created.wait() - dispatch_thread_info = cast(_DispatcherThreadInfo, dispatch_thread_info_ref.current) + dispatch_thread_info = cast( + _DispatcherThreadInfo, dispatch_thread_info_ref.current) if dispatch_thread_info is None: raise RuntimeError("Failed to create dispatcher thread") # nocov diff --git a/src/py/reactpy/reactpy/backend/hooks.py b/src/py/reactpy/reactpy/backend/hooks.py deleted file mode 100644 index ee4ce1b5c..000000000 --- a/src/py/reactpy/reactpy/backend/hooks.py +++ /dev/null @@ -1,30 +0,0 @@ -from __future__ import annotations - -from collections.abc import MutableMapping -from typing import Any - -from reactpy.backend.types import Connection, Location -from reactpy.core.hooks import create_context, use_context -from reactpy.core.types import Context - -# backend implementations should establish this context at the root of an app -ConnectionContext: Context[Connection[Any] | None] = create_context(None) - - -def use_connection() -> Connection[Any]: - """Get the current :class:`~reactpy.backend.types.Connection`.""" - conn = use_context(ConnectionContext) - if conn is None: # nocov - msg = "No backend established a connection." - raise RuntimeError(msg) - return conn - - -def use_scope() -> MutableMapping[str, Any]: - """Get the current :class:`~reactpy.backend.types.Connection`'s scope.""" - return use_connection().scope - - -def use_location() -> Location: - """Get the current :class:`~reactpy.backend.types.Connection`'s location.""" - return use_connection().location diff --git a/src/py/reactpy/reactpy/backend/sanic.py b/src/py/reactpy/reactpy/backend/sanic.py index 76eb0423e..531e0776e 100644 --- a/src/py/reactpy/reactpy/backend/sanic.py +++ b/src/py/reactpy/reactpy/backend/sanic.py @@ -24,8 +24,8 @@ safe_web_modules_dir_path, serve_with_uvicorn, ) -from reactpy.backend.hooks import ConnectionContext -from reactpy.backend.hooks import use_connection as _use_connection +from reactpy.core.hooks import ConnectionContext +from reactpy.core.hooks import use_connection as _use_connection from reactpy.backend.types import Connection, Location from reactpy.core.layout import Layout from reactpy.core.serve import RecvCoroutine, SendCoroutine, Stop, serve_layout diff --git a/src/py/reactpy/reactpy/backend/starlette.py b/src/py/reactpy/reactpy/backend/starlette.py index 9bc68db47..6f14899c7 100644 --- a/src/py/reactpy/reactpy/backend/starlette.py +++ b/src/py/reactpy/reactpy/backend/starlette.py @@ -24,8 +24,8 @@ read_client_index_html, serve_with_uvicorn, ) -from reactpy.backend.hooks import ConnectionContext -from reactpy.backend.hooks import use_connection as _use_connection +from reactpy.core.hooks import ConnectionContext +from reactpy.core.hooks import use_connection as _use_connection from reactpy.backend.types import Connection, Location from reactpy.config import REACTPY_WEB_MODULES_DIR from reactpy.core.layout import Layout diff --git a/src/py/reactpy/reactpy/backend/tornado.py b/src/py/reactpy/reactpy/backend/tornado.py index 8f540ddb4..26612e7af 100644 --- a/src/py/reactpy/reactpy/backend/tornado.py +++ b/src/py/reactpy/reactpy/backend/tornado.py @@ -24,8 +24,8 @@ CommonOptions, read_client_index_html, ) -from reactpy.backend.hooks import ConnectionContext -from reactpy.backend.hooks import use_connection as _use_connection +from reactpy.core.hooks import ConnectionContext +from reactpy.core.hooks import use_connection as _use_connection from reactpy.backend.types import Connection, Location from reactpy.config import REACTPY_WEB_MODULES_DIR from reactpy.core.layout import Layout diff --git a/src/py/reactpy/reactpy/core/hooks.py b/src/py/reactpy/reactpy/core/hooks.py index 640cbf14c..84339a673 100644 --- a/src/py/reactpy/reactpy/core/hooks.py +++ b/src/py/reactpy/reactpy/core/hooks.py @@ -1,4 +1,6 @@ from __future__ import annotations +from collections.abc import MutableMapping +from reactpy.backend.types import Connection, Location import asyncio from collections.abc import Coroutine, Sequence @@ -227,6 +229,19 @@ def context( return context +# backend implementations should establish this context at the root of an app +ConnectionContext: Context[Connection[Any] | None] = create_context(None) + + +def use_connection() -> Connection[Any]: + """Get the current :class:`~reactpy.backend.types.Connection`.""" + conn = use_context(ConnectionContext) + if conn is None: # nocov + msg = "No backend established a connection." + raise RuntimeError(msg) + return conn + + def use_context(context: Context[_Type]) -> _Type: """Get the current value for the given context type. @@ -248,6 +263,16 @@ def use_context(context: Context[_Type]) -> _Type: return provider.value +def use_scope() -> MutableMapping[str, Any]: + """Get the current :class:`~reactpy.backend.types.Connection`'s scope.""" + return use_connection().scope + + +def use_location() -> Location: + """Get the current :class:`~reactpy.backend.types.Connection`'s location.""" + return use_connection().location + + class _ContextProvider(Generic[_Type]): def __init__( self, From 36ca352955fcb693b5c2bf8c717112f7eb428ed0 Mon Sep 17 00:00:00 2001 From: Josh Birlingmair Date: Thu, 7 Mar 2024 00:42:27 -0600 Subject: [PATCH 02/13] Add 'reactpy.backend.hooks -> reactpy.core.hooks' move to changelog --- docs/source/about/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/about/changelog.rst b/docs/source/about/changelog.rst index b2297c20c..ded722bca 100644 --- a/docs/source/about/changelog.rst +++ b/docs/source/about/changelog.rst @@ -40,6 +40,7 @@ Unreleased fragment to conditionally render an element by writing ``something if condition else html._()``. Now you can simply write ``something if condition else None``. +- :pull:`1210` - Move hooks in `reactpy.backend.core` into `reactpy.core.hooks`. **Deprecated** From 942ad6a167155a9c15e6d94b3eab7835de577514 Mon Sep 17 00:00:00 2001 From: Josh Birlingmair Date: Fri, 8 Mar 2024 18:40:56 -0600 Subject: [PATCH 03/13] Move use_connection to sit next to functions that use them --- src/py/reactpy/reactpy/core/hooks.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/py/reactpy/reactpy/core/hooks.py b/src/py/reactpy/reactpy/core/hooks.py index 84339a673..f4ed0e547 100644 --- a/src/py/reactpy/reactpy/core/hooks.py +++ b/src/py/reactpy/reactpy/core/hooks.py @@ -229,19 +229,6 @@ def context( return context -# backend implementations should establish this context at the root of an app -ConnectionContext: Context[Connection[Any] | None] = create_context(None) - - -def use_connection() -> Connection[Any]: - """Get the current :class:`~reactpy.backend.types.Connection`.""" - conn = use_context(ConnectionContext) - if conn is None: # nocov - msg = "No backend established a connection." - raise RuntimeError(msg) - return conn - - def use_context(context: Context[_Type]) -> _Type: """Get the current value for the given context type. @@ -263,6 +250,19 @@ def use_context(context: Context[_Type]) -> _Type: return provider.value +# backend implementations should establish this context at the root of an app +ConnectionContext: Context[Connection[Any] | None] = create_context(None) + + +def use_connection() -> Connection[Any]: + """Get the current :class:`~reactpy.backend.types.Connection`.""" + conn = use_context(ConnectionContext) + if conn is None: # nocov + msg = "No backend established a connection." + raise RuntimeError(msg) + return conn + + def use_scope() -> MutableMapping[str, Any]: """Get the current :class:`~reactpy.backend.types.Connection`'s scope.""" return use_connection().scope From 4f5b780364411b131adf0cf24433e9cda9a01c47 Mon Sep 17 00:00:00 2001 From: Josh Birlingmair Date: Fri, 8 Mar 2024 19:05:27 -0600 Subject: [PATCH 04/13] Re-add 'reactpy.backend.hooks' with deprecation warnings --- src/py/reactpy/reactpy/backend/hooks.py | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/py/reactpy/reactpy/backend/hooks.py diff --git a/src/py/reactpy/reactpy/backend/hooks.py b/src/py/reactpy/reactpy/backend/hooks.py new file mode 100644 index 000000000..16537fa39 --- /dev/null +++ b/src/py/reactpy/reactpy/backend/hooks.py @@ -0,0 +1,36 @@ +from __future__ import annotations + +from collections.abc import MutableMapping +from typing import Any + +from reactpy._warnings import warn +from reactpy.backend.types import Connection, Location +from reactpy.core.hooks import ConnectionContext, use_context + + +def use_connection() -> Connection[Any]: + """Get the current :class:`~reactpy.backend.types.Connection`.""" + warn("The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", + "Call use_connection in reactpy.core.hooks instead.", DeprecationWarning) + + conn = use_context(ConnectionContext) + if conn is None: # nocov + msg = "No backend established a connection." + raise RuntimeError(msg) + return conn + + +def use_scope() -> MutableMapping[str, Any]: + """Get the current :class:`~reactpy.backend.types.Connection`'s scope.""" + warn("The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", + "Call use_scope in reactpy.core.hooks instead.", DeprecationWarning) + + return use_connection().scope + + +def use_location() -> Location: + """Get the current :class:`~reactpy.backend.types.Connection`'s location.""" + warn("The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", + "Call use_location in reactpy.core.hooks instead.", DeprecationWarning) + + return use_connection().location From 908206c9ff54dd01104ec9e8668e0556cca117da Mon Sep 17 00:00:00 2001 From: Josh Birlingmair Date: Fri, 8 Mar 2024 19:14:35 -0600 Subject: [PATCH 05/13] Add reactpy.backend.hooks deprecation in changelog, and fix mistakes --- docs/source/about/changelog.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/about/changelog.rst b/docs/source/about/changelog.rst index ded722bca..536229e18 100644 --- a/docs/source/about/changelog.rst +++ b/docs/source/about/changelog.rst @@ -40,13 +40,15 @@ Unreleased fragment to conditionally render an element by writing ``something if condition else html._()``. Now you can simply write ``something if condition else None``. -- :pull:`1210` - Move hooks in `reactpy.backend.core` into `reactpy.core.hooks`. +- :pull:`1210` - Move hooks from `reactpy.backend.hooks` into `reactpy.core.hooks`. **Deprecated** - :pull:`1171` - The ``Stop`` exception. Recent releases of ``anyio`` have made this exception difficult to use since it now raises an ``ExceptionGroup``. This exception was primarily used for internal testing purposes and so is now deprecated. +- :pull:`1210` - Deprecate `reactpy.backend.hooks` since the hooks have been moved into + `reactpy.core.hooks`. v1.0.2 From f503824f30988d3b25abdb70f01fd3122a591729 Mon Sep 17 00:00:00 2001 From: Josh Birlingmair Date: Fri, 8 Mar 2024 19:19:24 -0600 Subject: [PATCH 06/13] Add formatting to module names --- docs/source/about/changelog.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/about/changelog.rst b/docs/source/about/changelog.rst index 536229e18..a1355a62c 100644 --- a/docs/source/about/changelog.rst +++ b/docs/source/about/changelog.rst @@ -40,15 +40,15 @@ Unreleased fragment to conditionally render an element by writing ``something if condition else html._()``. Now you can simply write ``something if condition else None``. -- :pull:`1210` - Move hooks from `reactpy.backend.hooks` into `reactpy.core.hooks`. +- :pull:`1210` - Move hooks from ``reactpy.backend.hooks`` into ``reactpy.core.hooks``. **Deprecated** - :pull:`1171` - The ``Stop`` exception. Recent releases of ``anyio`` have made this exception difficult to use since it now raises an ``ExceptionGroup``. This exception was primarily used for internal testing purposes and so is now deprecated. -- :pull:`1210` - Deprecate `reactpy.backend.hooks` since the hooks have been moved into - `reactpy.core.hooks`. +- :pull:`1210` - Deprecate ``reactpy.backend.hooks`` since the hooks have been moved into + ``reactpy.core.hooks``. v1.0.2 From 51cd038bf78532ca93687f04c6ff505f2d9fe9a4 Mon Sep 17 00:00:00 2001 From: Josh Birlingmair Date: Wed, 13 Mar 2024 19:07:15 -0500 Subject: [PATCH 07/13] Fix formatting --- src/py/reactpy/reactpy/backend/flask.py | 13 +++++-------- src/py/reactpy/reactpy/backend/hooks.py | 21 +++++++++++++++------ src/py/reactpy/reactpy/backend/sanic.py | 2 +- src/py/reactpy/reactpy/backend/starlette.py | 4 ++-- src/py/reactpy/reactpy/backend/tornado.py | 4 ++-- src/py/reactpy/reactpy/core/hooks.py | 5 ++--- 6 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/py/reactpy/reactpy/backend/flask.py b/src/py/reactpy/reactpy/backend/flask.py index c8bf520d9..4401fb6f7 100644 --- a/src/py/reactpy/reactpy/backend/flask.py +++ b/src/py/reactpy/reactpy/backend/flask.py @@ -35,9 +35,9 @@ safe_client_build_dir_path, safe_web_modules_dir_path, ) +from reactpy.backend.types import Connection, Location from reactpy.core.hooks import ConnectionContext from reactpy.core.hooks import use_connection as _use_connection -from reactpy.backend.types import Connection, Location from reactpy.core.serve import serve_layout from reactpy.core.types import ComponentType, RootComponentConstructor from reactpy.utils import Ref @@ -70,8 +70,7 @@ def configure( """ options = options or Options() - api_bp = Blueprint(f"reactpy_api_{id(app)}", - __name__, url_prefix=str(PATH_PREFIX)) + api_bp = Blueprint(f"reactpy_api_{id(app)}", __name__, url_prefix=str(PATH_PREFIX)) spa_bp = Blueprint( f"reactpy_spa_{id(app)}", __name__, url_prefix=options.url_prefix ) @@ -193,15 +192,14 @@ def recv() -> Any: _dispatch_in_thread( ws, # remove any url prefix from path - path[len(options.url_prefix):], + path[len(options.url_prefix) :], constructor(), send, recv, ) sock.route(STREAM_PATH.name, endpoint="without_path")(model_stream) - sock.route(f"{STREAM_PATH.name}/", - endpoint="with_path")(model_stream) + sock.route(f"{STREAM_PATH.name}/", endpoint="with_path")(model_stream) def _dispatch_in_thread( @@ -262,8 +260,7 @@ async def main() -> None: Thread(target=run_dispatcher, daemon=True).start() dispatch_thread_info_created.wait() - dispatch_thread_info = cast( - _DispatcherThreadInfo, dispatch_thread_info_ref.current) + dispatch_thread_info = cast(_DispatcherThreadInfo, dispatch_thread_info_ref.current) if dispatch_thread_info is None: raise RuntimeError("Failed to create dispatcher thread") # nocov diff --git a/src/py/reactpy/reactpy/backend/hooks.py b/src/py/reactpy/reactpy/backend/hooks.py index 16537fa39..3a642c77e 100644 --- a/src/py/reactpy/reactpy/backend/hooks.py +++ b/src/py/reactpy/reactpy/backend/hooks.py @@ -10,8 +10,11 @@ def use_connection() -> Connection[Any]: """Get the current :class:`~reactpy.backend.types.Connection`.""" - warn("The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", - "Call use_connection in reactpy.core.hooks instead.", DeprecationWarning) + warn( + "The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", + "Call use_connection in reactpy.core.hooks instead.", + DeprecationWarning, + ) conn = use_context(ConnectionContext) if conn is None: # nocov @@ -22,15 +25,21 @@ def use_connection() -> Connection[Any]: def use_scope() -> MutableMapping[str, Any]: """Get the current :class:`~reactpy.backend.types.Connection`'s scope.""" - warn("The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", - "Call use_scope in reactpy.core.hooks instead.", DeprecationWarning) + warn( + "The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", + "Call use_scope in reactpy.core.hooks instead.", + DeprecationWarning, + ) return use_connection().scope def use_location() -> Location: """Get the current :class:`~reactpy.backend.types.Connection`'s location.""" - warn("The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", - "Call use_location in reactpy.core.hooks instead.", DeprecationWarning) + warn( + "The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", + "Call use_location in reactpy.core.hooks instead.", + DeprecationWarning, + ) return use_connection().location diff --git a/src/py/reactpy/reactpy/backend/sanic.py b/src/py/reactpy/reactpy/backend/sanic.py index 531e0776e..d272fb4cf 100644 --- a/src/py/reactpy/reactpy/backend/sanic.py +++ b/src/py/reactpy/reactpy/backend/sanic.py @@ -24,9 +24,9 @@ safe_web_modules_dir_path, serve_with_uvicorn, ) +from reactpy.backend.types import Connection, Location from reactpy.core.hooks import ConnectionContext from reactpy.core.hooks import use_connection as _use_connection -from reactpy.backend.types import Connection, Location from reactpy.core.layout import Layout from reactpy.core.serve import RecvCoroutine, SendCoroutine, Stop, serve_layout from reactpy.core.types import RootComponentConstructor diff --git a/src/py/reactpy/reactpy/backend/starlette.py b/src/py/reactpy/reactpy/backend/starlette.py index 6f14899c7..20e2b4478 100644 --- a/src/py/reactpy/reactpy/backend/starlette.py +++ b/src/py/reactpy/reactpy/backend/starlette.py @@ -24,10 +24,10 @@ read_client_index_html, serve_with_uvicorn, ) -from reactpy.core.hooks import ConnectionContext -from reactpy.core.hooks import use_connection as _use_connection from reactpy.backend.types import Connection, Location from reactpy.config import REACTPY_WEB_MODULES_DIR +from reactpy.core.hooks import ConnectionContext +from reactpy.core.hooks import use_connection as _use_connection from reactpy.core.layout import Layout from reactpy.core.serve import RecvCoroutine, SendCoroutine, serve_layout from reactpy.core.types import RootComponentConstructor diff --git a/src/py/reactpy/reactpy/backend/tornado.py b/src/py/reactpy/reactpy/backend/tornado.py index 26612e7af..bd339c5b9 100644 --- a/src/py/reactpy/reactpy/backend/tornado.py +++ b/src/py/reactpy/reactpy/backend/tornado.py @@ -24,10 +24,10 @@ CommonOptions, read_client_index_html, ) -from reactpy.core.hooks import ConnectionContext -from reactpy.core.hooks import use_connection as _use_connection from reactpy.backend.types import Connection, Location from reactpy.config import REACTPY_WEB_MODULES_DIR +from reactpy.core.hooks import ConnectionContext +from reactpy.core.hooks import use_connection as _use_connection from reactpy.core.layout import Layout from reactpy.core.serve import serve_layout from reactpy.core.types import ComponentConstructor diff --git a/src/py/reactpy/reactpy/core/hooks.py b/src/py/reactpy/reactpy/core/hooks.py index f4ed0e547..0ece8cccf 100644 --- a/src/py/reactpy/reactpy/core/hooks.py +++ b/src/py/reactpy/reactpy/core/hooks.py @@ -1,9 +1,7 @@ from __future__ import annotations -from collections.abc import MutableMapping -from reactpy.backend.types import Connection, Location import asyncio -from collections.abc import Coroutine, Sequence +from collections.abc import Coroutine, MutableMapping, Sequence from logging import getLogger from types import FunctionType from typing import ( @@ -19,6 +17,7 @@ from typing_extensions import TypeAlias +from reactpy.backend.types import Connection, Location from reactpy.config import REACTPY_DEBUG_MODE from reactpy.core._life_cycle_hook import current_hook from reactpy.core.types import Context, Key, State, VdomDict From 8967f7f15041c8d35c3ae42cce8b1dc4e5f95a69 Mon Sep 17 00:00:00 2001 From: Josh Birlingmair Date: Wed, 13 Mar 2024 20:21:15 -0500 Subject: [PATCH 08/13] Add nocov comments to backend.hooks --- src/py/reactpy/reactpy/backend/hooks.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/py/reactpy/reactpy/backend/hooks.py b/src/py/reactpy/reactpy/backend/hooks.py index 3a642c77e..de911c752 100644 --- a/src/py/reactpy/reactpy/backend/hooks.py +++ b/src/py/reactpy/reactpy/backend/hooks.py @@ -1,14 +1,14 @@ -from __future__ import annotations +from __future__ import annotations # nocov -from collections.abc import MutableMapping -from typing import Any +from collections.abc import MutableMapping # nocov +from typing import Any # nocov -from reactpy._warnings import warn -from reactpy.backend.types import Connection, Location -from reactpy.core.hooks import ConnectionContext, use_context +from reactpy._warnings import warn # nocov +from reactpy.backend.types import Connection, Location # nocov +from reactpy.core.hooks import ConnectionContext, use_context # nocov -def use_connection() -> Connection[Any]: +def use_connection() -> Connection[Any]: # nocov """Get the current :class:`~reactpy.backend.types.Connection`.""" warn( "The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", @@ -17,13 +17,13 @@ def use_connection() -> Connection[Any]: ) conn = use_context(ConnectionContext) - if conn is None: # nocov + if conn is None: msg = "No backend established a connection." raise RuntimeError(msg) return conn -def use_scope() -> MutableMapping[str, Any]: +def use_scope() -> MutableMapping[str, Any]: # nocov """Get the current :class:`~reactpy.backend.types.Connection`'s scope.""" warn( "The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", @@ -34,7 +34,7 @@ def use_scope() -> MutableMapping[str, Any]: return use_connection().scope -def use_location() -> Location: +def use_location() -> Location: # nocov """Get the current :class:`~reactpy.backend.types.Connection`'s location.""" warn( "The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", From 8b071a56d8c8cf8e215d997f1dd75053037e10fe Mon Sep 17 00:00:00 2001 From: Josh Birlingmair Date: Thu, 14 Mar 2024 17:58:39 -0500 Subject: [PATCH 09/13] Fix deprecation warning messages --- src/py/reactpy/reactpy/backend/hooks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/py/reactpy/reactpy/backend/hooks.py b/src/py/reactpy/reactpy/backend/hooks.py index de911c752..ef1b4a5cb 100644 --- a/src/py/reactpy/reactpy/backend/hooks.py +++ b/src/py/reactpy/reactpy/backend/hooks.py @@ -12,7 +12,7 @@ def use_connection() -> Connection[Any]: # nocov """Get the current :class:`~reactpy.backend.types.Connection`.""" warn( "The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", - "Call use_connection in reactpy.core.hooks instead.", + "Call reactpy.use_connection instead.", DeprecationWarning, ) @@ -27,7 +27,7 @@ def use_scope() -> MutableMapping[str, Any]: # nocov """Get the current :class:`~reactpy.backend.types.Connection`'s scope.""" warn( "The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", - "Call use_scope in reactpy.core.hooks instead.", + "Call reactpy.use_scope instead.", DeprecationWarning, ) @@ -38,7 +38,7 @@ def use_location() -> Location: # nocov """Get the current :class:`~reactpy.backend.types.Connection`'s location.""" warn( "The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", - "Call use_location in reactpy.core.hooks instead.", + "Call reactpy.use_location instead.", DeprecationWarning, ) From 45d377083eeb6bd13e2ee8a779c84111e8d3ff12 Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 28 Oct 2024 16:24:28 -0700 Subject: [PATCH 10/13] Pin mypy to v1.8 --- src/py/reactpy/pyproject.toml | 56 ++++++++--------------------------- 1 file changed, 13 insertions(+), 43 deletions(-) diff --git a/src/py/reactpy/pyproject.toml b/src/py/reactpy/pyproject.toml index 309248507..e5a2559b7 100644 --- a/src/py/reactpy/pyproject.toml +++ b/src/py/reactpy/pyproject.toml @@ -12,9 +12,7 @@ readme = "README.md" requires-python = ">=3.9" license = "MIT" keywords = ["react", "javascript", "reactpy", "component"] -authors = [ - { name = "Ryan Morshead", email = "ryan.morshead@gmail.com" }, -] +authors = [{ name = "Ryan Morshead", email = "ryan.morshead@gmail.com" }] classifiers = [ "Development Status :: 4 - Beta", "Programming Language :: Python", @@ -39,10 +37,7 @@ dependencies = [ [project.optional-dependencies] all = ["reactpy[starlette,sanic,fastapi,flask,tornado,testing]"] -starlette = [ - "starlette >=0.13.6", - "uvicorn[standard] >=0.19.0", -] +starlette = ["starlette >=0.13.6", "uvicorn[standard] >=0.19.0"] sanic = [ "sanic >=21", "sanic-cors", @@ -50,22 +45,10 @@ sanic = [ "setuptools", "uvicorn[standard] >=0.19.0", ] -fastapi = [ - "fastapi >=0.63.0", - "uvicorn[standard] >=0.19.0", -] -flask = [ - "flask", - "markupsafe>=1.1.1,<2.1", - "flask-cors", - "flask-sock", -] -tornado = [ - "tornado", -] -testing = [ - "playwright", -] +fastapi = ["fastapi >=0.63.0", "uvicorn[standard] >=0.19.0"] +flask = ["flask", "markupsafe>=1.1.1,<2.1", "flask-cors", "flask-sock"] +tornado = ["tornado"] +testing = ["playwright"] [project.urls] Source = "https://github.com/reactive-python/reactpy" @@ -101,21 +84,17 @@ cov-report = [ # "- coverage combine", "coverage report", ] -cov = [ - "test-cov {args}", - "cov-report", -] +cov = ["test-cov {args}", "cov-report"] [tool.hatch.envs.default.env-vars] -REACTPY_DEBUG_MODE="1" +REACTPY_DEBUG_MODE = "1" [tool.hatch.envs.lint] features = ["all"] dependencies = [ - "mypy>=1.0.0", + "mypy==1.8", "types-click", "types-tornado", - "types-pkg-resources", "types-flask", "types-requests", ] @@ -127,13 +106,8 @@ all = ["types"] [[tool.hatch.build.hooks.build-scripts.scripts]] work_dir = "../../js" out_dir = "reactpy/_static" -commands = [ - "npm ci", - "npm run build" -] -artifacts = [ - "app/dist/" -] +commands = ["npm ci", "npm run build"] +artifacts = ["app/dist/"] # --- Pytest --------------------------------------------------------------------------- @@ -159,9 +133,7 @@ warn_unused_ignores = true source_pkgs = ["reactpy"] branch = false parallel = false -omit = [ - "reactpy/__init__.py", -] +omit = ["reactpy/__init__.py"] [tool.coverage.report] fail_under = 100 @@ -174,6 +146,4 @@ exclude_lines = [ "if __name__ == .__main__.:", "if TYPE_CHECKING:", ] -omit = [ - "reactpy/__main__.py", -] +omit = ["reactpy/__main__.py"] From 27a06a89b6f20e4eb79e956acfc7c147d8e78f36 Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 28 Oct 2024 16:31:23 -0700 Subject: [PATCH 11/13] conditional pkg_resources --- src/py/reactpy/pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/py/reactpy/pyproject.toml b/src/py/reactpy/pyproject.toml index e5a2559b7..7f4139fe2 100644 --- a/src/py/reactpy/pyproject.toml +++ b/src/py/reactpy/pyproject.toml @@ -96,6 +96,7 @@ dependencies = [ "types-click", "types-tornado", "types-flask", + "pkg_resources; sys_platform != 'win32'", "types-requests", ] From fea5e232f3897fd1be1c474e2956d4cc5f4e86a5 Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 28 Oct 2024 16:34:01 -0700 Subject: [PATCH 12/13] Remove reactpy-flake8 --- pyproject.toml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 775ab01a2..1745a3dfe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,12 +12,11 @@ detached = true dependencies = [ "invoke", # lint - "black==24.1.1", # Pin lint tools we don't control to avoid breaking changes - "ruff==0.0.278", # Pin lint tools we don't control to avoid breaking changes + "black==24.1.1", # Pin lint tools we don't control to avoid breaking changes + "ruff==0.0.278", # Pin lint tools we don't control to avoid breaking changes "toml", - "flake8==7.0.0", # Pin lint tools we don't control to avoid breaking changes + "flake8==7.0.0", # Pin lint tools we don't control to avoid breaking changes "flake8-pyproject", - "reactpy-flake8 >=0.7", # types "mypy", "types-toml", From a9ba5db43d4f518e0f531c303848e0bba07e1b5c Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:22:23 -0700 Subject: [PATCH 13/13] Revert --- pyproject.toml | 7 ++++--- src/py/reactpy/pyproject.toml | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1745a3dfe..775ab01a2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,11 +12,12 @@ detached = true dependencies = [ "invoke", # lint - "black==24.1.1", # Pin lint tools we don't control to avoid breaking changes - "ruff==0.0.278", # Pin lint tools we don't control to avoid breaking changes + "black==24.1.1", # Pin lint tools we don't control to avoid breaking changes + "ruff==0.0.278", # Pin lint tools we don't control to avoid breaking changes "toml", - "flake8==7.0.0", # Pin lint tools we don't control to avoid breaking changes + "flake8==7.0.0", # Pin lint tools we don't control to avoid breaking changes "flake8-pyproject", + "reactpy-flake8 >=0.7", # types "mypy", "types-toml", diff --git a/src/py/reactpy/pyproject.toml b/src/py/reactpy/pyproject.toml index 7f4139fe2..584a28792 100644 --- a/src/py/reactpy/pyproject.toml +++ b/src/py/reactpy/pyproject.toml @@ -92,11 +92,11 @@ REACTPY_DEBUG_MODE = "1" [tool.hatch.envs.lint] features = ["all"] dependencies = [ - "mypy==1.8", + "mypy>=1.0.0", "types-click", "types-tornado", + "types-pkg-resources", "types-flask", - "pkg_resources; sys_platform != 'win32'", "types-requests", ]