Skip to content

Commit 79ffcdc

Browse files
committed
fixed linting and add ruff
1 parent 2a4a720 commit 79ffcdc

File tree

6 files changed

+49
-28
lines changed

6 files changed

+49
-28
lines changed

.github/workflows/test_full.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ jobs:
3939
run: flit install --symlink
4040
- name: Black
4141
run: black --check ellar_jwt tests
42-
- name: isort
43-
run: isort --check ellar_jwt tests
44-
- name: Flake8
45-
run: flake8 ellar_jwt tests
42+
- name: Linting check
43+
run: ruff check ellar_jwt tests & ruff check tests
4644
- name: mypy
4745
run: mypy ellar_jwt

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ install-full: ## Install dependencies
1919

2020
lint: ## Run code linters
2121
black --check ellar_jwt tests
22-
isort --check ellar_jwt tests
23-
autoflake --remove-unused-variables --remove-unused-variables -r ellar_jwt tests
24-
flake8 ellar_jwt tests
22+
ruff check ellar_jwt
23+
ruff check tests
2524
mypy ellar_jwt
2625

2726
fmt format: ## Run code formatters
2827
black ellar_jwt tests
29-
isort ellar_jwt tests
28+
ruff check --fix ellar_jwt
29+
ruff check --fix tests
3030

3131
test: ## Run tests
3232
pytest tests

ellar_jwt/module.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ellar.core import Config, ModuleSetup
77
from ellar.core.modules import DynamicModule, ModuleBase
88
from ellar.di import ProviderConfig
9+
from pydantic import AnyHttpUrl
910

1011
from .schemas import JWTConfiguration
1112
from .services import JWTService
@@ -17,19 +18,19 @@ class JWTModule(ModuleBase, IModuleSetup):
1718
def setup(
1819
cls,
1920
signing_secret_key: str,
20-
verifying_secret_key: t.Optional[str] = "",
21+
verifying_secret_key: str = "",
2122
algorithm: str = "HS256",
22-
audience: str = None,
23-
issuer: str = None,
24-
jwk_url: str = None,
23+
audience: t.Optional[str] = None,
24+
issuer: t.Optional[str] = None,
25+
jwk_url: t.Optional[AnyHttpUrl] = None,
2526
leeway: t.Union[float, int, timedelta] = 0,
2627
jti: str = "jti",
27-
lifetime: timedelta = None,
28+
lifetime: t.Optional[timedelta] = None,
2829
json_encoder: t.Any = json.JSONEncoder,
2930
) -> DynamicModule:
3031
configuration = JWTConfiguration(
3132
signing_secret_key=signing_secret_key,
32-
algorithm=algorithm,
33+
algorithm=algorithm, # type: ignore[arg-type]
3334
audience=audience,
3435
issuer=issuer,
3536
jwk_url=jwk_url,

ellar_jwt/services.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def get_verifying_key(self, token: t.Any) -> bytes:
4444

4545
return self.jwt_config.verifying_secret_key.encode()
4646

47-
def sign(self, payload: dict, headers: t.Dict[str, t.Any] = None) -> str:
47+
def sign(
48+
self, payload: dict, headers: t.Optional[t.Dict[str, t.Any]] = None
49+
) -> str:
4850
"""
4951
Returns an encoded token for the given payload dictionary.
5052
"""
@@ -60,7 +62,7 @@ def sign(self, payload: dict, headers: t.Dict[str, t.Any] = None) -> str:
6062
)
6163

6264
async def sign_async(
63-
self, payload: dict, headers: t.Dict[str, t.Any] = None
65+
self, payload: dict, headers: t.Optional[t.Dict[str, t.Any]] = None
6466
) -> str:
6567
return await anyio.to_thread.run_sync(self.sign, payload, headers)
6668

pyproject.toml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,32 @@ Homepage = "https://eadwincode.github.io/ellar-jwt/"
6262
test = [
6363
"pytest >= 7.1.3,<8.0.0",
6464
"pytest-cov >= 2.12.0,<5.0.0",
65-
"mypy == 0.971",
66-
"flake8 >= 3.8.3,<7.0.0",
65+
"mypy == 1.4.1",
66+
"ruff ==0.0.275",
6767
"black == 22.8.0",
68-
"isort >=5.0.6,<6.0.0",
6968
"pytest-asyncio",
7069
"autoflake",
7170
"types-python-dateutil",
7271
"types-pytz"
7372
]
73+
74+
[tool.ruff]
75+
select = [
76+
"E", # pycodestyle errors
77+
"W", # pycodestyle warnings
78+
"F", # pyflakes
79+
"I", # isort
80+
"C", # flake8-comprehensions
81+
"B", # flake8-bugbear
82+
]
83+
ignore = [
84+
"E501", # line too long, handled by black
85+
"B008", # do not perform function calls in argument defaults
86+
"C901", # too complex
87+
]
88+
89+
[tool.ruff.per-file-ignores]
90+
"__init__.py" = ["F401"]
91+
92+
[tool.ruff.isort]
93+
known-third-party = ["ellar", "pydantic", "starlette"]

tests/test_module_options.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ def test_jwt_module_configuration_case_1():
3030
def test_jwt_module_configuration_case_2():
3131
tm = Test.create_test_module(
3232
modules=[JWTModule.register_setup()],
33-
config_module=dict(
34-
JWT_CONFIG=dict(
35-
algorithm="HS256",
36-
signing_secret_key="no_secret",
37-
issuer="https://ellar.com",
38-
lifetime=timedelta(minutes=30),
39-
leeway=None,
40-
)
41-
),
33+
config_module={
34+
"JWT_CONFIG": {
35+
"algorithm": "HS256",
36+
"signing_secret_key": "no_secret",
37+
"issuer": "https://ellar.com",
38+
"lifetime": timedelta(minutes=30),
39+
"leeway": None,
40+
}
41+
},
4242
)
4343
jwt_service: JWTService = tm.get(JWTService)
4444

0 commit comments

Comments
 (0)