Skip to content

Commit b10be18

Browse files
authored
Merge branch 'main' into main
2 parents bf7236f + f70bccd commit b10be18

File tree

12 files changed

+105
-66
lines changed

12 files changed

+105
-66
lines changed

.github/workflows/.hatch-run.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ jobs:
3838
runs-on: ${{ fromJson(inputs.runs-on-array) }}
3939
runs-on: ${{ matrix.runs-on }}
4040
steps:
41-
- uses: actions/checkout@v2
42-
- uses: actions/setup-node@v2
41+
- uses: actions/checkout@v4
42+
- uses: actions/setup-node@v4
4343
with:
4444
node-version: "23.x"
4545
registry-url: ${{ inputs.node-registry-url }}
4646
- name: Pin NPM Version
4747
run: npm install -g [email protected]
4848
- name: Use Python ${{ matrix.python-version }}
49-
uses: actions/setup-python@v2
49+
uses: actions/setup-python@v5
5050
with:
5151
python-version: ${{ matrix.python-version }}
5252
- name: Install Python Dependencies

.github/workflows/deploy-docs.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44
name: deploy-docs
55

66
on:
7-
push:
8-
branches:
9-
- "main"
10-
tags:
11-
- "*"
7+
push:
8+
branches:
9+
- "main"
10+
tags:
11+
- "*"
1212

1313
jobs:
14-
deploy-documentation:
15-
runs-on: ubuntu-latest
16-
steps:
17-
- name: Check out src from Git
18-
uses: actions/checkout@v2
19-
- name: Get history and tags for SCM versioning to work
20-
run: |
21-
git fetch --prune --unshallow
22-
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
23-
- name: Login to Heroku Container Registry
24-
run: echo ${{ secrets.HEROKU_API_KEY }} | docker login -u ${{ secrets.HEROKU_EMAIL }} --password-stdin registry.heroku.com
25-
- name: Build Docker Image
26-
run: docker build . --file docs/Dockerfile --tag registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/web
27-
- name: Push Docker Image
28-
run: docker push registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/web
29-
- name: Deploy
30-
run: HEROKU_API_KEY=${{ secrets.HEROKU_API_KEY }} heroku container:release web --app ${{ secrets.HEROKU_APP_NAME }}
14+
deploy-documentation:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Check out src from Git
18+
uses: actions/checkout@v4
19+
- name: Get history and tags for SCM versioning to work
20+
run: |
21+
git fetch --prune --unshallow
22+
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
23+
- name: Login to Heroku Container Registry
24+
run: echo ${{ secrets.HEROKU_API_KEY }} | docker login -u ${{ secrets.HEROKU_EMAIL }} --password-stdin registry.heroku.com
25+
- name: Build Docker Image
26+
run: docker build . --file docs/Dockerfile --tag registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/web
27+
- name: Push Docker Image
28+
run: docker push registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/web
29+
- name: Deploy
30+
run: HEROKU_API_KEY=${{ secrets.HEROKU_API_KEY }} heroku container:release web --app ${{ secrets.HEROKU_APP_NAME }}

.github/workflows/publish.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
name: publish
55

66
on:
7-
release:
8-
types: [published]
7+
release:
8+
types: [published]
99

1010
jobs:
11-
publish:
12-
uses: ./.github/workflows/.hatch-run.yml
13-
with:
14-
job-name: "publish"
15-
hatch-run: "publish"
16-
node-registry-url: "https://registry.npmjs.org"
17-
secrets:
18-
node-auth-token: ${{ secrets.NODE_AUTH_TOKEN }}
19-
pypi-username: ${{ secrets.PYPI_USERNAME }}
20-
pypi-password: ${{ secrets.PYPI_PASSWORD }}
11+
publish:
12+
uses: ./.github/workflows/.hatch-run.yml
13+
with:
14+
job-name: "publish"
15+
hatch-run: "publish"
16+
node-registry-url: "https://registry.npmjs.org"
17+
secrets:
18+
node-auth-token: ${{ secrets.NODE_AUTH_TOKEN }}
19+
pypi-username: ${{ secrets.PYPI_USERNAME }}
20+
pypi-password: ${{ secrets.PYPI_PASSWORD }}

