Skip to content

Commit 13fefe8

Browse files
authored
Merge pull request #9 from eadwinCode/linting_with_ruff
Linting with ruff
2 parents e220674 + bb53027 commit 13fefe8

File tree

8 files changed

+40
-23
lines changed

8 files changed

+40
-23
lines changed

.github/workflows/test_full.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
13+
python-version: ['3.8', '3.9', '3.10', '3.11']
1414

1515
steps:
1616
- uses: actions/checkout@v3
@@ -39,9 +39,7 @@ jobs:
3939
run: flit install --symlink
4040
- name: Black
4141
run: black --check ellar_throttler tests
42-
- name: isort
43-
run: isort --check ellar_throttler tests
44-
- name: Flake8
45-
run: flake8 ellar_throttler tests
42+
- name: Ruff Lint Check
43+
run: ruff check ellar_throttler tests
4644
- name: mypy
4745
run: mypy ellar_throttler

Makefile

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

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

2725
fmt format: ## Run code formatters
2826
black ellar_throttler tests
29-
isort ellar_throttler tests
27+
ruff check --fix ellar_throttler tests
3028

3129
test: ## Run tests
3230
pytest tests

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p align="center">
2-
<a href="#" target="blank"><img src="docs/img/EllarLogoIconOnly.png" width="200" alt="Ellar Logo" /></a>
2+
<a href="#" target="blank"><img src="https://eadwincode.github.io/ellar/img/EllarLogoB.png" width="200" alt="Ellar Logo" /></a>
33
</p>
44

5-
<p align="center">A rate limiting module for Ellar</p>
5+
<p align="center">Ellar - Python ASGI web framework for building fast, efficient and scalable RESTful APIs and server-side application.</p>
66

77
![Test](https://github.com/eadwinCode/ellar-throttler/actions/workflows/test_full.yml/badge.svg)
88
![Coverage](https://img.shields.io/codecov/c/github/eadwinCode/ellar-throttler)

ellar_throttler/exception.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class ThrottledException(APIException):
1111
extra_detail_singular = "Expected available in {wait} second."
1212
extra_detail_plural = "Expected available in {wait} seconds."
1313

14-
def __init__(self, wait: float = None, detail: t.Any = None) -> None:
14+
def __init__(
15+
self, wait: t.Optional[float] = None, detail: t.Optional[t.Any] = None
16+
) -> None:
1517
if detail is None:
1618
detail = self.default_detail
1719
if wait is not None:

ellar_throttler/module.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def setup(
1616
cls,
1717
ttl: int,
1818
limit: int,
19-
storage: t.Union[t.Type, t.Any] = None,
20-
skip_if: t.Callable[[IExecutionContext], bool] = None,
19+
storage: t.Union[t.Type, t.Any, None] = None,
20+
skip_if: t.Optional[t.Callable[[IExecutionContext], bool]] = None,
2121
) -> DynamicModule:
2222
if storage and isinstance(storage, IThrottlerStorage):
2323
_provider = ProviderConfig(IThrottlerStorage, use_value=storage)
@@ -28,7 +28,7 @@ def setup(
2828
IThrottlerStorage, use_class=ThrottlerStorageService
2929
)
3030

31-
return DynamicModule( # type:ignore
31+
return DynamicModule(
3232
cls,
3333
providers=[
3434
_provider,

ellar_throttler/throttler_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def storage(self) -> t.Any: # pragma: no cover
8484
return self._cache_service.get_backend()
8585

8686
async def get_expiration_time(self, key: str) -> int:
87-
result = await self._cache_service.get_async(f"{key}-ttl")
87+
result: int = await self._cache_service.get_async(f"{key}-ttl")
8888
return math.floor(result - time.time()) if result else -1
8989

9090
async def increment(self, key: str, ttl: int) -> ThrottlerStorageRecord:

pyproject.toml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ authors = [
1212
{name = "Ezeudoh Tochukwu", email = "[email protected]"},
1313
]
1414
dynamic = ["version", "description"]
15-
requires-python = ">=3.7"
15+
requires-python = ">=3.8"
1616
readme = "README.md"
1717
home-page = "https://github.com/eadwinCode/ellar-throttler"
1818
classifiers = [
@@ -29,7 +29,6 @@ classifiers = [
2929
"Intended Audience :: Developers",
3030
"License :: OSI Approved :: MIT License",
3131
"Programming Language :: Python :: 3",
32-
"Programming Language :: Python :: 3.7",
3332
"Programming Language :: Python :: 3.8",
3433
"Programming Language :: Python :: 3.9",
3534
"Programming Language :: Python :: 3.10",
@@ -54,13 +53,33 @@ Homepage = "https://eadwincode.github.io/ellar-throttler/"
5453
test = [
5554
"pytest >= 7.1.3,<8.0.0",
5655
"pytest-cov >= 2.12.0,<5.0.0",
57-
"mypy == 0.971",
58-
"flake8 >= 3.8.3,<7.0.0",
56+
"mypy == 1.4.1",
57+
"ruff ==0.0.275",
5958
"black ==22.8.0",
60-
"isort >=5.0.6,<6.0.0",
6159
"pytest-asyncio",
6260
"autoflake",
6361
]
6462
dev = [
6563
"pre-commit"
6664
]
65+
66+
[tool.ruff]
67+
select = [
68+
"E", # pycodestyle errors
69+
"W", # pycodestyle warnings
70+
"F", # pyflakes
71+
"I", # isort
72+
"C", # flake8-comprehensions
73+
"B", # flake8-bugbear
74+
]
75+
ignore = [
76+
"E501", # line too long, handled by black
77+
"B008", # do not perform function calls in argument defaults
78+
"C901", # too complex
79+
]
80+
81+
[tool.ruff.per-file-ignores]
82+
"__init__.py" = ["F401"]
83+
84+
[tool.ruff.isort]
85+
known-third-party = ["ellar",]

tests/test_throttler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_skip_configure(self):
9494
)
9595

9696
_client = test_module.get_test_client()
97-
for i in range(15):
97+
for _i in range(15):
9898
res = _client.get("/")
9999

100100
assert res.status_code == 200
@@ -115,7 +115,7 @@ class TestThrottlerStorageServiceConfiguration:
115115
ControllerModule,
116116
),
117117
global_guards=[ThrottlerGuard],
118-
config_module=dict(CACHES={"default": LocalMemCacheBackend()}),
118+
config_module={"CACHES": {"default": LocalMemCacheBackend()}},
119119
)
120120

121121
test_module_use_value = Test.create_test_module(

0 commit comments

Comments
 (0)