From daeede9ffa05a75a1476c7d0c4a86e5d93252bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=AD=90=E6=98=82?= <929110464@qq.com> Date: Sun, 26 Oct 2025 21:11:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?build:=20=E6=B7=BB=E5=8A=A0=20MagicWord=20v?= =?UTF-8?q?0.3=20=E7=9A=84=E6=89=93=E5=8C=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 Python 打包脚本用于生成 MagicWord v0.3 的可执行文件 包含清理目录、构建可执行文件和检查输出等功能 --- build_v0.3.py | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 build_v0.3.py 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 -- 2.34.1 From 220a8d46e9c854561a3bbf1c304e7213e08307bb Mon Sep 17 00:00:00 2001 From: Horse861 <929110464@qq.com> Date: Mon, 27 Oct 2025 10:05:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?build:=20=E6=9B=B4=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E8=87=B30.3.0=E5=B9=B6=E8=B0=83=E6=95=B4=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=9E=84=E5=BB=BA=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新项目版本号至0.3.0,同步修改构建脚本中的版本信息 添加新版发布包的输出目录到.gitignore --- .gitignore | 1 + build_release.py | 14 +++++++------- setup.py | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) 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/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"), -- 2.34.1