docs/source/about/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,15 @@ Unreleased
4040
fragment to conditionally render an element by writing
4141
``something if condition else html._()``. Now you can simply write
4242
``something if condition else None``.
43+
- :pull:`1210` - Move hooks from ``reactpy.backend.hooks`` into ``reactpy.core.hooks``.
4344

4445
**Deprecated**
4546

4647
- :pull:`1171` - The ``Stop`` exception. Recent releases of ``anyio`` have made this
4748
exception difficult to use since it now raises an ``ExceptionGroup``. This exception
4849
was primarily used for internal testing purposes and so is now deprecated.
50+
- :pull:`1210` - Deprecate ``reactpy.backend.hooks`` since the hooks have been moved into
51+
``reactpy.core.hooks``.
4952

5053

5154
v1.0.2

src/py/reactpy/reactpy/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
from reactpy import backend, config, html, logging, sample, svg, types, web, widgets
2-
from reactpy.backend.hooks import use_connection, use_location, use_scope
32
from reactpy.backend.utils import run
43
from reactpy.core import hooks
54
from reactpy.core.component import component
65
from reactpy.core.events import event
76
from reactpy.core.hooks import (
87
create_context,
98
use_callback,
9+
use_connection,
1010
use_context,
1111
use_debug_value,
1212
use_effect,
13+
use_location,
1314
use_memo,
1415
use_reducer,
1516
use_ref,
17+
use_scope,
1618
use_state,
1719
)
1820
from reactpy.core.layout import Layout

src/py/reactpy/reactpy/backend/flask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
safe_client_build_dir_path,
3636
safe_web_modules_dir_path,
3737
)
38-
from reactpy.backend.hooks import ConnectionContext
39-
from reactpy.backend.hooks import use_connection as _use_connection
4038
from reactpy.backend.types import Connection, Location
39+
from reactpy.core.hooks import ConnectionContext
40+
from reactpy.core.hooks import use_connection as _use_connection
4141
from reactpy.core.serve import serve_layout
4242
from reactpy.core.types import ComponentType, RootComponentConstructor
4343
from reactpy.utils import Ref
Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,45 @@
1-
from __future__ import annotations
1+
from __future__ import annotations # nocov
22

3-
from collections.abc import MutableMapping
4-
from typing import Any
3+
from collections.abc import MutableMapping # nocov
4+
from typing import Any # nocov
55

6-
from reactpy.backend.types import Connection, Location
7-
from reactpy.core.hooks import create_context, use_context
8-
from reactpy.core.types import Context
6+
from reactpy._warnings import warn # nocov
7+
from reactpy.backend.types import Connection, Location # nocov
8+
from reactpy.core.hooks import ConnectionContext, use_context # nocov
99

10-
# backend implementations should establish this context at the root of an app
11-
ConnectionContext: Context[Connection[Any] | None] = create_context(None)
1210

13-
14-
def use_connection() -> Connection[Any]:
11+
def use_connection() -> Connection[Any]: # nocov
1512
"""Get the current :class:`~reactpy.backend.types.Connection`."""
13+
warn(
14+
"The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ",
15+
"Call reactpy.use_connection instead.",
16+
DeprecationWarning,
17+
)
18+
1619
conn = use_context(ConnectionContext)
17-
if conn is None: # nocov
20+
if conn is None:
1821
msg = "No backend established a connection."
1922
raise RuntimeError(msg)
2023
return conn
2124

2225

23-
def use_scope() -> MutableMapping[str, Any]:
26+
def use_scope() -> MutableMapping[str, Any]: # nocov
2427
"""Get the current :class:`~reactpy.backend.types.Connection`'s scope."""
28+
warn(
29+
"The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ",
30+
"Call reactpy.use_scope instead.",
31+
DeprecationWarning,
32+
)
33+
2534
return use_connection().scope
2635

2736

28-
def use_location() -> Location:
37+
def use_location() -> Location: # nocov
2938
"""Get the current :class:`~reactpy.backend.types.Connection`'s location."""
39+
warn(
40+
"The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ",
41+
"Call reactpy.use_location instead.",
42+
DeprecationWarning,
43+
)
44+
3045
return use_connection().location

