mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-09-21 13:12:24 +00:00
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
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
@@ -8,6 +6,8 @@ import zipfile
|
||||
|
||||
from typing import Any
|
||||
|
||||
import anyio
|
||||
|
||||
from fastapi import UploadFile
|
||||
|
||||
from backend.common.enums import PluginType, StatusType
|
||||
@@ -26,14 +26,10 @@ class PluginService:
|
||||
@staticmethod
|
||||
async def get_all() -> list[dict[str, Any]]:
|
||||
"""获取所有插件"""
|
||||
keys = []
|
||||
result = []
|
||||
|
||||
async for key in redis_client.scan_iter(f'{settings.PLUGIN_REDIS_PREFIX}:*'):
|
||||
keys.append(key)
|
||||
keys = [key async for key in redis_client.scan_iter(f'{settings.PLUGIN_REDIS_PREFIX}:*')]
|
||||
|
||||
for info in await redis_client.mget(*keys):
|
||||
result.append(json.loads(info))
|
||||
result = [json.loads(info) for info in await redis_client.mget(*keys)]
|
||||
|
||||
return result
|
||||
|
||||
@@ -61,24 +57,24 @@ class PluginService:
|
||||
return await install_git_plugin(repo_url)
|
||||
|
||||
@staticmethod
|
||||
async def uninstall(*, plugin: str):
|
||||
async def uninstall(*, plugin: str) -> None:
|
||||
"""
|
||||
卸载插件
|
||||
|
||||
:param plugin: 插件名称
|
||||
:return:
|
||||
"""
|
||||
plugin_dir = os.path.join(PLUGIN_DIR, plugin)
|
||||
if not os.path.exists(plugin_dir):
|
||||
plugin_dir = anyio.Path(PLUGIN_DIR / plugin)
|
||||
if not await plugin_dir.exists():
|
||||
raise errors.NotFoundError(msg='插件不存在')
|
||||
await uninstall_requirements_async(plugin)
|
||||
bacup_dir = os.path.join(PLUGIN_DIR, f'{plugin}.{timezone.now().strftime("%Y%m%d%H%M%S")}.backup')
|
||||
bacup_dir = PLUGIN_DIR / f'{plugin}.{timezone.now().strftime("%Y%m%d%H%M%S")}.backup'
|
||||
shutil.move(plugin_dir, bacup_dir)
|
||||
await redis_client.delete(f'{settings.PLUGIN_REDIS_PREFIX}:{plugin}')
|
||||
await redis_client.set(f'{settings.PLUGIN_REDIS_PREFIX}:changed', 'ture')
|
||||
|
||||
@staticmethod
|
||||
async def update_status(*, plugin: str):
|
||||
async def update_status(*, plugin: str) -> None:
|
||||
"""
|
||||
更新插件状态
|
||||
|
||||
@@ -107,8 +103,8 @@ class PluginService:
|
||||
:param plugin: 插件名称
|
||||
:return:
|
||||
"""
|
||||
plugin_dir = os.path.join(PLUGIN_DIR, plugin)
|
||||
if not os.path.exists(plugin_dir):
|
||||
plugin_dir = anyio.Path(PLUGIN_DIR / plugin)
|
||||
if not await plugin_dir.exists():
|
||||
raise errors.NotFoundError(msg='插件不存在')
|
||||
|
||||
bio = io.BytesIO()
|
||||
@@ -117,7 +113,7 @@ class PluginService:
|
||||
dirs[:] = [d for d in dirs if d != '__pycache__']
|
||||
for file in files:
|
||||
file_path = os.path.join(root, file)
|
||||
arcname = os.path.relpath(file_path, start=plugin_dir)
|
||||
arcname = os.path.relpath(file_path, start=plugin_dir) # noqa: ASYNC240
|
||||
zf.write(file_path, os.path.join(plugin, arcname))
|
||||
|
||||
bio.seek(0)
|
||||
|
||||
Reference in New Issue
Block a user