from setuptools import setup, find_packages
import sys
import shutil
import os
import subprocess
try:
    shutil.rmtree("dist")
    shutil.rmtree("build")
except:
    pass
sys.argv.append("bdist_wheel")
sys.argv.append("sdist")
setup(
    name="mini-game-tools",
    version="1.24.1",
    description="一个做着玩的游戏工具库",
    long_description=open("README.md",encoding='utf-8').read(),
    long_description_content_type="text/markdown",
    author="Li Mo",
    author_email="28009663@qq.com",
    license="MIT",
    url="https://github.com/limo1027/mlib",
    packages=find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "Operating System :: OS Independent",
        "Topic :: Scientific/Engineering :: Mathematics",
        "Topic :: Software Development :: Libraries :: Python Modules",
    ],
    python_requires=">=3.6",
    keywords="game development, gamedev, game tools, graphics, rendering, game math, game physics",
)

print("=" * 50)
print("🚀 上传 game_tools 到 PyPI")
print("=" * 50)
# 1. 切换到正确目录
target_dir = r"C:\Users\Lq\Desktop\mlib"
if os.getcwd() != target_dir:
    print(f"📂 切换到目录: {target_dir}")
    os.chdir(target_dir)
# 2. 检查 dist
if not os.path.exists('dist'):
    print("❌ dist 目录不存在，先构建包")
    subprocess.run([sys.executable, "-m", "build"])

print("\n📦 dist 目录内容:")
print(os.listdir("dist"))
# 3. 设置令牌环境变量（避免手动输入）
token = "pypi-AgEIcHlwaS5vcmcCJDdjNmU3OTZlLTRjMDEtNDViMi04NTQxLWJiODQxNmY2ZDA1MgACKlszLCJmZDlkMWQ0OS03YjlhLTQwM2YtOTdjMS1lZWRiYWRkMzhiMjkiXQAABiC6MuaEIPqFsn_OtxAayCD6jBKFyW29TRvyDjiDOpohyQ"
os.environ['TWINE_USERNAME'] = '__token__'
os.environ['TWINE_PASSWORD'] = token
# 4. 上传
print("\n📤 上传中...")
result = subprocess.run([sys.executable, "-m", "twine", "upload", "dist/*"])
if result.returncode == 0:
    print("\n✨ 上传成功！")
    print("🔗 https://pypi.org/project/game_tools/")
    print("\n等待5-10分钟后运行: pip install game_tools")
else:
    print("\n❌ 上传失败")
