initial-import: 2026-04-11 21:18:55
This commit is contained in:
Executable
+76
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
检测依赖版本冲突
|
||||
检查requirements-base.txt和requirements-extra.txt中是否有同一包的不同版本要求
|
||||
|
||||
用法:
|
||||
python scripts/check_version_conflict.py
|
||||
"""
|
||||
|
||||
import re
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
def parse_requirements(filename):
|
||||
"""解析requirements文件,返回{package: version_spec}"""
|
||||
packages = {}
|
||||
with open(filename, 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line or line.startswith('#'):
|
||||
continue
|
||||
# 提取包名(处理>=、==、~=等)
|
||||
match = re.match(r'^([a-zA-Z0-9_\-]+)\s*(.*)', line)
|
||||
if match:
|
||||
pkg_name = match.group(1).lower().replace('_', '-')
|
||||
version_spec = match.group(2)
|
||||
packages[pkg_name] = version_spec
|
||||
return packages
|
||||
|
||||
|
||||
def main():
|
||||
import os
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
base_file = os.path.join(script_dir, '..', 'requirements-base.txt')
|
||||
extra_file = os.path.join(script_dir, '..', 'requirements-extra.txt')
|
||||
|
||||
if not os.path.exists(base_file):
|
||||
print(f"❌ 未找到文件: {base_file}")
|
||||
return 1
|
||||
|
||||
if not os.path.exists(extra_file):
|
||||
print(f"❌ 未找到文件: {extra_file}")
|
||||
return 1
|
||||
|
||||
base = parse_requirements(base_file)
|
||||
extra = parse_requirements(extra_file)
|
||||
|
||||
conflicts = []
|
||||
all_pkgs = defaultdict(list)
|
||||
|
||||
for pkg, ver in base.items():
|
||||
all_pkgs[pkg].append(('base', ver))
|
||||
|
||||
for pkg, ver in extra.items():
|
||||
all_pkgs[pkg].append(('extra', ver))
|
||||
|
||||
for pkg, locations in all_pkgs.items():
|
||||
if len(locations) > 1:
|
||||
versions = [f"{file}: {ver}" for file, ver in locations]
|
||||
conflicts.append(f" - {pkg}: {', '.join(versions)}")
|
||||
|
||||
if conflicts:
|
||||
print("❌ 检测到版本冲突:")
|
||||
print("\n".join(conflicts))
|
||||
print(f"\n总计 {len(conflicts)} 个冲突,请解决后再构建")
|
||||
return 1
|
||||
else:
|
||||
print("✅ 未检测到版本冲突")
|
||||
print(f" 基础依赖: {len(base)} 包")
|
||||
print(f" 额外依赖: {len(extra)} 包")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
# 验证所有依赖是否正确安装
|
||||
# 此脚本在容器内运行,验证构建是否正确
|
||||
|
||||
echo "🔍 开始验证依赖安装..."
|
||||
echo ""
|
||||
|
||||
EXIT_CODE=0
|
||||
|
||||
# 检查关键包是否能导入
|
||||
check_python_package() {
|
||||
package=$1
|
||||
echo -n " Checking $package... "
|
||||
if python3 -c "import $package" 2>/dev/null; then
|
||||
echo "✅ OK"
|
||||
else
|
||||
echo "❌ FAILED"
|
||||
EXIT_CODE=1
|
||||
fi
|
||||
}
|
||||
|
||||
# 检查关键基础包
|
||||
echo "📦 检查基础依赖包:"
|
||||
check_python_package vnpy
|
||||
check_python_package numpy
|
||||
check_python_package pandas
|
||||
check_python_package scipy
|
||||
check_python_package matplotlib
|
||||
check_python_package fastapi
|
||||
check_python_package uvicorn
|
||||
check_python_package jupyterlab
|
||||
check_python_package voila
|
||||
|
||||
echo ""
|
||||
echo "📦 检查额外依赖包:"
|
||||
check_python_package akshare
|
||||
|
||||
echo ""
|
||||
# 检查命令是否存在
|
||||
check_command() {
|
||||
cmd=$1
|
||||
echo -n " Checking $cmd... "
|
||||
if command -v $cmd >/dev/null 2>&1; then
|
||||
echo "✅ OK ($(which $cmd))"
|
||||
else
|
||||
echo "❌ NOT FOUND"
|
||||
EXIT_CODE=1
|
||||
fi
|
||||
}
|
||||
|
||||
echo "🛠️ 检查系统命令:"
|
||||
check_command code-server
|
||||
check_command jupyter
|
||||
|
||||
echo ""
|
||||
if [ $EXIT_CODE -eq 0 ]; then
|
||||
echo "✅ 所有依赖验证通过!"
|
||||
else
|
||||
echo "❌ 部分依赖验证失败,请检查!"
|
||||
fi
|
||||
|
||||
exit $EXIT_CODE
|
||||
Reference in New Issue
Block a user