Skip to content

Rewrite ReactPy-Router #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 62 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
69598ef
Bump workflows
Archmonger Feb 22, 2024
c86f37b
use_query -> use_search_params
Archmonger Jun 25, 2024
ec1b633
use_params docstring
Archmonger Jun 25, 2024
332ca75
better error for route state
Archmonger Jun 25, 2024
189b484
simple.router -> browser_router
Archmonger Jun 25, 2024
6557000
Allow multi-component routes
Archmonger Jun 25, 2024
9e72ca0
Fix potential key identity bug of router component children
Archmonger Jun 25, 2024
7a242e1
Add slug conversion type
Archmonger Jun 25, 2024
e92842f
SimpleResolver -> Resolver, CONVERSION_TYPES -> CONVERTERS, file refa…
Archmonger Jun 25, 2024
f46d9d1
allow customizable match_any_identifier
Archmonger Jun 25, 2024
b8efe54
attempt to fix workflows
Archmonger Jun 25, 2024
bee18a5
server-side link component
Archmonger Jun 25, 2024
de53beb
fix a handful of test errors
Archmonger Jun 26, 2024
f77f052
change js output directory
Archmonger Jun 26, 2024
518d226
fix py3.9 type hints
Archmonger Jun 26, 2024
e96a512
Change star pattern to `{NAME:any}`
Archmonger Jun 28, 2024
03b8f2c
Fix router in local environment
Archmonger Oct 5, 2024
37760bb
Fix link component
Archmonger Oct 5, 2024
ee616d0
Fix route parameters
Archmonger Oct 5, 2024
169e2dc
remove black from workflow
Archmonger Oct 5, 2024
5ffc34f
Format with ruff + prettier
Archmonger Oct 5, 2024
8b057b2
Fix github actions
Archmonger Oct 5, 2024
db9e074
Fix use_search_params
Archmonger Oct 5, 2024
7947e91
Clean up use-params example
Archmonger Oct 5, 2024
d9a943a
Remove select from top level router
Archmonger Oct 5, 2024
94e9de5
docs tweaks
Archmonger Oct 6, 2024
afb97c8
js tweaks
Archmonger Oct 6, 2024
78c7c49
Refactor some more docs
Archmonger Oct 6, 2024
1b8031b
Better mkdocstrings
Archmonger Oct 6, 2024
f52aaa3
Remove core.py
Archmonger Oct 6, 2024
bad417f
cleaner example for use params
Archmonger Oct 6, 2024
155079b
ignore link click type
Archmonger Oct 6, 2024
c7d19f6
Move event loop policy to dedicated fixture
Archmonger Oct 6, 2024
d7184b1
Fix resolver tests
Archmonger Oct 6, 2024
6857f7a
fix type errors
Archmonger Oct 6, 2024
fa0f307
use link class instead of ID
Archmonger Oct 6, 2024
1723f8d
prefix uuid with a string
Archmonger Oct 6, 2024
b67101a
add test for link search params
Archmonger Oct 6, 2024
c38ac3b
Remove coverage from some unneeded places
Archmonger Oct 6, 2024
f57b63b
Fix browser history
Archmonger Oct 6, 2024
88d1f46
use server side prevent default
Archmonger Oct 6, 2024
a78a5b1
Server side handling of relative URLs
Archmonger Oct 6, 2024
97a715c
Add test for class name
Archmonger Oct 7, 2024
4633ab2
fix last coverage hit
Archmonger Oct 7, 2024
70a7ea0
self review
Archmonger Oct 11, 2024
98ac776
Add click delay (attempt to fix flakey tests)
Archmonger Oct 11, 2024
9fc92ce
Add changelog
Archmonger Oct 11, 2024
0e87d27
Increase delay
Archmonger Oct 11, 2024
0469615
Remove unneeded homepage stuff
Archmonger Oct 12, 2024
1d33c65
Use ReactJS event naming conventions
Archmonger Oct 12, 2024
25e440f
Self review: Use JS component as background listener for link clicks
Archmonger Oct 12, 2024
8e9b6a8
use attributes dict for all link parameters
Archmonger Oct 12, 2024
05e7012
Allow reconnections to re-obtain the current URL
Archmonger Oct 12, 2024
afa8c83
Add new changelog item
Archmonger Oct 12, 2024
972c275
Revert to dumb script for links
Archmonger Oct 12, 2024
ff65483
no cov on exception
Archmonger Oct 12, 2024
7e10dd4
fix test
Archmonger Oct 12, 2024
78b5a95
Fix spelling
Archmonger Oct 12, 2024
2d88133
Update src/reactpy_router/resolvers.py
Archmonger Oct 13, 2024
b1192c5
use unpacking instead of list
Archmonger Oct 14, 2024
9d18fc9
safer query string parsing
Archmonger Oct 14, 2024
df4c088
Remove unused import
Archmonger Oct 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# http://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
end_of_line = lf

