Skip to content

Commit 5762834

Browse files
authored
Update the ruff rules and format the code (#846)
* Update the ruff rules and format the code * Update the per-file-ignores * Update the ci * Update rules * Fix codes * Fix pagination * Update rules
1 parent 5135459 commit 5762834

File tree

269 files changed

+975
-1198
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+975
-1198
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
name: lint ${{ matrix.python-version }}
1313
strategy:
1414
matrix:
15-
python-version: [ '3.10', '3.11', '3.12', '3.13' ]
15+
python-version: [ '3.10', '3.11', '3.12', '3.13', '3.14' ]
1616
fail-fast: false
1717
steps:
1818
- uses: actions/checkout@v4

.ruff.toml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
line-length = 120
2+
preview = true
3+
fix = true
4+
unsafe-fixes = true
5+
show-fixes = true
6+
required-version = ">=0.13.0"
7+
8+
[lint]
9+
select = [
10+
"FAST",
11+
"ANN001",
12+
"ANN201",
13+
"ANN202",
14+
"ANN204",
15+
"ANN205",
16+
"ANN206",
17+
"ASYNC110",
18+
"ASYNC116",
19+
"ASYNC210",
20+
"ASYNC212",
21+
"ASYNC230",
22+
"ASYNC240",
23+
"ASYNC250",
24+
"ASYNC251",
25+
"S310",
26+
"FBT001",
27+
"FBT002",
28+
"B002",
29+
"B005",
30+
"B006",
31+
"B007",
32+
"B008",
33+
"B009",
34+
"B010",
35+
"B013",
36+
"B014",
37+
"B019",
38+
"B020",
39+
"B021",
40+
"B024",
41+
"B025",
42+
"B026",
43+
"B027",
44+
"B039",
45+
"COM",
46+
"C402",
47+
"C403",
48+
"C404",
49+
"C408",
50+
"C410",
51+
"C411",
52+
"C414",
53+
"C416",
54+
"C417",
55+
"C418",
56+
"C419",
57+
"C420",
58+
"DTZ",
59+
"EXE",
60+
"ISC001",
61+
"ISC002",
62+
"ISC003",
63+
"PIE",
64+
"PYI009",
65+
"PYI010",
66+
"PYI011",
67+
"PYI012",
68+
"PYI013",
69+
"PYI016",
70+
"PYI017",
71+
"PYI019",
72+
"PYI020",
73+
"PYI021",
74+
"PYI024",
75+
"PYI026",
76+
"PYI030",
77+
"PYI033",
78+
"PYI034",
79+
"PYI036",
80+
"PYI041",
81+
"PYI042",
82+
"PYI055",
83+
"PYI061",
84+
"PYI062",
85+
"PYI063",
86+
"Q001",
87+
"Q002",
88+
"RSE102",
89+
"RET501",
90+
"RET505",
91+
"RET506",
92+
"RET507",
93+
"RET508",
94+
"SIM101",
95+
"SIM102",
96+
"SIM103",
97+
"SIM107",
98+
"SIM108",
99+
"SIM109",
100+
"SIM110",
101+
"SIM114",
102+
"SIM115",
103+
"SIM201",
104+
"SIM202",
105+
"SIM210",
106+
"SIM211",
107+
"SIM212",
108+
"SIM300",
109+
"SIM401",
110+
"SIM910",
111+
"TID252",
112+
"TC",
113+
"FLY",
114+
"I",
115+
"C901",
116+
"N",
117+
"PERF",
118+
"E",
119+
"W",
120+
"D404",
121+
"D417",
122+
"D419",
123+
"F",
124+
"PGH",
125+
"PLC1901",
126+
"UP",
127+
"FURB",
128+
"RUF",
129+
"TRY",
130+
]
131+
ignore = [
132+
"COM812",
133+
"PGH003",
134+
"RUF001",
135+
"RUF002",
136+
"RUF003",
137+
"RUF006",
138+
"RUF012",
139+
"TRY400",
140+
"TRY003",
141+
"TRY301"
142+
]
143+
144+
[lint.per-file-ignores]
145+
"**/model/*.py" = ["TC003"]
146+
"backend/common/socketio/server.py" = ["ANN001"]
147+
"backend/common/exception/exception_handler.py" = ["ANN202","RUF029"]
148+
149+
[lint.flake8-pytest-style]
150+
parametrize-names-type = "list"
151+
parametrize-values-row-type = "list"
152+
parametrize-values-type = "list"
153+
154+
[lint.flake8-quotes]
155+
inline-quotes = "single"
156+
157+
[lint.flake8-type-checking]
158+
runtime-evaluated-base-classes = ["pydantic.BaseModel", "sqlalchemy.orm.DeclarativeBase"]
159+
160+
[lint.flake8-unused-arguments]
161+
ignore-variadic-names = true
162+
163+
[lint.isort]
164+
case-sensitive = true
165+
lines-between-types = 1
166+
order-by-type = true
167+
168+
[lint.pylint]
169+
allow-dunder-method-names = ["__tablename__", "__table_args__"]
170+
171+
[format]
172+
docstring-code-format = true
173+
preview = true
174+
quote-style = "single"

backend/.ruff.toml

Lines changed: 0 additions & 55 deletions
This file was deleted.

backend/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
31
from backend.common.i18n import i18n
42

53
__version__ = '1.8.2'

backend/alembic/env.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
3-
# ruff: noqa: F403, F401, I001, RUF100
41
import asyncio
52
import os
3+
64
from logging.config import fileConfig
75

86
from alembic import context
@@ -40,11 +38,12 @@
4038

4139
# other values from the config, defined by the needs of env.py,
4240
alembic_config.set_main_option(
43-
'sqlalchemy.url', SQLALCHEMY_DATABASE_URL.render_as_string(hide_password=False).replace('%', '%%')
41+
'sqlalchemy.url',
42+
SQLALCHEMY_DATABASE_URL.render_as_string(hide_password=False).replace('%', '%%'),
4443
)
4544

4645

47-
def run_migrations_offline():
46+
def run_migrations_offline() -> None:
4847
"""Run migrations in 'offline' mode.
4948
5049
This configures the context with just a URL
@@ -73,7 +72,7 @@ def run_migrations_offline():
7372

7473
def do_run_migrations(connection: Connection) -> None:
7574
# 当迁移无变化时,不生成迁移记录
76-
def process_revision_directives(context, revision, directives):
75+
def process_revision_directives(context, revision, directives) -> None: # noqa: ANN001
7776
if alembic_config.cmd_opts.autogenerate:
7877
script = directives[0]
7978
if script.upgrade_ops.is_empty():

backend/app/__init__.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
31
import os.path
42

53
from backend.core.path_conf import BASE_PATH
@@ -8,14 +6,10 @@
86

97
def get_app_models() -> list[type]:
108
"""获取 app 所有模型类"""
11-
app_path = os.path.join(BASE_PATH, 'app')
9+
app_path = BASE_PATH / 'app'
1210
list_dirs = os.listdir(app_path)
1311

14-
apps = []
15-
16-
for d in list_dirs:
17-
if os.path.isdir(os.path.join(app_path, d)) and d != '__pycache__':
18-
apps.append(d)
12+
apps = [d for d in list_dirs if os.path.isdir(os.path.join(app_path, d)) and d != '__pycache__']
1913

2014
objs = []
2115

backend/app/admin/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-

backend/app/admin/api/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-

backend/app/admin/api/router.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
31
from fastapi import APIRouter
42

53
from backend.app.admin.api.v1.auth import router as auth_router
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-

0 commit comments

Comments
 (0)