Skip to content

Commit

Permalink
feat: optimize processes during api doc build workflow (#286)
Browse files Browse the repository at this point in the history
* workflow(build-api): optimize processes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix: using bash syntax

* fix: 'onebot11': No such file or directory

* style: update .pre-commit-config.yaml

* workflow(build-api): revert tags

* workflow: fix some warns

* style: format code

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
HsiangNianian and pre-commit-ci[bot] authored Aug 11, 2024
1 parent 7fda1e0 commit 2f9505b
Show file tree
Hide file tree
Showing 89 changed files with 714 additions and 829 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/build-api.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: api build

on:
pull_request:
push:
# tags:
# - "v*"
tags:
- "v*"
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -33,13 +34,10 @@ jobs:
# cd docs
# make api build
rm -rf docs/source/pages/api
cp -r packages/iamai-adapter-apscheduler/iamai/adapter/apscheduler iamai/adapter/apscheduler
cp -r packages/iamai-adapter-bililive/iamai/adapter/bililive iamai/adapter/bililive
cp -r packages/iamai-adapter-console/iamai/adapter/console iamai/adapter/console
cp -r packages/iamai-adapter-gensokyo/iamai/adapter/gensokyo iamai/adapter/gensokyo
cp -r packages/iamai-adapter-kook/iamai/adapter/kook iamai/adapter/kook
cp -r packages/iamai-adapter-cqhttp/iamai/adapter/cqhttp iamai/adapter/cqhttp
cp -r packages/iamai-adapter-red/iamai/adapter/red iamai/adapter/red
for adapter in apscheduler bililive console cqhttp dingtalk gensokyo kook red
do
cp -r "packages/iamai-adapter-$adapter/iamai/adapter/$adapter" "iamai/adapter/$adapter"
done
pdm run sphinx-apidoc -o docs/source/pages/api iamai packages -f -e --tocfile index
shell: bash
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main
- master
tags:
- '*'
- 'v*'
pull_request:
workflow_dispatch:

Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.7
rev: v0.3.5
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- id: ruff-check
args: [--unsafe-fixes, --add-noqa]
1 change: 0 additions & 1 deletion build_credit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import pathlib

import httpx
from python_graphql_client import GraphqlClient

root = pathlib.Path(__file__).parent.resolve()
Expand Down
9 changes: 4 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import iamai
import os, sys
import os
import sys

if sys.version_info >= (3, 11):
import tomllib
Expand Down Expand Up @@ -102,9 +102,8 @@
#
# Note: this file shouldn't rely on extra dependencies.

import importlib
import sys
import os.path
import sys # noqa: E402
import os.path # noqa: E402

# User's Sphinx configurations
language_user = globals().get("language", None)
Expand Down
2 changes: 0 additions & 2 deletions examples/plugins/_eval_kook.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from iamai.adapter.kook.message import (
KookMessage,
KookMessageSegment,
escape_kmarkdown,
unescape_kmarkdown,
)

documents = [
Expand Down
3 changes: 1 addition & 2 deletions examples/plugins/_hello_kook.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from iamai import Plugin
from iamai.log import logger
from iamai.adapter.kook.message import KookMessage, KookMessageSegment
from iamai.adapter.kook.message import KookMessageSegment


class HalloKook(Plugin):
Expand Down
3 changes: 0 additions & 3 deletions examples/plugins/_send_message_bililive.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import time

from iamai import Plugin
from iamai.log import logger
from iamai.adapter.apscheduler import scheduler_decorator


Expand Down
2 changes: 1 addition & 1 deletion iamai/adapter/apscheduler/apscheduler/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from iamai.plugin import Plugin

if TYPE_CHECKING:
from . import APSchedulerAdapter
pass


__all__ = ["APSchedulerEvent"]
Expand Down
2 changes: 1 addition & 1 deletion iamai/adapter/apscheduler/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from iamai.plugin import Plugin

if TYPE_CHECKING:
from . import APSchedulerAdapter
pass


__all__ = ["APSchedulerEvent"]
Expand Down
46 changes: 23 additions & 23 deletions iamai/adapter/bililive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@
"""

import os
import re
import re # noqa: F401
import sys
import json
import time
import zlib
import struct
import asyncio
from math import log
from math import log # noqa: F401
from functools import partial
from abc import abstractmethod
from collections import namedtuple
from os.path import join, split, abspath, dirname
from typing import TYPE_CHECKING, Any, Dict, NamedTuple
from os.path import join, split, abspath, dirname # noqa: F401
from typing import TYPE_CHECKING, Any, Dict, NamedTuple # noqa: F401

import qrcode
import aiohttp
from genericpath import exists
from aiohttp.client import ClientSession

from iamai.utils import DataclassEncoder
from iamai.utils import DataclassEncoder # noqa: F401
from iamai.adapter.utils import WebSocketAdapter
from iamai.log import logger, error_or_exception

from .event import *
from .message import *
from .event import * # noqa: F403
from .message import * # noqa: F403
from .config import Config
from .event import get_event_class

if TYPE_CHECKING:
from .message import T_BililiveMSG
from .message import T_BililiveMSG # noqa: F401

__all__ = ["BililiveAdapter"]

Expand Down Expand Up @@ -80,7 +80,7 @@
user_cookies = aiohttp.cookiejar.CookieJar()


class BililiveAdapter(WebSocketAdapter[BililiveEvent, Config]):
class BililiveAdapter(WebSocketAdapter[BililiveEvent, Config]): # noqa: F405
"""bililive 协议适配器。"""

name: str = "bililive"
Expand Down Expand Up @@ -115,7 +115,7 @@ async def startup(self):
self.cookies = json.load(f)
user_cookies.update_cookies(self.cookies)
if self.config.login: # type: ignore
logger.debug(f"Login enabled!")
logger.debug("Login enabled!")
try:
# 尝试登陆
async with ClientSession(cookie_jar=user_cookies) as self.session:
Expand All @@ -125,9 +125,9 @@ async def startup(self):
self._uid = get_cookies("DedeUserID")
self.jct = get_cookies("bili_jct")

if self._uid == None or self.jct == None:
if self._uid == None or self.jct == None: # noqa: E711
logger.error(
f"Unable to get cookies, please check your cookies."
"Unable to get cookies, please check your cookies."
)
return
if not exists(_path):
Expand All @@ -143,7 +143,7 @@ async def startup(self):
logger.error(e)
return
else:
logger.debug(f"Login disabled!")
logger.debug("Login disabled!")
await super().startup()

async def websocket_connect(self):
Expand Down Expand Up @@ -183,7 +183,7 @@ async def handle_websocket_msg(self, msg: aiohttp.WSMessage):
header = HeaderTuple(*HEADER_STRUCT.unpack_from(data, offset))
except struct.error:
break
if header.operation == Operation.HEARTBEAT_REPLY:
if header.operation == Operation.HEARTBEAT_REPLY: # noqa: F405
popularity = int.from_bytes(
data[
offset + HEADER_STRUCT.size : offset
Expand All @@ -193,7 +193,7 @@ async def handle_websocket_msg(self, msg: aiohttp.WSMessage):
"big",
)
await self._on_receive_popularity(popularity)
elif header.operation == Operation.SEND_MSG_REPLY:
elif header.operation == Operation.SEND_MSG_REPLY: # noqa: F405
body = data[
offset + HEADER_STRUCT.size : offset + header.pack_len
]
Expand All @@ -219,9 +219,9 @@ async def handle_websocket_msg(self, msg: aiohttp.WSMessage):
logger.debug(f"body: {body}")
raise

elif header.operation == Operation.AUTH_REPLY:
elif header.operation == Operation.AUTH_REPLY: # noqa: F405
await self.websocket.send_bytes(
self._make_packet({}, Operation.HEARTBEAT)
self._make_packet({}, Operation.HEARTBEAT) # noqa: F405
)

else:
Expand Down Expand Up @@ -270,7 +270,7 @@ async def _send_auth(self):
"clientver": "1.14.3",
"type": 2,
}
await self.websocket.send_bytes(self._make_packet(auth_params, Operation.AUTH))
await self.websocket.send_bytes(self._make_packet(auth_params, Operation.AUTH)) # noqa: F405

@staticmethod
def _make_packet(data, operation):
Expand All @@ -291,7 +291,7 @@ async def _start_heartbeat(self) -> None:
if self.websocket.closed:
break
await self.websocket.send_bytes(bytes.fromhex(hb))
logger.debug(f"HeartBeat sent!")
logger.debug("HeartBeat sent!")
await asyncio.sleep(29)
except Exception as e:
logger.error(e)
Expand Down Expand Up @@ -327,7 +327,7 @@ async def send(
danmaku: str,
fontsize: int = 25,
color: int = 0xFFFFFF,
pos: DanmakuPosition = DanmakuPosition.NORMAL,
pos: DanmakuPosition = DanmakuPosition.NORMAL, # noqa: F405
) -> bool:
# don't know what the hell is bubble
return await self.send_danmu(
Expand Down Expand Up @@ -361,13 +361,13 @@ def rawData_to_jsonData(data: bytes):
try:
jd = json.loads(data[16:].decode("utf-8", errors="ignore"))
return jd
except Exception as e:
except Exception:
pass


async def login(session: ClientSession) -> bool:
if get_cookies("bili_jct") != None:
logger.info(f"Aleady login!")
if get_cookies("bili_jct") != None: # noqa: E711
logger.info("Aleady login!")
return True
try:
res = await _get(session, QRCODE_REQUEST_URL)
Expand Down
2 changes: 1 addition & 1 deletion iamai/adapter/bililive/api/blivedm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# code from xfgryujk
from abc import abstractmethod
from collections import namedtuple
from typing import * # ??这是什么粗暴的import方式
from typing import * # ??这是什么粗暴的import方式 # noqa: F403

import aiohttp

Expand Down
Loading

0 comments on commit 2f9505b

Please sign in to comment.