Files
chatgpt-on-wechat/common/package_manager.py
haosenwang1018 adca89b973 fix: replace bare except clauses with except Exception
Bare `except:` catches BaseException including KeyboardInterrupt and
SystemExit. Replaced 29 instances with `except Exception:`.
2026-02-25 11:49:19 +00:00

37 lines
735 B
Python

import time
import pip
from pip._internal import main as pipmain
from common.log import _reset_logger, logger
def install(package):
pipmain(["install", package])
def install_requirements(file):
pipmain(["install", "-r", file, "--upgrade"])
_reset_logger(logger)
def check_dulwich():
needwait = False
for i in range(2):
if needwait:
time.sleep(3)
needwait = False
try:
import dulwich
return
except ImportError:
try:
install("dulwich")
except Exception:
needwait = True
try:
import dulwich
except ImportError:
raise ImportError("Unable to import dulwich")