Skip to content

Commit bc2d64c

Browse files
committed
add star pattern
1 parent 5f46ed9 commit bc2d64c

File tree

5 files changed

+14
-23
lines changed

5 files changed

+14
-23
lines changed

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install Python Dependencies
2121
run: pip install -r requirements/nox-deps.txt
2222
- name: Run Tests
23-
run: nox -s test
23+
run: nox -t test
2424

2525
environments:
2626
runs-on: ubuntu-latest
@@ -36,4 +36,4 @@ jobs:
3636
- name: Install Python Dependencies
3737
run: pip install -r requirements/nox-deps.txt
3838
- name: Run Tests
39-
run: nox -s test -- --no-cov
39+
run: nox -t test -- --no-cov

noxfile.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@session
1010
def format(session: Session) -> None:
11-
install_requirements(session, "style")
11+
install_requirements(session, "check-style")
1212
session.run("black", ".")
1313
session.run("isort", ".")
1414

@@ -25,29 +25,21 @@ def docs_build(session: Session) -> None:
2525
session.run("mkdocs", "build")
2626

2727

28-
@session
29-
def test(session: Session) -> None:
30-
session.notify("test_style")
31-
session.notify("test_types")
32-
session.notify("test_suite")
33-
session.notify("test_javascript")
34-
35-
36-
@session
28+
@session(tags=["test"])
3729
def test_style(session: Session) -> None:
3830
install_requirements(session, "check-style")
3931
session.run("black", "--check", ".")
4032
session.run("isort", "--check", ".")
4133
session.run("flake8", ".")
4234

4335

44-
@session
36+
@session(tags=["test"])
4537
def test_types(session: Session) -> None:
4638
install_requirements(session, "check-types")
4739
session.run("mypy", "--strict", "reactpy_router")
4840

4941

50-
@session
42+
@session(tags=["test"])
5143
def test_suite(session: Session) -> None:
5244
install_requirements(session, "test-env")
5345
session.run("playwright", "install", "chromium")
@@ -65,7 +57,7 @@ def test_suite(session: Session) -> None:
6557
session.run("pytest", "tests", *posargs)
6658

6759

68-
@session
60+
@session(tags=["test"])
6961
def test_javascript(session: Session) -> None:
7062
session.chdir(ROOT / "js")
7163
session.run("npm", "install", external=True)

reactpy_router/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from reactpy import (
1111
component,
1212
create_context,
13+
html,
1314
use_context,
1415
use_location,
1516
use_memo,
@@ -20,7 +21,6 @@
2021
from reactpy.core.types import VdomChild, VdomDict
2122
from reactpy.types import ComponentType, Context, Location
2223
from reactpy.web.module import export, module_from_file
23-
from reactpy import html
2424

2525
from reactpy_router.types import Route, RouteCompiler, Router, RouteResolver
2626

@@ -45,7 +45,7 @@ def wrapper(*routes: R) -> ComponentType:
4545
def router_component(
4646
*routes: R,
4747
compiler: RouteCompiler[R],
48-
) -> ComponentType | None:
48+
) -> VdomDict | None:
4949
"""A component that renders the first matching route using the given compiler"""
5050

5151
old_conn = use_connection()

reactpy_router/simple.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
ConversionFunc: TypeAlias = "Callable[[str], Any]"
1717
ConverterMapping: TypeAlias = "dict[str, ConversionFunc]"
1818

19-
PARAM_REGEX = re.compile(r"{(?P<name>\w+)(?P<type>:\w+)?}")
20-
"""Regex for matching path params"""
19+
STAR_PATTERN = re.compile("^.*$")
20+
PARAM_PATTERN = re.compile(r"{(?P<name>\w+)(?P<type>:\w+)?}")
2121

2222

2323
class SimpleResolver:
@@ -39,14 +39,13 @@ def resolve(self, path: str) -> tuple[Any, dict[str, Any]] | None:
3939

4040

4141
def parse_path(path: str) -> tuple[re.Pattern[str], ConverterMapping]:
42-
"""Parse a path into a regex pattern and a mapping of converters"""
4342
if path == "*":
44-
return re.compile(".*"), {}
43+
return STAR_PATTERN, {}
4544

4645
pattern = "^"
4746
last_match_end = 0
4847
converters: ConverterMapping = {}
49-
for match in PARAM_REGEX.finditer(path):
48+
for match in PARAM_PATTERN.finditer(path):
5049
param_name = match.group("name")
5150
param_type = (match.group("type") or "str").lstrip(":")
5251
try:

tests/test_simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ def test_parse_path_re_escape():
5050
)
5151

5252

53-
def test_match_any_path():
53+
def test_match_star_path():
5454
assert parse_path("*") == (re.compile(".*"), {})

0 commit comments

Comments
 (0)