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 black and isort with ruff #176

Merged
merged 1 commit into from
Feb 11, 2025
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
29 changes: 13 additions & 16 deletions .github/workflows/test_and_publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ on:
branches:
- master
paths-ignore:
- 'examples/**'
- '.github/**'
- 'docs/**'
- 'scripts/**'
- 'Dockerfiles/**'
- "examples/**"
- ".github/**"
- "docs/**"
- "scripts/**"
- "Dockerfiles/**"

env:
DEFAULT_LINUX: "slim"
Expand All @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
python: ["3.9", "3.10", "3.11", "3.12", "3.13"]
container:
image: python:${{ matrix.python }}
steps:
Expand All @@ -40,18 +40,15 @@ jobs:
run: |
pip install pip poetry --upgrade
./scripts/install
- id: black
- id: format
name: Code format checking
run: ./scripts/black --check .
- id: isort
name: Imports order checking
run: ./scripts/isort --check .
- id: ruff
name: Code style (ruff)
run: ./scripts/ruff .
- id: pyright
run: ./scripts/format --check .
- id: lint
name: Code linting
run: ./scripts/lint --output-format=github .
- id: types
name: Static types check
run: ./scripts/pyright
run: ./scripts/types
- id: tests
name: Tests
run: ./scripts/test
Expand Down
17 changes: 7 additions & 10 deletions .github/workflows/test_pull_request_branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@ jobs:
run: |
pip install pip poetry --upgrade
./scripts/install
- id: black
- id: format
name: Code format checking
run: ./scripts/black --check .
- id: isort
name: Imports order checking
run: ./scripts/isort --check .
- id: ruff
name: Code style (ruff)
run: ./scripts/ruff .
- id: pyright
run: ./scripts/format --check .
- id: lint
name: Code linting
run: ./scripts/lint --output-format=github .
- id: types
name: Static types check
run: ./scripts/pyright
run: ./scripts/types
- id: tests
name: Tests
run: ./scripts/test
56 changes: 23 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,56 +1,46 @@
fail_fast: true
repos:
- repo: [email protected]:pre-commit/pre-commit-hooks
- repo: [email protected]:pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-added-large-files
- id: check-added-large-files
args:
- --maxkb=2000
- id: check-merge-conflict
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: name-tests-test
- --maxkb=2000
- id: check-merge-conflict
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: name-tests-test
args:
- --django
- --django
exclude: "asserts.py|utils.py"
- id: pretty-format-json
- id: pretty-format-json
args:
- --autofix
- --indent=2
- --autofix
- --indent=2
exclude: "templates/.+\\.json"
- repo: [email protected]:alessandrojcm/commitlint-pre-commit-hook
- repo: [email protected]:alessandrojcm/commitlint-pre-commit-hook
rev: v8.0.0
hooks:
- id: commitlint
stages: [commit-msg]
- repo: local
- repo: local
hooks:
- id: black
name: Black - Code Style
entry: ./scripts/black
args:
- -q
- --safe
- --line-length=120
language: system
types: [file, python]
exclude: "make"
- id: isort
name: Isort - Sort Imports
entry: ./scripts/isort
- id: format
name: Code formatting
entry: ./scripts/format
language: system
types: [file, python]
exclude: "make"
- id: ruff
name: Ruff - Code Linter
entry: ./scripts/ruff --fix
- id: lint
name: Code linting
entry: ./scripts/lint --fix
language: system
types: [file, python]
exclude: "make"
- id: pyright
name: Pyright - Static types check
entry: ./scripts/pyright
- id: types
name: Static types check
entry: ./scripts/types
language: system
types: [file, python]
exclude: "(make|tests/|examples/)"
24 changes: 9 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ install: ## Installs the package, JS requirements, and build templates needed
build: ## Builds the package, and templates needed
@./scripts/build

lint: ## Runs a linting pipeline: black, isort, ruff, and mypy
@./scripts/lint

lint-fix: ## Runs a linting pipeline with auto fixing: black, isort, ruff, and mypy
@./scripts/lint --fix

test: ## Runs all tests of the repository
@./scripts/test

Expand All @@ -27,22 +21,22 @@ publish: ## Publishes the package in PiPy if user and passwords are correct
version: ## Gets the current version of the package
@./scripts/version

isort: ## Runs isort on Flama
@./scripts/isort .
format: ## Runs code formatting
@./scripts/format .

black: ## Runs black on Flama
@./scripts/black .
lint: ## Runs code linting
@./scripts/lint .

ruff: ## Runs ruff on Flama
@./scripts/ruff .
lint-fix: ## Runs code linting with autofixing
@./scripts/lint --fix .

pyright: ## Runs pyright on Flama
@./scripts/pyright
types: ## Runs static types checking
@./scripts/types

docker_push: ## Push docker images to registry
@./scripts/docker_push .

.PHONY: help check clean install build lint tests publish version isort black ruff pyright docker_push
.PHONY: help check clean install build tests publish version format lint lint-fix types docker_push
.DEFAULT_GOAL := help

help:
Expand Down
9 changes: 3 additions & 6 deletions examples/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def home():
error_app = flama.Router()


class FooException(Exception):
...
class FooException(Exception): ...