src/py/reactpy/reactpy/backend/sanic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
safe_web_modules_dir_path,
2525
serve_with_uvicorn,
2626
)
27-
from reactpy.backend.hooks import ConnectionContext
28-
from reactpy.backend.hooks import use_connection as _use_connection
2927
from reactpy.backend.types import Connection, Location
28+
from reactpy.core.hooks import ConnectionContext
29+
from reactpy.core.hooks import use_connection as _use_connection
3030
from reactpy.core.layout import Layout
3131
from reactpy.core.serve import RecvCoroutine, SendCoroutine, Stop, serve_layout
3232
from reactpy.core.types import RootComponentConstructor

src/py/reactpy/reactpy/backend/starlette.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
read_client_index_html,
2525
serve_with_uvicorn,
2626
)
27-
from reactpy.backend.hooks import ConnectionContext
28-
from reactpy.backend.hooks import use_connection as _use_connection
2927
from reactpy.backend.types import Connection, Location
3028
from reactpy.config import REACTPY_WEB_MODULES_DIR
29+
from reactpy.core.hooks import ConnectionContext
30+
from reactpy.core.hooks import use_connection as _use_connection
3131
from reactpy.core.layout import Layout
3232
from reactpy.core.serve import RecvCoroutine, SendCoroutine, serve_layout
3333
from reactpy.core.types import RootComponentConstructor

src/py/reactpy/reactpy/backend/tornado.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
CommonOptions,
2525
read_client_index_html,
2626
)
27-
from reactpy.backend.hooks import ConnectionContext
28-
from reactpy.backend.hooks import use_connection as _use_connection
2927
from reactpy.backend.types import Connection, Location
3028
from reactpy.config import REACTPY_WEB_MODULES_DIR
29+
from reactpy.core.hooks import ConnectionContext
30+
from reactpy.core.hooks import use_connection as _use_connection
3131
from reactpy.core.layout import Layout
3232
from reactpy.core.serve import serve_layout
3333
from reactpy.core.types import ComponentConstructor

src/py/reactpy/reactpy/core/hooks.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4-
from collections.abc import Coroutine, Sequence
4+
from collections.abc import Coroutine, MutableMapping, Sequence
55
from logging import getLogger
66
from types import FunctionType
77
from typing import (
@@ -17,6 +17,7 @@
1717

1818
from typing_extensions import TypeAlias
1919

20+
from reactpy.backend.types import Connection, Location
2021
from reactpy.config import REACTPY_DEBUG_MODE
2122
from reactpy.core._life_cycle_hook import current_hook
2223
from reactpy.core.types import Context, Key, State, VdomDict
@@ -248,6 +249,29 @@ def use_context(context: Context[_Type]) -> _Type:
248249
return provider.value
249250

250251

252+
# backend implementations should establish this context at the root of an app
253+
ConnectionContext: Context[Connection[Any] | None] = create_context(None)
254+
255+
256+
def use_connection() -> Connection[Any]:
257+
"""Get the current :class:`~reactpy.backend.types.Connection`."""
258+
conn = use_context(ConnectionContext)
259+
if conn is None: # nocov
260+
msg = "No backend established a connection."
261+
raise RuntimeError(msg)
262+
return conn
263+
264+
265+
def use_scope() -> MutableMapping[str, Any]:
266+
"""Get the current :class:`~reactpy.backend.types.Connection`'s scope."""
267+
return use_connection().scope
268+
269+
270+
def use_location() -> Location:
271+
"""Get the current :class:`~reactpy.backend.types.Connection`'s location."""
272+
return use_connection().location
273+
274+
251275
class _ContextProvider(Generic[_Type]):
252276
def __init__(
253277
self,

src/py/reactpy/tests/test_backend/test_all.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
from collections.abc import MutableMapping
32

43
import pytest
@@ -107,17 +106,13 @@ def ShowScope():
107106
assert isinstance(scope.current, MutableMapping)
108107

109108

110-
@pytest.mark.skipIf(
111-
sys.platform == "darwin",
112-
reason="Tornado and Flask backends are currently buggy on MacOS.",
113-
)
114109
async def test_use_location(display: DisplayFixture):
115110
location = reactpy.Ref()
116111

117112
@poll
118113
async def poll_location():
119114
"""This needs to be async to allow the server to respond"""
120-
return location.current
115+
return getattr(location, "current", None)
121116

122117
@reactpy.component
123118
def ShowRoute():

0 commit comments

Comments
 (0)