Skip to content

Commit 5b09237

Browse files
committed
add black support
1 parent 28916cc commit 5b09237

File tree

22 files changed

+91
-120
lines changed

22 files changed

+91
-120
lines changed

.pre-commit-config.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,16 @@ repos:
1010
rev: v0.0.262
1111
hooks:
1212
- id: ruff
13-
args: [ '--config', '.ruff.toml' ]
13+
args:
14+
- '--config'
15+
- '.ruff.toml'
16+
- '--fix'
17+
- repo: https://github.com/psf/black
18+
rev: 23.3.0
19+
hooks:
20+
- id: black
21+
language_version: python3.8
22+
args:
23+
- '--skip-string-normalization'
24+
- '--line-length'
25+
- '120'

backend/app/api/service/user_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515

1616
class UserService:
17-
1817
@staticmethod
1918
async def login(form_data: OAuth2PasswordRequestForm):
2019
async with async_db_session() as db:

backend/app/api/v1/task_demo.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,28 @@ async def task_demo_async():
2222
async def task_demo_get():
2323
tasks = []
2424
for job in scheduler.get_jobs():
25-
tasks.append({
26-
"id": job.id,
27-
"func_name": job.func_ref,
28-
"trigger": str(job.trigger),
29-
"executor": job.executor,
30-
# "args": str(job.args),
31-
# "kwargs": job.kwargs,
32-
"name": job.name,
33-
"misfire_grace_time": job.misfire_grace_time,
34-
"coalesce": job.coalesce,
35-
"max_instances": job.max_instances,
36-
"next_run_time": job.next_run_time,
37-
})
25+
tasks.append(
26+
{
27+
"id": job.id,
28+
"func_name": job.func_ref,
29+
"trigger": str(job.trigger),
30+
"executor": job.executor,
31+
# "args": str(job.args),
32+
# "kwargs": job.kwargs,
33+
"name": job.name,
34+
"misfire_grace_time": job.misfire_grace_time,
35+
"coalesce": job.coalesce,
36+
"max_instances": job.max_instances,
37+
"next_run_time": job.next_run_time,
38+
}
39+
)
3840
return {'msg': 'success', 'data': tasks}
3941

4042

4143
@router.post('', summary='添加同步任务')
4244
async def task_demo_add():
4345
scheduler.add_job(
44-
task_demo,
45-
'interval',
46-
seconds=1,
47-
id='task_demo',
48-
replace_existing=True,
49-
start_date=datetime.datetime.now()
46+
task_demo, 'interval', seconds=1, id='task_demo', replace_existing=True, start_date=datetime.datetime.now()
5047
)
5148

5249
return {'msg': 'success'}
@@ -60,7 +57,7 @@ async def task_demo_add_async():
6057
seconds=1,
6158
id='task_demo_async',
6259
replace_existing=True,
63-
start_date=datetime.datetime.now()
60+
start_date=datetime.datetime.now(),
6461
)
6562

6663
return {'msg': 'success'}

backend/app/common/enums.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class EnumBase(Enum):
7-
87
@classmethod
98
def get_member_values(cls):
109
return [item.value for item in cls._member_map_.values()]
@@ -16,9 +15,11 @@ def get_member_names(cls):
1615

1716
class IntEnum(int, EnumBase):
1817
"""整型枚举"""
18+
1919
pass
2020

2121

2222
class StrEnum(str, EnumBase):
2323
"""字符串枚举"""
24+
2425
pass

backend/app/common/exception/errors.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def __init__(self, *, msg: str = 'Bad Gateway', data: Any = None):
5555

5656

5757
class CodeError(BaseExceptionMixin):
58-
5958
def __init__(self, *, error: CodeEnum, data: Any = None):
6059
self.code = error.code
6160
super().__init__(msg=error.msg, data=data)