[*.py]
indent_size = 4
max_line_length = 120

[*.md]
indent_size = 4

[*.html]
max_line_length = off

[*.js]
max_line_length = off

[*.css]
indent_size = 4
max_line_length = off

# Tests can violate line width restrictions in the interest of clarity.
[**/test_*.py]
max_line_length = off
108 changes: 46 additions & 62 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,67 +12,51 @@
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
# Runs at 22:21 on Monday.
- cron: '21 22 * * 1'
push:
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]
schedule:
# Runs at 22:21 on Monday.
- cron: "21 22 * * 1"

jobs:
analyze:
name: Analyze
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript', 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
analyze:
name: Analyze
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ["javascript", "python"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
4 changes: 2 additions & 2 deletions .github/workflows/publish-develop-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- run: pip install -r requirements/build-docs.txt
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-py.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
publish-package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-release-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- run: pip install -r requirements/build-docs.txt
Expand Down
66 changes: 34 additions & 32 deletions .github/workflows/test-docs.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
name: Test

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "0 0 * * *"
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "0 0 * * *"

jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Check docs build
run: |
pip install -r requirements/build-docs.txt
linkcheckMarkdown docs/ -v -r
linkcheckMarkdown README.md -v -r
linkcheckMarkdown CHANGELOG.md -v -r
cd docs
mkdocs build --strict
- name: Check docs examples
run: |
pip install -r requirements/check-types.txt
pip install -r requirements/check-style.txt
mypy --show-error-codes docs/examples/python/
black docs/examples/python/ --check
ruff check docs/examples/python/
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install Python Dependencies
run: |
pip install -r requirements/build-docs.txt
pip install -r requirements/check-types.txt
pip install -r requirements/check-style.txt
pip install -e .
- name: Check docs build
run: |
linkcheckMarkdown docs/ -v -r
linkcheckMarkdown README.md -v -r
linkcheckMarkdown CHANGELOG.md -v -r
cd docs
mkdocs build --strict
- name: Check docs examples
run: |
mypy --show-error-codes docs/examples/python/
ruff check docs/examples/python/
8 changes: 4 additions & 4 deletions .github/workflows/test-src.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Python Dependencies
Expand All @@ -29,9 +29,9 @@ jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Latest Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Python Dependencies
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ docs/site

# --- JAVASCRIPT BUNDLES ---

src/reactpy_router/bundle.js
src/reactpy_router/static/bundle.js

# --- PYTHON IGNORE FILES ----

Expand Down Expand Up @@ -108,7 +108,7 @@ celerybeat.pid

# Environments
.env
.venv
.venv*
env/
venv/
ENV/
Expand Down
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"proseWrap": "never",
"trailingComma": "all"
}
26 changes: 25 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,31 @@ Using the following categories, list your changes in this order:

## [Unreleased]

- Nothing (yet)!
### Changed

- Bump GitHub workflows
- Rename `use_query` to `use_search_params`.
- Rename `simple.router` to `browser_router`.
- Rename `SimpleResolver` to `StarletteResolver`.
- Rename `CONVERSION_TYPES` to `CONVERTERS`.
- Change "Match Any" syntax from a star `*` to `{name:any}`.
- Rewrite `reactpy_router.link` to be a server-side component.
- Simplified top-level exports within `reactpy_router`.

### Added

- New error for ReactPy router elements being used outside router context.
- Configurable/inheritable `Resolver` base class.
- Add debug log message for when there are no router matches.
- Add slug as a supported type.

### Fixed

- Fix bug where changing routes could cause render failure due to key identity.
- Fix bug where "Match Any" pattern wouldn't work when used in complex or nested paths.
- Fix bug where `link` elements could not have `@component` type children.
- Fix bug where the ReactPy would not detect the current URL after a reconnection.
- Fixed flakey tests being flakey on GitHub CI by adding click delays.

## [0.1.1] - 2023-12-13

Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include src/reactpy_router/bundle.js
recursive-include src/reactpy_router/static *
include src/reactpy_router/py.typed
7 changes: 3 additions & 4 deletions docs/examples/python/basic-routing-more-routes.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from reactpy import component, html, run

from reactpy_router import route, simple
from reactpy_router import browser_router, route


@component
def root():
return simple.router(
return browser_router(
route("/", html.h1("Home Page 🏠")),
route("/messages", html.h1("Messages 💬")),
route("*", html.h1("Missing Link 🔗‍💥")),
route("{404:any}", html.h1("Missing Link 🔗‍💥")),
)


Expand Down
7 changes: 3 additions & 4 deletions docs/examples/python/basic-routing.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from reactpy import component, html, run

from reactpy_router import route, simple
from reactpy_router import browser_router, route


@component
def root():
return simple.router(
return browser_router(
route("/", html.h1("Home Page 🏠")),
route("*", html.h1("Missing Link 🔗‍💥")),
route("{404:any}", html.h1("Missing Link 🔗‍💥")),
)


Expand Down
Loading