105 lines
2.9 KiB
Python
105 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
RustFS S3 Storage Toolkit 构建和发布脚本
|
|
"""
|
|
|
|
import subprocess
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
|
|
|
|
def run_command(command, description):
|
|
"""运行命令并显示结果"""
|
|
print(f"🔧 {description}...")
|
|
try:
|
|
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
|
|
print(f"✅ {description}成功")
|
|
if result.stdout.strip():
|
|
print(f"输出: {result.stdout.strip()}")
|
|
return True
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"❌ {description}失败: {e}")
|
|
if e.stdout:
|
|
print(f"输出: {e.stdout}")
|
|
if e.stderr:
|
|
print(f"错误: {e.stderr}")
|
|
return False
|
|
|
|
|
|
def main():
|
|
"""主构建流程"""
|
|
print("🚀 RustFS S3 Storage Toolkit 构建脚本")
|
|
print("=" * 50)
|
|
|
|
# 检查当前目录
|
|
current_dir = Path.cwd()
|
|
if not (current_dir / "pyproject.toml").exists():
|
|
print("❌ 请在项目根目录运行此脚本")
|
|
sys.exit(1)
|
|
|
|
print(f"✅ 项目目录: {current_dir}")
|
|
|
|
# 清理旧的构建文件
|
|
print("\n🧹 清理旧的构建文件...")
|
|
cleanup_commands = [
|
|
"rm -rf dist/",
|
|
"rm -rf build/",
|
|
"rm -rf *.egg-info/",
|
|
"find . -name '__pycache__' -type d -exec rm -rf {} + 2>/dev/null || true",
|
|
"find . -name '*.pyc' -delete 2>/dev/null || true"
|
|
]
|
|
|
|
for command in cleanup_commands:
|
|
subprocess.run(command, shell=True, capture_output=True)
|
|
|
|
print("✅ 清理完成")
|
|
|
|
# 安装构建依赖
|
|
build_deps = [
|
|
"pip install --upgrade pip",
|
|
"pip install --upgrade build twine"
|
|
]
|
|
|
|
for command in build_deps:
|
|
if not run_command(command, f"安装构建依赖"):
|
|
print("❌ 安装构建依赖失败")
|
|
sys.exit(1)
|
|
|
|
# 构建包
|
|
if not run_command("python -m build", "构建包"):
|
|
print("❌ 构建失败")
|
|
sys.exit(1)
|
|
|
|
# 检查构建结果
|
|
dist_dir = current_dir / "dist"
|
|
if not dist_dir.exists():
|
|
print("❌ 构建目录不存在")
|
|
sys.exit(1)
|
|
|
|
built_files = list(dist_dir.glob("*"))
|
|
if not built_files:
|
|
print("❌ 没有找到构建文件")
|
|
sys.exit(1)
|
|
|
|
print(f"\n📦 构建完成!生成的文件:")
|
|
for file in built_files:
|
|
print(f" - {file.name}")
|
|
|
|
# 验证包
|
|
if not run_command("python -m twine check dist/*", "验证包"):
|
|
print("❌ 包验证失败")
|
|
sys.exit(1)
|
|
|
|
print("\n🎉 构建和验证完成!")
|
|
print("\n📖 发布到 PyPI:")
|
|
print("1. 测试发布: python -m twine upload --repository testpypi dist/*")
|
|
print("2. 正式发布: python -m twine upload dist/*")
|
|
|
|
print("\n💡 本地安装测试:")
|
|
print("pip install dist/*.whl")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|