diff --git a/.gitignore b/.gitignore index f4d94b7..4ec21cb 100644 --- a/.gitignore +++ b/.gitignore @@ -199,6 +199,7 @@ temp/ # Project specific dist_package/ +dist_package_v0.3/ *.zip *.pyc *.pyo diff --git a/build_release.py b/build_release.py index 89054d8..08a0160 100644 --- a/build_release.py +++ b/build_release.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ -MagicWord 0.2.1 版本发布脚本 +MagicWord 0.3.0 版本发布脚本 用于构建和打包应用程序 """ @@ -72,7 +72,7 @@ def build_executable(): pyinstaller_cmd = [ "pyinstaller", "--name", "MagicWord", - "--version", "0.2.1", + "--version", "0.3.0", "--distpath", "dist", "--workpath", "build", "--specpath", ".", @@ -161,7 +161,7 @@ def create_package(): # 创建运行脚本 if platform.system() == "Windows": run_script = """@echo off -echo MagicWord 0.2.1 启动中... +echo MagicWord 0.3.0 启动中... cd /d "%~dp0" start MagicWord.exe """ @@ -169,7 +169,7 @@ start MagicWord.exe f.write(run_script) else: run_script = """#!/bin/bash -echo "MagicWord 0.2.1 启动中..." +echo "MagicWord 0.3.0 启动中..." cd "$(dirname "$0")" ./MagicWord & """ @@ -178,7 +178,7 @@ cd "$(dirname "$0")" os.chmod(os.path.join(release_dir, "run.sh"), 0o755) # 创建发布说明 - release_info = f"""MagicWord 0.2.1 发布包 + release_info = f"""MagicWord 0.3.0 发布包 构建时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} 平台: {platform.system()} {platform.machine()} Python版本: {platform.python_version()} @@ -203,7 +203,7 @@ Python版本: {platform.python_version()} f.write(release_info) # 创建ZIP包 - zip_name = f"MagicWord_v0.2.1_{platform.system()}_{platform.machine()}.zip" + zip_name = f"MagicWord_v0.3.0_{platform.system()}_{platform.machine()}.zip" with zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) as zipf: for root, dirs, files in os.walk(release_dir): for file in files: @@ -217,7 +217,7 @@ Python版本: {platform.python_version()} def main(): """主函数""" print("=" * 60) - print("MagicWord 0.2.1 版本发布构建脚本") + print("MagicWord 0.3.0 版本发布构建脚本") print("=" * 60) # 检查Python版本 diff --git a/build_v0.3.py b/build_v0.3.py new file mode 100644 index 0000000..147f732 --- /dev/null +++ b/build_v0.3.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +""" +MagicWord v0.3 打包脚本 +版本号:0.3 +输出目录:dist/ +图标:resources/icons/app_icon_256X256.png +""" + +import os +import sys +import subprocess +import shutil +from pathlib import Path + +def clean_dist(): + """清理dist目录""" + dist_dir = Path("dist") + if dist_dir.exists(): + shutil.rmtree(dist_dir) + dist_dir.mkdir(exist_ok=True) + +def build_executable(): + """使用PyInstaller构建可执行文件""" + print("开始构建 MagicWord v0.3...") + + # 清理之前的构建 + clean_dist() + + # PyInstaller 参数 + pyinstaller_args = [ + "-m", "PyInstaller", + "--onefile", # 单文件模式 + "--windowed", # 窗口模式(无控制台) + f"--name=MagicWord_v0.3", # 可执行文件名 + f"--icon=resources/icons/app_icon_256X256.png", # 图标文件 + "--add-data=resources:resources", # 添加资源文件 + "--add-data=src:src", # 添加源代码 + "--clean", # 清理临时文件 + "--noconfirm", # 不确认覆盖 + "src/main.py" # 主程序入口 + ] + + # 执行打包命令 + cmd = [sys.executable] + pyinstaller_args + print(f"执行命令: {' '.join(cmd)}") + + try: + result = subprocess.run(cmd, capture_output=True, text=True) + if result.returncode != 0: + print(f"打包失败: {result.stderr}") + return False + else: + print("打包成功!") + return True + except Exception as e: + print(f"执行打包时出错: {e}") + return False + +def check_output(): + """检查输出文件""" + dist_dir = Path("dist") + exe_files = list(dist_dir.glob("MagicWord_v0.3*")) + + if exe_files: + print(f"生成的文件:") + for exe in exe_files: + size = exe.stat().st_size / (1024 * 1024) # MB + print(f" {exe.name} - {size:.1f} MB") + return True + else: + print("未找到生成的可执行文件") + return False + +def main(): + """主函数""" + print("=" * 50) + print("MagicWord v0.3 打包工具") + print("=" * 50) + + # 检查Python环境 + print(f"Python版本: {sys.version}") + print(f"Python路径: {sys.executable}") + + # 检查文件是否存在 + required_files = [ + "src/main.py", + "resources/icons/app_icon_256X256.png" + ] + + missing_files = [] + for file in required_files: + if not Path(file).exists(): + missing_files.append(file) + + if missing_files: + print(f"缺少必需文件: {missing_files}") + return + + # 构建可执行文件 + if build_executable(): + # 检查输出 + if check_output(): + print("\n✅ 打包完成!可执行文件位于 dist/ 目录") + else: + print("\n❌ 打包可能存在问题") + else: + print("\n❌ 打包失败") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/setup.py b/setup.py index c8cf589..f509b1c 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name="MagicWord", - version="0.2.1", + version="0.3.0", description="隐私学习软件 - 一款通过打字练习来学习文档内容的工具", author="MagicWord Team", packages=find_packages(where="src"),