@error_app.route("/500")
Expand All @@ -56,13 +55,11 @@ def error_500():


@bar_app.route("/foobar/")
def foobar():
...
def foobar(): ...


@bar_app.route("/barfoo/")
def barfoo():
...
def barfoo(): ...


foo_app = flama.Router()
Expand Down
2 changes: 1 addition & 1 deletion flama/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

try:
from flama.resources.workers import FlamaWorker
except exceptions.DependencyNotInstalled:
except exceptions.DependencyNotInstalled: # pragma: no cover
FlamaWorker = None

if t.TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion flama/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async def resolve(self, receive: types.Receive) -> types.Body:
body = b""
while True:
message = await receive()
if not message["type"] == "http.request":
if not message["type"] == "http.request": # pragma: no cover
raise Exception(f"Unexpected ASGI message type '{message['type']}'.")
body += message.get("body", b"")
if not message.get("more_body", False):
Expand Down
18 changes: 6 additions & 12 deletions flama/authentication/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,22 @@
]


class AuthenticationException(Exception):
...
class AuthenticationException(Exception): ...


class Unauthorized(AuthenticationException):
...
class Unauthorized(AuthenticationException): ...


class Forbidden(AuthenticationException):
...
class Forbidden(AuthenticationException): ...


class JWTException(AuthenticationException):
...
class JWTException(AuthenticationException): ...


class JWTDecodeException(JWTException):
...
class JWTDecodeException(JWTException): ...


class JWTValidateException(JWTException):
...
class JWTValidateException(JWTException): ...


class JWTClaimValidateException(JWTValidateException):
Expand Down
4 changes: 2 additions & 2 deletions flama/authentication/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class AuthenticationMiddleware:
def __init__(self, app: "types.App"):
self.app: "Flama" = t.cast("Flama", app)
self.app: Flama = t.cast("Flama", app)

async def __call__(self, scope: "types.Scope", receive: "types.Receive", send: "types.Send") -> None:
if scope["type"] not in ("http", "websocket"):
Expand All @@ -34,7 +34,7 @@ def _get_permissions(self, route: "BaseRoute") -> set[str]:
return set(route.tags.get("permissions", []))

async def _get_response(self, scope: "types.Scope", receive: "types.Receive") -> t.Union["Response", "Flama"]:
app: "Flama" = scope["app"]
app: Flama = scope["app"]

route, _ = app.router.resolve_route(scope)

Expand Down
3 changes: 1 addition & 2 deletions flama/cli/config/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ class App(metaclass=abc.ABCMeta):
@property # type: ignore
@abc.abstractmethod
@contextlib.contextmanager
def context(self) -> t.Generator[_AppContext, None, None]:
...
def context(self) -> t.Generator[_AppContext, None, None]: ...

@classmethod
def build(cls, app: t.Union[str, dict[str, t.Any], "Flama"]) -> "App":
Expand Down
3 changes: 1 addition & 2 deletions flama/cli/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def build(cls, mode: str) -> "ExampleConfig":

@classmethod
@abc.abstractmethod
def dumps(cls) -> str:
...
def dumps(cls) -> str: ...


class SimpleExample(ExampleConfig):
Expand Down
8 changes: 4 additions & 4 deletions flama/cli/config/uvicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
click.option(
"--server-reload-dirs",
multiple=True,
help="Set reload directories explicitly, instead of using the current working" " directory.",
help="Set reload directories explicitly, instead of using the current working directory.",
type=click.Path(exists=True),
),
click.option(
Expand All @@ -70,7 +70,7 @@
type=float,
default=0.25,
show_default=True,
help="Delay between previous and next check if application needs to be." " Defaults to 0.25s.",
help="Delay between previous and next check if application needs to be. Defaults to 0.25s.",
),
click.option(
"--server-workers",
Expand Down Expand Up @@ -179,7 +179,7 @@
"--server-proxy-headers/--server-no-proxy-headers",
is_flag=True,
default=True,
help="Enable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to " "populate remote address info.",
help="Enable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to populate remote address info.",
),
click.option(
"--server-server-header/--server-no-server-header",
Expand Down Expand Up @@ -210,7 +210,7 @@
"--server-limit-concurrency",
type=int,
default=None,
help="Maximum number of concurrent connections or tasks to allow, before issuing" " HTTP 503 responses.",
help="Maximum number of concurrent connections or tasks to allow, before issuing HTTP 503 responses.",
),
click.option(
"--server-backlog",
Expand Down
9 changes: 3 additions & 6 deletions flama/codecs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@

class Codec(metaclass=abc.ABCMeta):
@abc.abstractmethod
async def decode(self, item: t.Any, **options) -> t.Any:
...
async def decode(self, item: t.Any, **options) -> t.Any: ...


class HTTPCodec(Codec):
media_type: t.Optional[str] = None

@abc.abstractmethod
async def decode(self, item: "http.Request", **options) -> t.Any:
...
async def decode(self, item: "http.Request", **options) -> t.Any: ...


class WebsocketsCodec(Codec):
encoding: t.Optional[str] = None

@abc.abstractmethod
async def decode(self, item: "types.Message", **options) -> t.Any:
...
async def decode(self, item: "types.Message", **options) -> t.Any: ...
Loading