Skip to content

Commit

Permalink
refactor: replace flake8 plugins with ruff (#2236)
Browse files Browse the repository at this point in the history
* chore: replace flake8 with ruff

* chore: remove flake8 block in setup file

* fix: make mypy happy

* style: enable isort in ruff

* chore: rework cython import to avoid coverage issue

* style: format the examples

* chore: fix mypy error

* docs: update tutorial code to reflect format style changes
  • Loading branch information
CaselIT authored Jul 13, 2024
1 parent c345420 commit 09189a8
Show file tree
Hide file tree
Showing 112 changed files with 306 additions and 317 deletions.
10 changes: 6 additions & 4 deletions docs/user/tutorial-asgi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ We can now implement a basic async image store. Save the following code as
import io
import aiofiles
import falcon
import PIL.Image
import falcon
class Image:
def __init__(self, config, image_id, size):
Expand Down Expand Up @@ -266,6 +267,7 @@ of images. Place the code below in a file named ``images.py``:
.. code:: python
import aiofiles
import falcon
Expand Down Expand Up @@ -670,8 +672,6 @@ The new ``thumbnails`` end-point should now render thumbnails on the fly::
Again, we could also verify thumbnail URIs in the browser or image viewer that
supports HTTP input.



.. _asgi_tutorial_caching:

Caching Responses
Expand Down Expand Up @@ -979,9 +979,11 @@ your ASGI Falcon application:

.. code:: python
import falcon
import logging
import falcon
logging.basicConfig(level=logging.INFO)
class ErrorResource:
Expand Down
35 changes: 22 additions & 13 deletions docs/user/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,9 @@ Then, update the responder to use the new media type:

.. code:: python
import falcon
import msgpack
import falcon
class Resource:
Expand Down Expand Up @@ -467,11 +466,12 @@ Next, edit ``test_app.py`` to look like this:

.. code:: python
import falcon
from falcon import testing
import msgpack
import pytest
import falcon
from falcon import testing
from look.app import app
Expand Down Expand Up @@ -601,9 +601,10 @@ POSTs. Open ``images.py`` and add a POST responder to the
import uuid
import mimetypes
import falcon
import msgpack
import falcon
class Resource:
Expand Down Expand Up @@ -723,9 +724,10 @@ operation:
import os
import uuid
import falcon
import msgpack
import falcon
class Resource:
Expand Down Expand Up @@ -789,7 +791,8 @@ Hmm, it looks like we forgot to update ``app.py``. Let's do that now:
import falcon
from .images import ImageStore, Resource
from .images import ImageStore
from .images import Resource
app = application = falcon.App()
Expand All @@ -813,7 +816,8 @@ similar to the following:
import falcon
from .images import ImageStore, Resource
from .images import ImageStore
from .images import Resource
def create_app(image_store):
Expand Down Expand Up @@ -849,11 +853,12 @@ look similar to this:
from unittest.mock import call, MagicMock, mock_open
import falcon
from falcon import testing
import msgpack
import pytest
import falcon
from falcon import testing
import look.app
import look.images
Expand Down Expand Up @@ -1041,7 +1046,8 @@ the image storage directory with an environment variable:
import falcon
from .images import ImageStore, Resource
from .images import ImageStore
from .images import Resource
def create_app(image_store):
Expand Down Expand Up @@ -1123,9 +1129,10 @@ Go ahead and edit your ``images.py`` file to look something like this:
import uuid
import mimetypes
import falcon
import msgpack
import falcon
class Collection:
Expand Down Expand Up @@ -1234,7 +1241,9 @@ similar to the following:
import falcon
from .images import Collection, ImageStore, Item
from .images import Collection
from .images import ImageStore
from .images import Item
def create_app(image_store):
Expand Down
1 change: 0 additions & 1 deletion e2e-tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import falcon.testing


HERE = pathlib.Path(__file__).resolve().parent
INDEX = '/static/index.html'

Expand Down
4 changes: 3 additions & 1 deletion e2e-tests/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import falcon
import falcon.asgi

from .chat import Chat
from .hub import Events, Hub
from .hub import Events
from .hub import Hub
from .ping import Pong

HERE = pathlib.Path(__file__).resolve().parent
Expand Down
3 changes: 2 additions & 1 deletion e2e-tests/server/chat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re

from falcon.asgi import Request, WebSocket
from falcon.asgi import Request
from falcon.asgi import WebSocket

from .hub import Hub

Expand Down
5 changes: 4 additions & 1 deletion e2e-tests/server/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import typing
import uuid

from falcon.asgi import Request, Response, SSEvent, WebSocket
from falcon.asgi import Request
from falcon.asgi import Response
from falcon.asgi import SSEvent
from falcon.asgi import WebSocket


class Emitter:
Expand Down
3 changes: 2 additions & 1 deletion e2e-tests/server/ping.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from http import HTTPStatus

import falcon
from falcon.asgi import Request, Response
from falcon.asgi import Request
from falcon.asgi import Response


class Pong:
Expand Down
3 changes: 2 additions & 1 deletion examples/asgilook/asgilook/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from .cache import RedisCache
from .config import Config
from .images import Images, Thumbnails
from .images import Images
from .images import Thumbnails
from .store import Store


Expand Down
1 change: 0 additions & 1 deletion examples/asgilook/asgilook/cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import msgpack
import redis.asyncio as redis


class RedisCache:
Expand Down
3 changes: 2 additions & 1 deletion examples/asgilook/asgilook/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import pathlib
import redis.asyncio
import uuid

import redis.asyncio


class Config:
DEFAULT_CONFIG_PATH = '/tmp/asgilook'
Expand Down
1 change: 1 addition & 0 deletions examples/asgilook/asgilook/images.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import aiofiles

import falcon


Expand Down
3 changes: 2 additions & 1 deletion examples/asgilook/asgilook/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import io

import aiofiles
import falcon
import PIL.Image

import falcon


class Image:
def __init__(self, config, image_id, size):
Expand Down
5 changes: 3 additions & 2 deletions examples/asgilook/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import uuid

import fakeredis.aioredis
import falcon.asgi
import falcon.testing
import PIL.Image
import PIL.ImageDraw
import pytest

import falcon.asgi
import falcon.testing

from asgilook.app import create_app
from asgilook.config import Config

Expand Down
3 changes: 2 additions & 1 deletion examples/look/look/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import falcon

from .images import ImageStore, Resource
from .images import ImageStore
from .images import Resource


def create_app(image_store):
Expand Down
3 changes: 2 additions & 1 deletion examples/look/look/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import os
import uuid

import falcon
import msgpack

import falcon


class Resource:
def __init__(self, image_store):
Expand Down
1 change: 0 additions & 1 deletion examples/look/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import requests


LOOK_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

gunicorn = None
Expand Down
9 changes: 6 additions & 3 deletions examples/look/tests/test_app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import io
from unittest.mock import call
from unittest.mock import MagicMock
from unittest.mock import mock_open
from wsgiref.validate import InputWrapper

import falcon
from falcon import testing
from unittest.mock import call, MagicMock, mock_open
import msgpack
import pytest

import falcon
from falcon import testing

import look.app
import look.images

Expand Down
3 changes: 2 additions & 1 deletion examples/things_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import uuid
from wsgiref import simple_server

import falcon
import requests

import falcon


class StorageEngine:
def get_things(self, marker, limit):
Expand Down
3 changes: 2 additions & 1 deletion examples/things_advanced_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import logging
import uuid

import httpx

import falcon
import falcon.asgi
import httpx


class StorageEngine:
Expand Down
1 change: 0 additions & 1 deletion falcon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
from falcon.util import wrap_sync_to_async_unsafe
from falcon.version import __version__


# NOTE(kgriffs): Only to be used internally on the rare occasion that we
# need to log something that we can't communicate any other way.
_logger = _logging.getLogger('falcon')
Expand Down
10 changes: 5 additions & 5 deletions falcon/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
from falcon.response import Response
from falcon.response import ResponseOptions
import falcon.status_codes as status
from falcon.typing import ErrorHandler, ErrorSerializer, SinkPrefix
from falcon.typing import ErrorHandler
from falcon.typing import ErrorSerializer
from falcon.typing import SinkPrefix
from falcon.util import deprecation
from falcon.util import misc
from falcon.util.misc import code_to_http_status


# PERF(vytas): On Python 3.5+ (including cythonized modules),
# reference via module global is faster than going via self
_BODILESS_STATUS_CODES = frozenset(
Expand All @@ -63,7 +64,7 @@


class App:
"""This class is the main entry point into a Falcon-based WSGI app.
"""The main entry point into a Falcon-based WSGI app.
Each App instance provides a callable
`WSGI <https://www.python.org/dev/peps/pep-3333/>`_ interface
Expand Down Expand Up @@ -1152,8 +1153,7 @@ def _update_sink_and_static_routes(self):
# TODO(myusko): This class is a compatibility alias, and should be removed
# in the next major release (4.0).
class API(App):
"""
This class is a compatibility alias of :class:`falcon.App`.
"""Compatibility alias of :class:`falcon.App`.
``API`` was renamed to :class:`App <falcon.App>` in Falcon 3.0 in order to
reflect the breadth of applications that :class:`App <falcon.App>`, and its
Expand Down
3 changes: 2 additions & 1 deletion falcon/app_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from falcon import util
from falcon.constants import MEDIA_JSON
from falcon.constants import MEDIA_XML
from falcon.errors import CompatibilityError, HTTPError
from falcon.errors import CompatibilityError
from falcon.errors import HTTPError
from falcon.request import Request
from falcon.response import Response
from falcon.util.sync import _wrap_non_coroutine_unsafe
Expand Down
Loading

0 comments on commit 09189a8

Please sign in to comment.