Skip to content

Commit c0cb1d9

Browse files
committed
run hatch fmt
1 parent 12dc1d0 commit c0cb1d9

23 files changed

+64
-92
lines changed

.github/workflows/publish-py.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
pip install -r requirements/build-pkg.txt
2323
- name: Build Package
2424
run: |
25-
hatch build
25+
hatch build --clean
2626
- name: Publish to PyPI
2727
env:
2828
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}

docs/examples/python/nested-routes.py renamed to docs/examples/python/nested_routes.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import operator
12
from typing import TypedDict
23

34
from reactpy import component, html, run
@@ -41,7 +42,7 @@ def home():
4142

4243
@component
4344
def all_messages():
44-
last_messages = {", ".join(msg["with"]): msg for msg in sorted(message_data, key=lambda m: m["id"])}
45+
last_messages = {", ".join(msg["with"]): msg for msg in sorted(message_data, key=operator.itemgetter("id"))}
4546

4647
messages = []
4748
for msg in last_messages.values():

docs/examples/python/route-parameters.py renamed to docs/examples/python/route_parameters.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import operator
12
from typing import TypedDict
23

34
from reactpy import component, html, run
@@ -39,7 +40,7 @@ def home():
3940

4041
@component
4142
def all_messages():
42-
last_messages = {", ".join(msg["with"]): msg for msg in sorted(message_data, key=lambda m: m["id"])}
43+
last_messages = {", ".join(msg["with"]): msg for msg in sorted(message_data, key=operator.itemgetter("id"))}
4344
messages = []
4445
for msg in last_messages.values():
4546
msg_hyperlink = link(

docs/src/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ You're now ready to start building your own ReactPy applications with URL routin
1313
=== "components.py"
1414

1515
```python
16-
{% include "../examples/python/basic-routing.py" %}
16+
{% include "../examples/python/basic_routing.py" %}
1717
```

docs/src/learn/hooks.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The [`use_search_params`][reactpy_router.use_search_params] hook can be used to
1313
=== "components.py"
1414

1515
```python
16-
{% include "../../examples/python/use-search-params.py" %}
16+
{% include "../../examples/python/use_search_params.py" %}
1717
```
1818

1919
## Use Parameters
@@ -23,5 +23,5 @@ The [`use_params`][reactpy_router.use_params] hook can be used to access route p
2323
=== "components.py"
2424

2525
```python
26-
{% include "../../examples/python/use-params.py" %}
26+
{% include "../../examples/python/use_params.py" %}
2727
```

docs/src/learn/routers-routes-and-links.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Here's a basic example showing how to use `#!python browser_router` with two rou
1616
=== "components.py"
1717

1818
```python
19-
{% include "../../examples/python/basic-routing.py" %}
19+
{% include "../../examples/python/basic_routing.py" %}
2020
```
2121

2222
Here we'll note some special syntax in the route path for the second route. The `#!python "any"` type is a wildcard that will match any path. This is useful for creating a default page or error page such as "404 NOT FOUND".
@@ -65,5 +65,5 @@ Links between routes should be created using the [link][reactpy_router.link] com
6565
=== "components.py"
6666

6767
```python
68-
{% include "../../examples/python/route-links.py" %}
68+
{% include "../../examples/python/route_links.py" %}
6969
```

docs/src/learn/your-first-app.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The first step is to create a basic router that will display the home page when
3636
=== "components.py"
3737

3838
```python
39-
{% include "../../examples/python/basic-routing.py" %}
39+
{% include "../../examples/python/basic_routing.py" %}
4040
```
4141

4242
When navigating to [`http://127.0.0.1:8000`](http://127.0.0.1:8000) you should see `Home Page 🏠`. However, if you go to any other route you will instead see `Missing Link 🔗‍💥`.
@@ -46,7 +46,7 @@ With this foundation you can start adding more routes.
4646
=== "components.py"
4747

4848
```python
49-
{% include "../../examples/python/basic-routing-more-routes.py" %}
49+
{% include "../../examples/python/basic_routing_more_routes.py" %}
5050
```
5151

5252
With this change you can now also go to [`/messages`](http://127.0.0.1:8000/messages) to see `Messages 💬`.
@@ -58,7 +58,7 @@ Instead of using the standard `#!python reactpy.html.a` element to create links
5858
=== "components.py"
5959

6060
```python
61-
{% include "../../examples/python/route-links.py" %}
61+
{% include "../../examples/python/route_links.py" %}
6262
```
6363

6464
Now, when you go to the home page, you can click `Messages` link to go to [`/messages`](http://127.0.0.1:8000/messages).
@@ -70,7 +70,7 @@ Routes can be nested in order to construct more complicated application structur
7070
=== "components.py"
7171

7272
```python
73-
{% include "../../examples/python/nested-routes.py" %}
73+
{% include "../../examples/python/nested_routes.py" %}
7474
```
7575

7676
## Adding Route Parameters
@@ -84,5 +84,5 @@ If we take this information and apply it to our growing example application we'd
8484
=== "components.py"
8585

8686
```python
87-
{% include "../../examples/python/route-parameters.py" %}
87+
{% include "../../examples/python/route_parameters.py" %}
8888
```

noxfile.py

-52
This file was deleted.

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ lint.extend-ignore = [
113113
"SLF001", # Private member accessed
114114
]
115115
lint.preview = true
116-
lint.isort.known-first-party = ["src", "tests"]
117116
extend-exclude = [".venv/*", ".eggs/*", "build/*"]
118117

119118
[tool.pytest.ini_options]

src/reactpy_router/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
__version__ = "1.0.0"
33

44

5-
from .components import link, navigate, route
6-
from .hooks import use_params, use_search_params
7-
from .routers import browser_router, create_router
5+
from reactpy_router.components import link, navigate, route
6+
from reactpy_router.hooks import use_params, use_search_params
7+
from reactpy_router.routers import browser_router, create_router
88

99
__all__ = (
10+
"browser_router",
1011
"create_router",
1112
"link",
13+
"navigate",
1214
"route",
13-
"browser_router",
1415
"use_params",
1516
"use_search_params",
16-
"navigate",
1717
)

src/reactpy_router/components.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4-
from typing import Any
4+
from typing import TYPE_CHECKING, Any
55
from urllib.parse import urljoin
66
from uuid import uuid4
77

88
from reactpy import component, html, use_connection
99
from reactpy.backend.types import Location
10-
from reactpy.core.component import Component
11-
from reactpy.core.types import Key, VdomDict
1210
from reactpy.web.module import export, module_from_file
1311

1412
from reactpy_router.hooks import _use_route_state
1513
from reactpy_router.types import Route
1614

15+
if TYPE_CHECKING:
16+
from reactpy.core.component import Component
17+
from reactpy.core.types import Key, VdomDict
18+
1719
History = export(
1820
module_from_file("reactpy-router", file=Path(__file__).parent / "static" / "bundle.js"),
1921
("History"),
@@ -68,7 +70,8 @@ def _link(attributes: dict[str, Any], *children: Any) -> VdomDict:
6870
if "href" in attributes and "to" not in attributes:
6971
attributes["to"] = attributes.pop("href")
7072
if "to" not in attributes: # pragma: no cover
71-
raise ValueError("The `to` attribute is required for the `Link` component.")
73+
msg = "The `to` attribute is required for the `Link` component."
74+
raise ValueError(msg)
7275
to = attributes.pop("to")
7376

7477
attrs = {

src/reactpy_router/hooks.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
from __future__ import annotations
22

3-
from typing import Any
3+
from typing import TYPE_CHECKING, Any
44
from urllib.parse import parse_qs
55

66
from reactpy import create_context, use_context, use_location
7-
from reactpy.types import Context
87

9-
from reactpy_router.types import RouteState
8+
from reactpy_router.types import RouteState # noqa: TCH001
9+
10+
if TYPE_CHECKING:
11+
from reactpy.types import Context
12+
1013

1114
_route_state_context: Context[RouteState | None] = create_context(None)
1215

1316

1417
def _use_route_state() -> RouteState:
1518
route_state = use_context(_route_state_context)
1619
if route_state is None: # pragma: no cover
17-
raise RuntimeError(
20+
msg = (
1821
"ReactPy-Router was unable to find a route context. Are you "
1922
"sure this hook/component is being called within a router?"
2023
)
24+
raise RuntimeError(msg)
2125

2226
return route_state
2327

src/reactpy_router/resolvers.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from __future__ import annotations
22

33
import re
4-
from typing import Any
4+
from typing import TYPE_CHECKING, Any
55

66
from reactpy_router.converters import CONVERTERS
7-
from reactpy_router.types import ConversionInfo, ConverterMapping, Route
7+
8+
if TYPE_CHECKING:
9+
from reactpy_router.types import ConversionInfo, ConverterMapping, Route
810

911
__all__ = ["StarletteResolver"]
1012

@@ -48,7 +50,8 @@ def parse_path(self, path: str) -> re.Pattern[str]:
4850
try:
4951
conversion_info = self.registered_converters[param_type]
5052
except KeyError as e:
51-
raise ValueError(f"Unknown conversion type {param_type!r} in {path!r}") from e
53+
msg = f"Unknown conversion type {param_type!r} in {path!r}"
54+
raise ValueError(msg) from e
5255

5356
# Add the string before the match to the pattern
5457
pattern += re.escape(path[last_match_end : match.start()])

src/reactpy_router/routers.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@
44

55
from dataclasses import replace
66
from logging import getLogger
7-
from typing import Any, Iterator, Literal, Sequence, cast
7+
from typing import TYPE_CHECKING, Any, Literal, cast
88

99
from reactpy import component, use_memo, use_state
1010
from reactpy.backend.hooks import ConnectionContext, use_connection
1111
from reactpy.backend.types import Connection, Location
12-
from reactpy.core.component import Component
1312
from reactpy.types import ComponentType, VdomDict
1413

1514
from reactpy_router.components import FirstLoad, History
1615
from reactpy_router.hooks import RouteState, _route_state_context
1716
from reactpy_router.resolvers import StarletteResolver
18-
from reactpy_router.types import CompiledRoute, Resolver, Router, RouteType
17+
18+
if TYPE_CHECKING:
19+
from collections.abc import Iterator, Sequence
20+
21+
from reactpy.core.component import Component
22+
23+
from reactpy_router.types import CompiledRoute, Resolver, Router, RouteType
1924

2025
__all__ = ["browser_router", "create_router"]
2126
_logger = getLogger(__name__)

src/reactpy_router/types.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
from __future__ import annotations
44

55
from dataclasses import dataclass, field
6-
from typing import Any, Callable, Sequence, TypedDict, TypeVar
6+
from typing import TYPE_CHECKING, Any, Callable, TypedDict, TypeVar
77

8-
from reactpy.backend.types import Location
9-
from reactpy.core.component import Component
108
from reactpy.core.vdom import is_vdom
11-
from reactpy.types import Key
129
from typing_extensions import Protocol, Self, TypeAlias
1310

11+
if TYPE_CHECKING:
12+
from collections.abc import Sequence
13+
14+
from reactpy.backend.types import Location
15+
from reactpy.core.component import Component
16+
from reactpy.types import Key
17+
1418
ConversionFunc: TypeAlias = Callable[[str], Any]
1519
"""A function that converts a string to a specific type."""
1620

tests/conftest.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ def pytest_addoption(parser) -> None:
1717
)
1818

1919

20+
def pytest_sessionstart(session):
21+
"""Rebuild the project before running the tests to get the latest JavaScript"""
22+
subprocess.run(["hatch", "build", "--clean"], check=True)
23+
24+
2025
@pytest.fixture(scope="session")
2126
async def display(backend, browser):
22-
subprocess.run(["hatch", "build"], check=True)
2327
async with DisplayFixture(backend, browser) as display_fixture:
2428
display_fixture.page.set_default_timeout(10000)
2529
yield display_fixture

tests/test_resolver.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_parse_path():
4646

4747
def test_parse_path_unkown_conversion():
4848
resolver = StarletteResolver(route("/", None))
49-
with pytest.raises(ValueError):
49+
with pytest.raises(ValueError, match="Unknown conversion type 'unknown' in '/a/{b:unknown}/c'"):
5050
resolver.parse_path("/a/{b:unknown}/c")
5151

5252

tests/test_router.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def sample():
136136

137137
await display.show(sample)
138138

139-
for path, expected_params in [
139+
for path, _expected_params in [
140140
("/first/1", {"first": "1"}),
141141
("/first/1/second/2", {"first": "1", "second": "2"}),
142142
("/first/1/second/2/third/3", {"first": "1", "second": "2", "third": "3"}),

0 commit comments

Comments
 (0)