feat(scripts): 添加Python环境检查脚本 feat(scripts): 增强依赖导出脚本功能 perf(plugins/bili_parser): 优化B站解析器性能和代码结构 style(plugins/bili_parser): 统一代码风格和常量命名
75 lines
2.4 KiB
Python
75 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
编译模块脚本
|
||
|
||
这个脚本会单独编译每个Python模块,确保每个模块都在正确位置生成独立的.pyd文件。
|
||
"""
|
||
import os
|
||
import sys
|
||
import glob
|
||
from mypyc.build import mypycify
|
||
try:
|
||
from setuptools import setup
|
||
except ImportError:
|
||
from distutils.core import setup
|
||
|
||
def compile_module(module_path):
|
||
"""
|
||
编译单个模块
|
||
|
||
Args:
|
||
module_path: 要编译的Python模块路径
|
||
"""
|
||
print(f"\nCompiling {module_path}...")
|
||
try:
|
||
ext_modules = mypycify([module_path])
|
||
setup(name=f'compiled_{os.path.basename(module_path).replace(".py", "")}',
|
||
ext_modules=ext_modules)
|
||
return True
|
||
except Exception as e:
|
||
print(f"Error compiling {module_path}: {e}")
|
||
return False
|
||
|
||
def main():
|
||
"""
|
||
主函数
|
||
"""
|
||
# 检查 Python 版本
|
||
if not (sys.version_info.major == 3 and sys.version_info.minor == 14):
|
||
print("警告: 推荐使用 Python 3.14 以获得最佳性能")
|
||
print(f"当前版本: {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")
|
||
print("继续编译可能导致兼容性问题")
|
||
print()
|
||
|
||
# 要编译的模块列表
|
||
modules = [
|
||
'core/utils/json_utils.py', # JSON 处理
|
||
'core/utils/executor.py', # 代码执行引擎
|
||
'core/managers/command_manager.py', # 指令匹配和分发
|
||
'core/managers/admin_manager.py', # 管理员管理
|
||
'core/managers/permission_manager.py', # 权限管理
|
||
'core/ws.py', # WebSocket 核心
|
||
'core/managers/plugin_manager.py', # 插件管理器
|
||
'core/bot.py', # Bot 核心抽象
|
||
'core/config_loader.py', # 配置加载
|
||
]
|
||
|
||
# 自动添加 events 模型
|
||
event_models = glob.glob('models/events/*.py')
|
||
event_models = [m for m in event_models if not m.endswith('__init__.py')]
|
||
modules.extend(event_models)
|
||
|
||
print(f"Found {len(modules)} modules to compile.")
|
||
|
||
success_count = 0
|
||
for module in modules:
|
||
if compile_module(module):
|
||
success_count += 1
|
||
|
||
print(f"\n--- Compilation Summary ---")
|
||
print(f"Total modules: {len(modules)}")
|
||
print(f"Successfully compiled: {success_count}")
|
||
print(f"Failed: {len(modules) - success_count}")
|
||
|
||
if __name__ == '__main__':
|
||
main() |