style: introduce ruff as linter and formatter (#1356)

* style: remove necessary imports

* style: fix F841

* style: fix F401

* style: fix F811

* style: fix E402

* style: fix E721

* style: fix E722

* style: fix E722

* style: fix F541

* style: ruff format

* style: all passed

* style: add ruff in deps

* style: more ignores in ruff.toml

* style: add pre-commit
This commit is contained in:
Junyan Qin (Chin)
2025-04-29 17:24:07 +08:00
committed by GitHub
parent 09e70d70e9
commit 209f16af76
240 changed files with 5307 additions and 4689 deletions

29
main.py
View File

@@ -1,3 +1,4 @@
import asyncio
# LangBot 终端启动入口
# 在此层级解决依赖项检查。
# LangBot/main.py
@@ -14,9 +15,6 @@ asciiart = r"""
"""
import asyncio
async def main_entry(loop: asyncio.AbstractEventLoop):
print(asciiart)
@@ -29,20 +27,22 @@ async def main_entry(loop: asyncio.AbstractEventLoop):
missing_deps = await deps.check_deps()
if missing_deps:
print("以下依赖包未安装,将自动安装,请完成后重启程序:")
print('以下依赖包未安装,将自动安装,请完成后重启程序:')
for dep in missing_deps:
print("-", dep)
print('-', dep)
await deps.install_deps(missing_deps)
print("已自动安装缺失的依赖包,请重启程序。")
print('已自动安装缺失的依赖包,请重启程序。')
sys.exit(0)
# check plugin deps
await deps.precheck_plugin_deps()
# 检查pydantic版本如果没有 pydantic.v1则把 pydantic 映射为 v1
import pydantic.version
if pydantic.version.VERSION < '2.0':
import pydantic
sys.modules['pydantic.v1'] = pydantic
# 检查配置文件
@@ -52,11 +52,12 @@ async def main_entry(loop: asyncio.AbstractEventLoop):
generated_files = await files.generate_files()
if generated_files:
print("以下文件不存在,已自动生成:")
print('以下文件不存在,已自动生成:')
for file in generated_files:
print("-", file)
print('-', file)
from pkg.core import boot
await boot.main(loop)
@@ -66,8 +67,8 @@ if __name__ == '__main__':
# 必须大于 3.10.1
if sys.version_info < (3, 10, 1):
print("需要 Python 3.10.1 及以上版本,当前 Python 版本为:", sys.version)
input("按任意键退出...")
print('需要 Python 3.10.1 及以上版本,当前 Python 版本为:', sys.version)
input('按任意键退出...')
exit(1)
# 检查本目录是否有main.py且包含LangBot字符串
@@ -78,11 +79,11 @@ if __name__ == '__main__':
else:
with open('main.py', 'r', encoding='utf-8') as f:
content = f.read()
if "LangBot/main.py" not in content:
if 'LangBot/main.py' not in content:
invalid_pwd = True
if invalid_pwd:
print("请在 LangBot 项目根目录下以命令形式运行此程序。")
input("按任意键退出...")
print('请在 LangBot 项目根目录下以命令形式运行此程序。')
input('按任意键退出...')
exit(1)
loop = asyncio.new_event_loop()