🧑‍💻 使用 Ruff 包办所有格式化和检查 (#663)

This commit is contained in:
Azide
2024-12-17 10:52:21 +08:00
committed by GitHub
parent af1609730c
commit 08ad5c288c
126 changed files with 875 additions and 933 deletions
+2 -3
View File
@@ -1,10 +1,9 @@
from importlib import import_module
from pathlib import Path
from pkgutil import iter_modules
from importlib import import_module
from .types import Theme
from .registry import theme_manager
from .types import ThemeRegistrationError
from .types import Theme, ThemeRegistrationError
from .types import ThemeRenderError as ThemeRenderError
from .types import ThemeRenderUnsupportError as ThemeRenderUnsupportError
+5 -2
View File
@@ -1,11 +1,14 @@
from typing import ClassVar
from nonebot import logger
from ..plugin_config import plugin_config
from nonebot_bison.plugin_config import plugin_config
from .types import Theme, ThemeRegistrationError
class ThemeManager:
__themes: dict[str, Theme] = {}
__themes: ClassVar[dict[str, Theme]] = {}
def register(self, theme: Theme):
logger.trace(f"Registering theme: {theme}")
@@ -1,13 +1,13 @@
from dataclasses import dataclass
from io import BytesIO
from pathlib import Path
from dataclasses import dataclass
from typing import TYPE_CHECKING, Literal
from nonebot_plugin_saa import Text, Image, MessageSegmentFactory
from nonebot_plugin_saa import Image, MessageSegmentFactory, Text
from nonebot_bison.utils import text_fletten
from nonebot_bison.theme.utils import web_embed_image
from nonebot_bison.theme import Theme, ThemeRenderError, ThemeRenderUnsupportError
from nonebot_bison.theme.utils import web_embed_image
from nonebot_bison.utils import text_fletten
if TYPE_CHECKING:
from nonebot_bison.platform.arknights import ArknightsPost
+4 -3
View File
@@ -1,11 +1,12 @@
from collections.abc import Sequence
from io import BytesIO
from pathlib import Path
from typing import TYPE_CHECKING, Literal
from nonebot_plugin_saa import Text, Image, MessageSegmentFactory
from nonebot_plugin_saa import Image, MessageSegmentFactory, Text
from nonebot_bison.theme import Theme
from nonebot_bison.utils import pic_merge, is_pics_mergable
from nonebot_bison.utils import is_pics_mergable, pic_merge
if TYPE_CHECKING:
from nonebot_bison.post import Post
@@ -50,7 +51,7 @@ class BasicTheme(Theme):
client = await post.platform.ctx.get_client_for_static()
msgs: list[MessageSegmentFactory] = [Text(text)]
pics_group: list[list[str | bytes | Path | BytesIO]] = []
pics_group: list[Sequence[str | bytes | Path | BytesIO]] = []
if post.images:
pics_group.append(post.images)
if rp and rp.images:
+2 -2
View File
@@ -1,9 +1,9 @@
from typing import TYPE_CHECKING, Literal
from nonebot_plugin_saa import Text, Image, MessageSegmentFactory
from nonebot_plugin_saa import Image, MessageSegmentFactory, Text
from nonebot_bison.utils import pic_merge, is_pics_mergable
from nonebot_bison.theme import Theme, ThemeRenderUnsupportError
from nonebot_bison.utils import is_pics_mergable, pic_merge
if TYPE_CHECKING:
from nonebot_bison.post import Post
@@ -1,19 +1,20 @@
from collections.abc import Sequence
from datetime import datetime
from io import BytesIO
from pathlib import Path
from datetime import datetime
from typing import TYPE_CHECKING, Literal
import jinja2
from yarl import URL
from httpx import AsyncClient
from pydantic import BaseModel
import jinja2
from nonebot_plugin_saa import Image, MessageSegmentFactory, Text
from PIL import Image as PILImage
from nonebot_plugin_saa import Text, Image, MessageSegmentFactory
from pydantic import BaseModel
from yarl import URL
from nonebot_bison.compat import model_validator
from nonebot_bison.utils import pic_merge, is_pics_mergable
from nonebot_bison.theme.utils import convert_to_qr, web_embed_image
from nonebot_bison.theme import Theme, ThemeRenderError, ThemeRenderUnsupportError
from nonebot_bison.theme.utils import convert_to_qr, web_embed_image
from nonebot_bison.utils import is_pics_mergable, pic_merge
if TYPE_CHECKING:
from nonebot_bison.post import Post
@@ -122,7 +123,7 @@ class CeobeCanteenTheme(Theme):
@staticmethod
async def merge_pics(
images: list[str | bytes | Path | BytesIO],
images: Sequence[str | bytes | Path | BytesIO],
client: AsyncClient,
) -> list[str | bytes | Path | BytesIO]:
if is_pics_mergable(images):
@@ -224,7 +225,7 @@ class CeobeCanteenTheme(Theme):
text += f"详情: {post.url}"
msgs.append(Text(text))
pics_group: list[list[str | bytes | Path | BytesIO]] = []
pics_group: list[Sequence[str | bytes | Path | BytesIO]] = []
if post.images:
pics_group.append(post.images)
if post.repost and post.repost.images:
+6 -8
View File
@@ -1,12 +1,13 @@
from collections.abc import Sequence
from io import BytesIO
from pathlib import Path
from typing import TYPE_CHECKING, Literal
from nonebot_plugin_saa import Text, Image, MessageSegmentFactory
from nonebot_plugin_saa import Image, MessageSegmentFactory, Text
from nonebot_bison.theme import Theme, ThemeRenderError
from nonebot_bison.post.protocol import HTMLContentSupport
from nonebot_bison.utils import pic_merge, is_pics_mergable
from nonebot_bison.theme import Theme, ThemeRenderError
from nonebot_bison.utils import is_pics_mergable, pic_merge
if TYPE_CHECKING:
from nonebot_bison.post import Post
@@ -31,7 +32,6 @@ class Ht2iTheme(Theme):
raise ThemeRenderError(f"渲染文本失败: {e}")
async def render(self, post: "Post"):
md_text = ""
md_text += f"## {post.title}\n\n" if post.title else ""
@@ -50,9 +50,7 @@ class Ht2iTheme(Theme):
else:
rp_content = await rp.get_content()
md_text += (
"> \n> " + rp_content if len(rp_content) < 500 else f"{rp_content[:500]}..." + " \n" # noqa: E501
) # noqa: E501
md_text += "> \n> " + rp_content if len(rp_content) < 500 else f"{rp_content[:500]}..." + " \n"
md_text += "\n\n"
md_text += f"###### 来源: {post.platform.name} {post.nickname or ''}\n"
@@ -68,7 +66,7 @@ class Ht2iTheme(Theme):
if urls:
msgs.append(Text("\n".join(urls)))
pics_group: list[list[str | bytes | Path | BytesIO]] = []
pics_group: list[Sequence[str | bytes | Path | BytesIO]] = []
if post.images:
pics_group.append(post.images)
if rp and rp.images:
+4 -4
View File
@@ -1,14 +1,14 @@
from typing import TYPE_CHECKING
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
from nonebot import logger, require
from pydantic import BaseModel, PrivateAttr
from nonebot_plugin_saa import MessageSegmentFactory
from pydantic import BaseModel, PrivateAttr
from ..plugin_config import plugin_config
from nonebot_bison.plugin_config import plugin_config
if TYPE_CHECKING:
from ..post.abstract_post import AbstractPost
from nonebot_bison.post.abstract_post import AbstractPost
class Theme(ABC, BaseModel):
+2 -2
View File
@@ -1,10 +1,10 @@
from base64 import b64encode
from io import BytesIO
from pathlib import Path
from base64 import b64encode
from qrcode import constants
from qrcode.main import QRCode
from qrcode.image.pil import PilImage
from qrcode.main import QRCode
def convert_to_qr(data: str, **kwarg) -> bytes: