mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-27 16:04:21 +00:00
feat: 调用pip解决依赖
This commit is contained in:
@@ -240,6 +240,12 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
elif len(sys.argv) > 1 and sys.argv[1] == 'update':
|
elif len(sys.argv) > 1 and sys.argv[1] == 'update':
|
||||||
try:
|
try:
|
||||||
|
try:
|
||||||
|
import pkg.utils.pkgmgr
|
||||||
|
pkg.utils.pkgmgr.ensure_dulwich()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
from dulwich import porcelain
|
from dulwich import porcelain
|
||||||
|
|
||||||
repo = porcelain.open_repo('.')
|
repo = porcelain.open_repo('.')
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
from pip._internal import main as pipmain
|
||||||
|
|
||||||
|
|
||||||
|
def install(package):
|
||||||
|
pipmain(['install', package])
|
||||||
|
|
||||||
|
|
||||||
|
def install_requirements(file):
|
||||||
|
pipmain(['install', '-r', file])
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_dulwich():
|
||||||
|
# 尝试三次
|
||||||
|
for i in range(3):
|
||||||
|
try:
|
||||||
|
import dulwich
|
||||||
|
return
|
||||||
|
except ImportError:
|
||||||
|
install('dulwich')
|
||||||
|
|
||||||
|
raise ImportError("无法自动安装dulwich库")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
install("openai11")
|
||||||
|
except Exception as e:
|
||||||
|
print(111)
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
print(222)
|
||||||
@@ -5,6 +5,12 @@ import pkg.utils.context
|
|||||||
|
|
||||||
def update_all() -> bool:
|
def update_all() -> bool:
|
||||||
"""使用dulwich更新源码"""
|
"""使用dulwich更新源码"""
|
||||||
|
try:
|
||||||
|
import pkg.utils.pkgmgr
|
||||||
|
pkg.utils.pkgmgr.ensure_dulwich()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import dulwich
|
import dulwich
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
@@ -37,6 +43,12 @@ def update_all() -> bool:
|
|||||||
|
|
||||||
def get_current_version_info() -> str:
|
def get_current_version_info() -> str:
|
||||||
"""获取当前版本信息"""
|
"""获取当前版本信息"""
|
||||||
|
try:
|
||||||
|
import pkg.utils.pkgmgr
|
||||||
|
pkg.utils.pkgmgr.ensure_dulwich()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import dulwich
|
import dulwich
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
@@ -62,6 +74,12 @@ def get_current_version_info() -> str:
|
|||||||
|
|
||||||
def get_commit_id_and_time_and_msg() -> str:
|
def get_commit_id_and_time_and_msg() -> str:
|
||||||
"""获取当前提交id和时间和提交信息"""
|
"""获取当前提交id和时间和提交信息"""
|
||||||
|
try:
|
||||||
|
import pkg.utils.pkgmgr
|
||||||
|
pkg.utils.pkgmgr.ensure_dulwich()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import dulwich
|
import dulwich
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
@@ -79,6 +97,12 @@ def get_commit_id_and_time_and_msg() -> str:
|
|||||||
|
|
||||||
def get_current_commit_id() -> str:
|
def get_current_commit_id() -> str:
|
||||||
"""检查是否有新版本"""
|
"""检查是否有新版本"""
|
||||||
|
try:
|
||||||
|
import pkg.utils.pkgmgr
|
||||||
|
pkg.utils.pkgmgr.ensure_dulwich()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import dulwich
|
import dulwich
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
@@ -97,6 +121,12 @@ def get_current_commit_id() -> str:
|
|||||||
|
|
||||||
def is_new_version_available() -> bool:
|
def is_new_version_available() -> bool:
|
||||||
"""检查是否有新版本"""
|
"""检查是否有新版本"""
|
||||||
|
try:
|
||||||
|
import pkg.utils.pkgmgr
|
||||||
|
pkg.utils.pkgmgr.ensure_dulwich()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import dulwich
|
import dulwich
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
|
|||||||
Reference in New Issue
Block a user