mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
✨ 优化虚拟环境管理,插件管理支持名称添加
This commit is contained in:
parent
14f5842f10
commit
0b98aea0f2
@ -23,12 +23,6 @@ from .config import (
|
|||||||
LOG_COMMAND,
|
LOG_COMMAND,
|
||||||
)
|
)
|
||||||
|
|
||||||
BAT_FILE = Path() / "win启动.bat"
|
|
||||||
|
|
||||||
WIN_COMMAND = ["./Python310/python.exe", "-m", "pip", "install", "-r"]
|
|
||||||
|
|
||||||
DEFAULT_COMMAND = ["poetry", "run", "pip", "install", "-r"]
|
|
||||||
|
|
||||||
|
|
||||||
def row_style(column: str, text: str) -> RowStyle:
|
def row_style(column: str, text: str) -> RowStyle:
|
||||||
"""被动技能文本风格
|
"""被动技能文本风格
|
||||||
@ -438,8 +432,8 @@ class StoreManager:
|
|||||||
continue
|
continue
|
||||||
if cls.check_version_is_new(plugin_info, suc_plugin):
|
if cls.check_version_is_new(plugin_info, suc_plugin):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"插件 {plugin_info.name}({plugin_info.module}) 已是最新版本"
|
f"插件 {plugin_info.name}({plugin_info.module}) "
|
||||||
",跳过",
|
"已是最新版本,跳过",
|
||||||
LOG_COMMAND,
|
LOG_COMMAND,
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
@ -486,6 +480,18 @@ class StoreManager:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def _resolve_plugin_key(cls, plugin_id: str) -> str:
|
async def _resolve_plugin_key(cls, plugin_id: str) -> str:
|
||||||
|
"""获取插件module
|
||||||
|
|
||||||
|
参数:
|
||||||
|
plugin_id: module,id或插件名称
|
||||||
|
|
||||||
|
异常:
|
||||||
|
ValueError: 插件不存在
|
||||||
|
ValueError: 插件不存在
|
||||||
|
|
||||||
|
返回:
|
||||||
|
str: 插件模块名
|
||||||
|
"""
|
||||||
plugin_list: list[StorePluginInfo] = await cls.get_data()
|
plugin_list: list[StorePluginInfo] = await cls.get_data()
|
||||||
if is_number(plugin_id):
|
if is_number(plugin_id):
|
||||||
idx = int(plugin_id)
|
idx = int(plugin_id)
|
||||||
@ -493,6 +499,9 @@ class StoreManager:
|
|||||||
raise ValueError("插件ID不存在...")
|
raise ValueError("插件ID不存在...")
|
||||||
return plugin_list[idx].module
|
return plugin_list[idx].module
|
||||||
elif isinstance(plugin_id, str):
|
elif isinstance(plugin_id, str):
|
||||||
if plugin_id not in [v.module for v in plugin_list]:
|
result = (
|
||||||
raise ValueError("插件Module不存在...")
|
None if plugin_id not in [v.module for v in plugin_list] else plugin_id
|
||||||
return plugin_id
|
) or next(v for v in plugin_list if v.name == plugin_id).module
|
||||||
|
if not result:
|
||||||
|
raise ValueError("插件 Module / 名称 不存在...")
|
||||||
|
return result
|
||||||
|
|||||||
@ -3,12 +3,20 @@ import subprocess
|
|||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
from typing import ClassVar
|
from typing import ClassVar
|
||||||
|
|
||||||
|
from zhenxun.configs.config import Config
|
||||||
from zhenxun.services.log import logger
|
from zhenxun.services.log import logger
|
||||||
|
|
||||||
BAT_FILE = Path() / "win启动.bat"
|
BAT_FILE = Path() / "win启动.bat"
|
||||||
|
|
||||||
LOG_COMMAND = "VirtualEnvPackageManager"
|
LOG_COMMAND = "VirtualEnvPackageManager"
|
||||||
|
|
||||||
|
Config.add_plugin_config(
|
||||||
|
"virtualenv",
|
||||||
|
"python_path",
|
||||||
|
None,
|
||||||
|
help="虚拟环境python路径,为空时使用系统环境的poetry",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class VirtualEnvPackageManager:
|
class VirtualEnvPackageManager:
|
||||||
WIN_COMMAND: ClassVar[list[str]] = [
|
WIN_COMMAND: ClassVar[list[str]] = [
|
||||||
@ -21,6 +29,8 @@ class VirtualEnvPackageManager:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __get_command(cls) -> list[str]:
|
def __get_command(cls) -> list[str]:
|
||||||
|
if path := Config.get_config("virtualenv", "python_path"):
|
||||||
|
return [path, "-m", "pip"]
|
||||||
return cls.WIN_COMMAND if BAT_FILE.exists() else cls.DEFAULT_COMMAND
|
return cls.WIN_COMMAND if BAT_FILE.exists() else cls.DEFAULT_COMMAND
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user