Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion astrbot/core/utils/pip_installer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import asyncio
import locale
import logging
import sys

logger = logging.getLogger("astrbot")


def _robust_decode(line: bytes) -> str:
"""解码字节流,兼容不同平台的编码"""
try:
return line.decode("utf-8").strip()
except UnicodeDecodeError:
pass
try:
return line.decode(locale.getpreferredencoding(False)).strip()
except UnicodeDecodeError:
pass
if sys.platform.startswith("win"):
try:
return line.decode("gbk").strip()
except UnicodeDecodeError:
pass
return line.decode("utf-8", errors="replace").strip()


class PipInstaller:
def __init__(self, pip_install_arg: str, pypi_index_url: str | None = None):
self.pip_install_arg = pip_install_arg
Expand Down Expand Up @@ -42,7 +61,7 @@ async def install(

assert process.stdout is not None
async for line in process.stdout:
logger.info(line.decode().strip())
logger.info(_robust_decode(line))

await process.wait()

Expand Down