Skip to content
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

Replace mypy and black with ruff #262

Merged
merged 20 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/test-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
- name: Check docs build
run: hatch run docs:build
- name: Check docs examples
run: hatch run docs:check_examples
run: hatch fmt docs --check
15 changes: 15 additions & 0 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,18 @@ jobs:
run: hatch test --python ${{ matrix.python-version }} --ds=test_app.settings_single_db -v
- name: Run Multi-DB Tests
run: hatch test --python ${{ matrix.python-version }} --ds=test_app.settings_multi_db -v

python-formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install Python Dependencies
run: pip install --upgrade pip hatch uv
- name: Check Python formatting
run: hatch fmt src tests --check
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Don't forget to remove deprecated code on each major release!
### Changed

- Set upper limit on ReactPy version to `<2.0.0`.
- ReactPy web modules are now streamed in chunks.
- ReactPy web modules are now streamed using asynchronous file reading to improve performance.
- Performed refactoring to utilize `ruff` as this repository's linter.

## [5.1.0] - 2024-11-24

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@


from channels.routing import ProtocolTypeRouter, URLRouter # noqa: E402

from reactpy_django import REACTPY_WEBSOCKET_ROUTE # noqa: E402

application = ProtocolTypeRouter(
{
"http": django_asgi_app,
"websocket": URLRouter([REACTPY_WEBSOCKET_ROUTE]),
}
)
application = ProtocolTypeRouter({
"http": django_asgi_app,
"websocket": URLRouter([REACTPY_WEBSOCKET_ROUTE]),
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Broken load order, only used for linting
from channels.routing import ProtocolTypeRouter, URLRouter

from reactpy_django import REACTPY_WEBSOCKET_ROUTE

django_asgi_app = ""
Expand All @@ -8,9 +9,7 @@
# start
from channels.auth import AuthMiddlewareStack # noqa: E402

application = ProtocolTypeRouter(
{
"http": django_asgi_app,
"websocket": AuthMiddlewareStack(URLRouter([REACTPY_WEBSOCKET_ROUTE])),
}
)
application = ProtocolTypeRouter({
"http": django_asgi_app,
"websocket": AuthMiddlewareStack(URLRouter([REACTPY_WEBSOCKET_ROUTE])),
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component, html

from reactpy_django.components import django_css


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
@component
def my_component():
return html.div(
html.link(
{"rel": "stylesheet", "href": "https://example.com/external-styles.css"}
),
html.link({"rel": "stylesheet", "href": "https://example.com/external-styles.css"}),
html.button("My Button!"),
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component, html

from reactpy_django.components import django_js


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from example.models import TodoItem
from reactpy import component

from example.models import TodoItem
from reactpy_django.hooks import use_query
from reactpy_django.utils import django_query_postprocessor

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from reactpy import component, html
from reactpy_django.router import django_router
from reactpy_router import route

from reactpy_django.router import django_router


@component
def my_component():
Expand Down
3 changes: 3 additions & 0 deletions docs/examples/python/example/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""This module exists only to satisfy type checkers.

Do not use the files in this module as examples within the docs."""
6 changes: 6 additions & 0 deletions docs/examples/python/example/components.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""This module exists only to satisfy type checkers.

Do not use the files in this module as examples within the docs."""


def child_component(): ...
9 changes: 6 additions & 3 deletions docs/examples/python/example/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from django.shortcuts import render
"""This module exists only to satisfy type checkers.

Do not use the files in this module as examples within the docs."""

def index(request):
return render(request, "my_template.html")
from python.hello_world_cbv import HelloWorld
from python.hello_world_fbv import hello_world

__all__ = ["HelloWorld", "hello_world"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.urls import path

from example import views

urlpatterns = [
Expand Down
5 changes: 5 additions & 0 deletions docs/examples/python/first_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.shortcuts import render


def index(request):
return render(request, "my_template.html")
4 changes: 2 additions & 2 deletions docs/examples/python/hello_world_app_config_cbv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.apps import AppConfig
from reactpy_django.utils import register_iframe

from . import views
from example import views
from reactpy_django.utils import register_iframe


class ExampleAppConfig(AppConfig):
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/python/hello_world_app_config_fbv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.apps import AppConfig
from reactpy_django.utils import register_iframe

from . import views
from example import views
from reactpy_django.utils import register_iframe


class ExampleAppConfig(AppConfig):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

@component
def root():

def onClick(event):
def on_click(event):
js.document.title = "New window title"

return html.button({"onClick": onClick}, "Click Me!")
return html.button({"onClick": on_click}, "Click Me!")
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component, html

from reactpy_django.components import pyscript_component


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component, html

from reactpy_django.components import pyscript_component


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component, html

from reactpy_django.components import pyscript_component


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component, html

from reactpy_django.components import pyscript_component


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from typing import TYPE_CHECKING

from reactpy import component, html

if TYPE_CHECKING:
from .child import child_component
from example.components import child_component


@component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component, html

from reactpy_django.components import pyscript_component


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component, html

from reactpy_django.html import pyscript

example_source_code = """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.apps import AppConfig

from reactpy_django.utils import register_component


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component, hooks, html

from reactpy_django.hooks import use_channel_layer


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component, hooks, html

from reactpy_django.hooks import use_channel_layer


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component, hooks, html

from reactpy_django.hooks import use_channel_layer


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component, html

from reactpy_django.hooks import use_connection


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component, html

from reactpy_django.hooks import use_location


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from example.models import TodoItem
from reactpy import component, html

from example.models import TodoItem
from reactpy_django.hooks import use_mutation


Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from reactpy import component

from reactpy_django.hooks import use_mutation


def example_mutation(value: int, other_value: bool = False):
...
def example_mutation(value: int, other_value: bool = False): ...


@component
def my_component():
mutation = use_mutation(example_mutation)

mutation(123, other_value=True)

...
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from example.models import TodoItem
from reactpy import component, html

from example.models import TodoItem
from reactpy_django.hooks import use_mutation, use_query


Expand All @@ -26,9 +27,7 @@ def submit_event(event):
elif item_query.error or not item_query.data:
rendered_items = html.h2("Error when loading!")
else:
rendered_items = html.ul(
html.li(item.text, key=item.pk) for item in item_query.data
)
rendered_items = html.ul(html.li(item.text, key=item.pk) for item in item_query.data)

# Handle all possible mutation states
if item_mutation.loading:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from example.models import TodoItem
from reactpy import component, html

from example.models import TodoItem
from reactpy_django.hooks import use_mutation


Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from reactpy import component, html

from reactpy_django.hooks import use_mutation


def execute_thread_safe_mutation(text):
"""This is an example mutation function that does some thread-safe operation."""
pass


@component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component, html

from reactpy_django.hooks import use_origin


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from channels.db import database_sync_to_async
from example.models import TodoItem
from reactpy import component, html

from example.models import TodoItem
from reactpy_django.hooks import use_query


Expand All @@ -17,8 +18,6 @@ def todo_list():
elif item_query.error or not item_query.data:
rendered_items = html.h2("Error when loading!")
else:
rendered_items = html.ul(
[html.li(item.text, key=item.pk) for item in item_query.data]
)
rendered_items = html.ul([html.li(item.text, key=item.pk) for item in item_query.data])

return html.div("Rendered items: ", rendered_items)
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component

from reactpy_django.hooks import use_query


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from reactpy import component

from reactpy_django.hooks import use_query


Expand All @@ -11,7 +12,6 @@ def my_postprocessor(data, example_kwarg=True):

def execute_io_intensive_operation():
"""This is an example query function that does something IO intensive."""
pass


@component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from reactpy import component

from reactpy_django.hooks import use_query


def execute_io_intensive_operation():
"""This is an example query function that does something IO intensive."""
pass


@component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from example.models import TodoItem
from reactpy import component

from example.models import TodoItem
from reactpy_django.hooks import use_query


Expand Down
Loading
Loading