mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-05 20:00:04 +08:00
✨ feat(http_utils): 添加可选的 accept_status_codes 参数以支持自定义状态码处理 (#2096)
- 在 AsyncHttpx 类中,新增 accept_status_codes 参数,允许用户指定哪些 HTTP 状态码不视为错误。 - 更新了单次请求的逻辑,以便在响应状态码符合 accept_status_codes 时不调用 raise_for_status 方法。 ✨ feat(message): 增加随机失败提示消息功能 - 在 MessageUtils 类中,添加可爱风格的失败提示消息列表和获取随机消息的方法。 ✨ feat(github_utils): 引入动态查询外部插件分组的功能 - 在 AliyunFileInfo 类中,新增 list_group_repositories 方法以列出分组下的所有仓库,并实现通过仓库名称获取仓库ID的逻辑。 ✨ feat(virtual_env_package_manager): 增加清理 requirements 文件的功能 - 新增 _clean_requirements_file 方法,清理 requirements 文件中的非ASCII注释,避免 Windows 上 pip 使用 GBK 编码读取 UTF-8 文件时出错。 ✨ feat(repo_utils): 优化阿里云仓库 URL 处理逻辑 - 更新 prepare_aliyun_url 方法以支持指定分组名称,并新增 get_aliyun_group_for_repo 方法以获取仓库所属的阿里云分组名。
This commit is contained in:
@@ -125,6 +125,40 @@ class VirtualEnvPackageManager:
|
||||
logger.error(f"更新虚拟环境包指令执行失败: {e.stderr}.", LOG_COMMAND)
|
||||
return e.stderr
|
||||
|
||||
@staticmethod
|
||||
def _clean_requirements_file(file_path: Path) -> None:
|
||||
"""清理 requirements 文件中的非ASCII注释
|
||||
|
||||
防止 Windows 上 pip 使用 GBK 编码读取 UTF-8 文件时出错
|
||||
|
||||
参数:
|
||||
file_path: requirements 文件路径
|
||||
"""
|
||||
try:
|
||||
content = file_path.read_text(encoding="utf-8")
|
||||
lines = content.splitlines()
|
||||
cleaned_lines = []
|
||||
for line in lines:
|
||||
stripped = line.strip()
|
||||
# 跳过空行
|
||||
if not stripped:
|
||||
continue
|
||||
# 如果是注释行且包含非ASCII字符,跳过
|
||||
if stripped.startswith("#"):
|
||||
try:
|
||||
stripped.encode("ascii")
|
||||
except UnicodeEncodeError:
|
||||
continue
|
||||
cleaned_lines.append(line)
|
||||
# 写回文件
|
||||
file_path.write_text(
|
||||
"\n".join(cleaned_lines) + "\n" if cleaned_lines else "",
|
||||
encoding="utf-8",
|
||||
)
|
||||
except Exception:
|
||||
# 如果清理失败,忽略错误继续安装
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
async def install_requirement(cls, requirement_file: Path):
|
||||
"""安装依赖文件
|
||||
@@ -137,6 +171,8 @@ class VirtualEnvPackageManager:
|
||||
"""
|
||||
if not requirement_file.exists():
|
||||
raise FileNotFoundError(f"依赖文件 {requirement_file} 不存在", LOG_COMMAND)
|
||||
# 清理 requirements 文件中的非ASCII注释,防止 Windows GBK 编码问题
|
||||
cls._clean_requirements_file(requirement_file)
|
||||
try:
|
||||
command = cls.__get_command()
|
||||
command.append("install")
|
||||
|
||||
Reference in New Issue
Block a user