backend/app/common/exception/exception_handler.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def http_exception_handler(request: Request, exc: HTTPException): # noqa
4747
return JSONResponse(
4848
status_code=_get_exception_code(exc.status_code),
4949
content=response_base.fail(code=exc.status_code, msg=exc.detail),
50-
headers=exc.headers
50+
headers=exc.headers,
5151
)
5252

5353
@app.exception_handler(Exception)
@@ -81,24 +81,21 @@ def all_exception_handler(request: Request, exc): # noqa
8181
status_code=422,
8282
content=response_base.fail(
8383
msg='请求参数非法' if len(message) == 0 else f'请求参数非法:{message[:-1]}',
84-
data={'errors': exc.errors()} if message == '' and settings.UVICORN_RELOAD is True else None
85-
)
84+
data={'errors': exc.errors()} if message == '' and settings.UVICORN_RELOAD is True else None,
85+
),
8686
)
8787

8888
# 自定义
8989
if isinstance(exc, BaseExceptionMixin):
9090
return JSONResponse(
9191
status_code=_get_exception_code(exc.code),
92-
content=response_base.fail(
93-
code=exc.code,
94-
msg=str(exc.msg),
95-
data=exc.data if exc.data else None
96-
)
92+
content=response_base.fail(code=exc.code, msg=str(exc.msg), data=exc.data if exc.data else None),
9793
)
9894

9995
else:
10096
return JSONResponse(
10197
status_code=500,
102-
content=response_base.fail(code=500, msg=str(exc)) if settings.UVICORN_RELOAD else
103-
response_base.fail(code=500, msg='Internal Server Error')
98+
content=response_base.fail(code=500, msg=str(exc))
99+
if settings.UVICORN_RELOAD
100+
else response_base.fail(code=500, msg='Internal Server Error'),
104101
)

backend/app/common/log.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212

1313
class Logger:
14-
1514
@staticmethod
1615
def log() -> loguru.Logger:
1716
if not os.path.exists(path_conf.LogPath):

backend/app/common/pagination.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class Page(AbstractPage[T], Generic[T]):
4141

4242
@classmethod
4343
def create(
44-
cls,
45-
data: Sequence[T],
46-
total: int,
47-
params: Params,
44+
cls,
45+
data: Sequence[T],
46+
total: int,
47+
params: Params,
4848
) -> Page[T]:
4949
page = params.page
5050
size = params.size
@@ -54,15 +54,8 @@ def create(
5454
"first": {"page": 1, "size": f"{size}"},
5555
"last": {"page": f"{math.ceil(total / params.size)}", "size": f"{size}"} if total > 0 else None,
5656
"next": {"page": f"{page + 1}", "size": f"{size}"} if (page + 1) <= total_pages else None,
57-
"prev": {"page": f"{page - 1}", "size": f"{size}"} if (page - 1) >= 1 else None
57+
"prev": {"page": f"{page - 1}", "size": f"{size}"} if (page - 1) >= 1 else None,
5858
}
5959
).dict()
6060

61-
return cls(
62-
data=data,
63-
total=total,
64-
page=params.page,
65-
size=params.size,
66-
total_pages=total_pages,
67-
links=links
68-
)
61+
return cls(data=data, total=total, page=params.page, size=params.size, total_pages=total_pages, links=links)

backend/app/common/redis.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99

1010

1111
class RedisCli(Redis):
12-
1312
def __init__(self):
1413
super(RedisCli, self).__init__(
1514
host=settings.REDIS_HOST,
1615
port=settings.REDIS_PORT,
1716
password=settings.REDIS_PASSWORD,
1817
db=settings.REDIS_DATABASE,
1918
socket_timeout=settings.REDIS_TIMEOUT,
20-
decode_responses=True # 转码 utf-8
19+
decode_responses=True, # 转码 utf-8
2120
)
2221

2322
async def open(self):

backend/app/common/response/response_code.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class CodeEnum(Enum):
77
"""
88
错误码
99
"""
10+
1011
CAPTCHA_ERROR = (40001, '图形验证码错误')
1112

1213
@property

0 commit comments

Comments
 (0)