mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-03 10:40:02 +08:00
✨ feat(env): 支持git更新
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
from subprocess import CalledProcessError
|
||||
@@ -36,7 +37,7 @@ class VirtualEnvPackageManager:
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def install(cls, package: list[str] | str):
|
||||
async def install(cls, package: list[str] | str):
|
||||
"""安装依赖包
|
||||
|
||||
参数:
|
||||
@@ -49,7 +50,8 @@ class VirtualEnvPackageManager:
|
||||
command.append("install")
|
||||
command.append(" ".join(package))
|
||||
logger.info(f"执行虚拟环境安装包指令: {command}", LOG_COMMAND)
|
||||
result = subprocess.run(
|
||||
result = await asyncio.to_thread(
|
||||
subprocess.run,
|
||||
command,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
@@ -65,7 +67,7 @@ class VirtualEnvPackageManager:
|
||||
return e.stderr
|
||||
|
||||
@classmethod
|
||||
def uninstall(cls, package: list[str] | str):
|
||||
async def uninstall(cls, package: list[str] | str):
|
||||
"""卸载依赖包
|
||||
|
||||
参数:
|
||||
@@ -79,7 +81,8 @@ class VirtualEnvPackageManager:
|
||||
command.append("-y")
|
||||
command.append(" ".join(package))
|
||||
logger.info(f"执行虚拟环境卸载包指令: {command}", LOG_COMMAND)
|
||||
result = subprocess.run(
|
||||
result = await asyncio.to_thread(
|
||||
subprocess.run,
|
||||
command,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
@@ -95,7 +98,7 @@ class VirtualEnvPackageManager:
|
||||
return e.stderr
|
||||
|
||||
@classmethod
|
||||
def update(cls, package: list[str] | str):
|
||||
async def update(cls, package: list[str] | str):
|
||||
"""更新依赖包
|
||||
|
||||
参数:
|
||||
@@ -109,7 +112,8 @@ class VirtualEnvPackageManager:
|
||||
command.append("--upgrade")
|
||||
command.append(" ".join(package))
|
||||
logger.info(f"执行虚拟环境更新包指令: {command}", LOG_COMMAND)
|
||||
result = subprocess.run(
|
||||
result = await asyncio.to_thread(
|
||||
subprocess.run,
|
||||
command,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
@@ -122,7 +126,7 @@ class VirtualEnvPackageManager:
|
||||
return e.stderr
|
||||
|
||||
@classmethod
|
||||
def install_requirement(cls, requirement_file: Path):
|
||||
async def install_requirement(cls, requirement_file: Path):
|
||||
"""安装依赖文件
|
||||
|
||||
参数:
|
||||
@@ -139,7 +143,8 @@ class VirtualEnvPackageManager:
|
||||
command.append("-r")
|
||||
command.append(str(requirement_file.absolute()))
|
||||
logger.info(f"执行虚拟环境安装依赖文件指令: {command}", LOG_COMMAND)
|
||||
result = subprocess.run(
|
||||
result = await asyncio.to_thread(
|
||||
subprocess.run,
|
||||
command,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
@@ -158,13 +163,14 @@ class VirtualEnvPackageManager:
|
||||
return e.stderr
|
||||
|
||||
@classmethod
|
||||
def list(cls) -> str:
|
||||
async def list(cls) -> str:
|
||||
"""列出已安装的依赖包"""
|
||||
try:
|
||||
command = cls.__get_command()
|
||||
command.append("list")
|
||||
logger.info(f"执行虚拟环境列出包指令: {command}", LOG_COMMAND)
|
||||
result = subprocess.run(
|
||||
result = await asyncio.to_thread(
|
||||
subprocess.run,
|
||||
command,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
|
||||
Reference in New Issue
Block a user