Skip to content

Commit

Permalink
style: CI checkings
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmiguel committed Jan 23, 2024
1 parent abd4650 commit 2165182
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 29 deletions.
35 changes: 25 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,49 @@ repos:
- id: check-added-large-files
- repo: local
hooks:
- id: flake8
name: flake8
entry: flake8 missil sample tests
language: system
always_run: true
pass_filenames: false
- id: pyupgrade
name: pyupgrade
entry: pyupgrade missil/__init__.py missil/bearers.py missil/exceptions.py missil/jwt_utilities.py --py310-plus --py311-plus --py312-plus
language: system
always_run: true
pass_filenames: false
- id: black
name: black
entry: black missil tests
entry: black missil sample tests
language: system
always_run: true
pass_filenames: false
- id: refurb
name: refurb
entry: refurb missil sample tests
language: system
always_run: true
pass_filenames: false
- id: isort
name: isort
entry: isort missil tests
entry: isort missil sample tests
language: system
always_run: true
pass_filenames: false
- id: mypy
name: mypy
entry: mypy missil
language: system
always_run: true
pass_filenames: false
- id: flake8
name: flake8
entry: flake8 missil tests
entry: mypy missil sample
language: system
always_run: true
pass_filenames: false
- id: pydocstyle
name: pydocstyle
entry: pydocstyle missil
entry: pydocstyle missil sample
language: system
always_run: true
pass_filenames: false
- id: test
name: test
entry: pytest --cov=missil tests/

2 changes: 1 addition & 1 deletion missil/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Simple FastAPI declarative endpoint-level access control."""

from collections.abc import Callable
from typing import TYPE_CHECKING
from typing import Annotated
from typing import Any
from typing import Callable

from fastapi import Depends as FastAPIDependsFunc
from fastapi import status
Expand Down
2 changes: 1 addition & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ testing = [
dev = [
"uvicorn>=0.26.0",
"types-python-jose>=3.3.4.20240106",
"pre-commit>=3.6.0",
]
docs = [
"griffe-typingdoc>=0.2.4",
Expand All @@ -132,21 +133,27 @@ autoflake = { cmd = [
"--remove-unused-variables",
"--in-place",
"missil",
"sample",
"tests",
] }

flake8 = { cmd = ["flake8", "missil", "tests"] }
black = { cmd = ["black", "missil", "tests"] }
isort = { cmd = ["isort", "missil", "tests"] }
mypy = { cmd = ["mypy", "missil"] }
refurb = { cmd = ["refurb", "missil", "tests"] }
flake8 = { cmd = ["flake8", "missil", "sample", "tests"] }
black = { cmd = ["black", "missil", "sample", "tests"] }
isort = { cmd = ["isort", "missil", "sample", "tests"] }
mypy = { cmd = ["mypy", "missil", "sample"] }
refurb = { cmd = ["refurb", "missil", "sample", "tests"] }
pyupgrade = { cmd = [
"pyupgrade",
"missil/__init__.py",
"missil/bearers.py",
"missil/exceptions.py",
"missil/jwt_utilities.py",
"sample/main.py",
"--py310-plus",
"--py311-plus",
"--py312-plus"
] }
pydocstyle = { cmd = ["pydocstyle", "missil"] }
pydocstyle = { cmd = ["pydocstyle", "missil", "sample"] }
improve = { composite = ["flake8", "pyupgrade", "refurb"] }
format = { composite = ["autoflake", "black", "isort"] }
test = { cmd = ["pytest", "--cov=missil", "tests/"] }
Expand Down
16 changes: 9 additions & 7 deletions sample/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""Missil sample usage."""

import missil
from datetime import datetime
from datetime import timedelta
from datetime import timezone

from fastapi import FastAPI
from fastapi import Response

from typing import Union
from datetime import datetime
from datetime import timezone
from datetime import timedelta
import missil


app = FastAPI()

Expand All @@ -22,14 +22,14 @@


@app.get("/")
def read_root():
def read_root() -> dict[str, str]:
"""Just a humble and happy endpoint."""
return {"Hello": "World"}


@app.get("/set-cookies", status_code=200)
def set_cookies(response: Response) -> dict[str, str]:
"""Just for example purposes."""

claims = {
"username": "JohnDoe",
# the key 'userPermissions' name must be the same as in the
Expand All @@ -56,11 +56,13 @@ def set_cookies(response: Response) -> dict[str, str]:

@app.get("/finances/read", dependencies=[rules["finances:read"]])
def finances_read() -> dict[str, str]:
"""Requires read permission on finances."""
return {"msg": "you have permission to perform read actions on finances!"}


@app.get("/finances/write", dependencies=[rules["finances:write"]])
def finances_write() -> dict[str, str]:
"""Requires write permission on finances."""
return {"msg": "you have permission to perform write actions on finances!"}


Expand Down
4 changes: 1 addition & 3 deletions tests/test_jwt_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,5 @@ def test_decode_jwt_expired_token(secret_key, encoded_expired_jwt_token):

@ignore_warnings
def test_decode_jwt_invalid_token(secret_key, encoded_invalid_jwt_token):
with pytest.raises(
TokenErrorException, match="The token signature is invalid."
) as e:
with pytest.raises(TokenErrorException, match="The token signature is invalid."):
jwt_utilities.decode_jwt_token(encoded_invalid_jwt_token, secret_key)
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def ignore_warnings(f):
@wraps(f)
def inner(*args, **kwargs):
with warnings.catch_warnings(record=True) as w:
with warnings.catch_warnings(record=True) as _:
warnings.simplefilter("ignore")
response = f(*args, **kwargs)
return response
Expand Down

0 comments on commit 2165182

Please sign in to comment.