Skip to content

Commit 9af31a2

Browse files
committed
refactor(packaging): 重构 Windows 打包工具和配置文件
将 Windows 打包相关的文件移动到 packaging/windows 目录,包括 build_app.py、build.bat、PyMeshGen.spec 和 PyMeshGen.iss。更新相关文档和引用路径,优化打包脚本功能并添加中文支持。 主要变更: - 移动打包文件到新目录 - 更新 README 文档中的路径说明 - 增强 build_app.py 功能并添加中文支持 - 添加新的 build.bat 一键打包脚本 - 更新 spec 和 iss 配置文件
1 parent 651c0fe commit 9af31a2

8 files changed

Lines changed: 44 additions & 30 deletions

File tree

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- Run a named test module: `cd unittests; python run_tests.py cas_file_io`
1111
- Run one unittest target from repo root: `python -m unittest unittests.test_bowyer_watson.TestBowyerWatsonJSONConfig.test_anw_bowyer_watson`
1212
- Build source and wheel distributions: `python -m pip install build && python -m build`
13-
- Preferred distribution path is Python packaging to PyPI; `build_app.py` is only for optional Windows desktop packaging
13+
- Preferred distribution path is Python packaging to PyPI; `packaging/windows/build_app.py` is only for optional Windows desktop packaging
1414
- There is no repo-root lint configuration checked in; do not invent Ruff/Flake8/Pylint commands. Prefer the existing unittest scripts and focused unittest targets.
1515

1616
## High-level architecture

MANIFEST.in

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ include VERSION
33
include README.md
44
include README_zh.md
55
include README_PACKAGING.md
6-
include PyMeshGen.spec
7-
include PyMeshGen.iss
8-
include build.bat
9-
include build_app.py
106
graft config
117
graft docs
128
graft 3rd_party/meshio/src

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ python -m pip install build
153153
python -m build
154154
```
155155

156-
For PyPI publishing and release workflow details, see [`README_PACKAGING.md`](./README_PACKAGING.md). Windows executable packaging remains available as an optional secondary path.
156+
For PyPI publishing and release workflow details, see [`README_PACKAGING.md`](./README_PACKAGING.md). Optional Windows desktop packaging tools now live under `packaging/windows/`.
157157

158158
## License
159159

README_PACKAGING.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ GUI usage still depends on GUI/runtime dependencies such as `PyQt5`, `vtk`, and
111111
Windows executable packaging is still available, but it is no longer the primary distribution mechanism.
112112

113113
```bash
114-
python build_app.py
115-
python build_app.py --all
114+
python packaging\windows\build_app.py
115+
python packaging\windows\build_app.py --all
116116
```
117117

118118
Typical outputs:
@@ -124,3 +124,16 @@ Typical outputs:
124124
| Windows installer | `installer/PyMeshGen-Setup-*.exe` |
125125

126126
This path depends on a fully prepared local Python environment plus PyInstaller, and is best treated as an optional desktop-delivery workflow rather than the main release channel.
127+
128+
The optional Windows packaging files now live under `packaging/windows/`:
129+
130+
- `packaging/windows/build_app.py`
131+
- `packaging/windows/build.bat`
132+
- `packaging/windows/PyMeshGen.spec`
133+
- `packaging/windows/PyMeshGen.iss`
134+
135+
You can also invoke the optional Windows wrapper directly:
136+
137+
```bash
138+
packaging\windows\build.bat
139+
```

PyMeshGen.iss renamed to packaging/windows/PyMeshGen.iss

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
; PyMeshGen Inno Setup 安装脚本
33
; ============================================================================
44
; 使用方法:
5-
; 1. 先运行 build.bat 构建可执行文件
5+
; 1. 先运行 packaging\windows\build.bat 构建可执行文件
66
; 2. 安装 Inno Setup: https://jrsoftware.org/isdl.php
7-
; 3. 运行: iscc.exe PyMeshGen.iss
7+
; 3. 运行: iscc.exe packaging\windows\PyMeshGen.iss
88
; ============================================================================
99

10+
#define RepoRoot "..\.."
1011
#define MyAppName "PyMeshGen"
1112
#define MyAppVersion "1.0.0"
1213
#define MyAppPublisher "PyMeshGen Team"
@@ -25,10 +26,10 @@ AppUpdatesURL={#MyAppURL}
2526
DefaultDirName={autopf}\{#MyAppName}
2627
DefaultGroupName={#MyAppName}
2728
AllowNoIcons=yes
28-
LicenseFile=LICENSE.txt
29-
OutputDir=installer
29+
LicenseFile={#RepoRoot}\LICENSE.txt
30+
OutputDir={#RepoRoot}\installer
3031
OutputBaseFilename=PyMeshGen-Setup-{#MyAppVersion}
31-
SetupIconFile=docs\icon.ico
32+
SetupIconFile={#RepoRoot}\docs\icon.ico
3233
UninstallDisplayIcon={app}\{#MyAppExeName}
3334
Compression=lzma
3435
SolidCompression=yes
@@ -49,8 +50,8 @@ Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescrip
4950

5051
[Files]
5152
; 主程序文件
52-
Source: "dist\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
53-
Source: "dist\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
53+
Source: "{#RepoRoot}\dist\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
54+
Source: "{#RepoRoot}\dist\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
5455

5556
; 注意:不要复制以下目录,它们已经包含在 dist 中
5657
; Source: "config\*"; DestDir: "{app}\config"; Flags: ignoreversion recursesubdirs createallsubdirs
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PyMeshGen PyInstaller 打包配置文件
44
用于生成 PyMeshGen GUI 应用程序的独立可执行文件
55
66
使用方法:
7-
pyinstaller PyMeshGen.spec
7+
pyinstaller packaging\windows\PyMeshGen.spec
88
"""
99

1010
import os
@@ -13,7 +13,8 @@ from PyInstaller.utils.hooks import collect_submodules, collect_data_files, coll
1313

1414
# 项目根目录
1515
block_cipher = None
16-
project_root = os.path.dirname(os.path.abspath(SPEC))
16+
spec_root = os.path.dirname(os.path.abspath(SPEC))
17+
project_root = os.path.abspath(os.path.join(spec_root, "..", ".."))
1718

1819
# 核心依赖 - 只收集必要的模块
1920
hiddenimports = [

build.bat renamed to packaging/windows/build.bat

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@echo off
2+
pushd "%~dp0"
23
REM ============================================================================
34
REM PyMeshGen 一键打包工具 (Windows)
45
REM ============================================================================
@@ -62,6 +63,7 @@ echo.
6263
python build_app.py %ARGS%
6364

6465
if errorlevel 1 (
66+
popd
6567
echo.
6668
echo ============================================================================
6769
echo [错误] 打包失败!请检查错误信息。
@@ -76,7 +78,7 @@ echo 打包完成!
7678
echo ============================================================================
7779
echo.
7880
pause
79-
81+
popd
8082
goto :eof
8183

8284
:help
@@ -108,4 +110,5 @@ echo 安装包:installer\PyMeshGen-Setup-*.exe
108110
echo ZIP 包:releases\PyMeshGen-v*.zip
109111
echo.
110112
echo ============================================================================
113+
popd
111114
goto :eof

build_app.py renamed to packaging/windows/build_app.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- 可选:创建便携版 ZIP 压缩包
1212
1313
使用方法:
14-
python build_app.py [--clean] [--debug] [--installer] [--zip]
14+
python packaging\\windows\\build_app.py [--clean] [--debug] [--installer] [--zip]
1515
1616
参数:
1717
--clean 清理之前的构建文件
@@ -43,7 +43,7 @@ class Config:
4343
BIN_DIR = "bin"
4444
INSTALLER_DIR = "installer"
4545
ZIP_DIR = "releases"
46-
SPEC_FILE = "PyMeshGen.spec"
46+
SPEC_FILE = Path(__file__).with_name("PyMeshGen.spec")
4747
MAIN_SCRIPT = "start_gui.py"
4848

4949

@@ -52,7 +52,7 @@ class Config:
5252
# ============================================================================
5353
def get_project_root():
5454
"""获取项目根目录"""
55-
return Path(__file__).parent.absolute()
55+
return Path(__file__).resolve().parents[2]
5656

5757

5858
def get_version(project_root):
@@ -189,9 +189,9 @@ def clean_build_dirs(project_root):
189189
shutil.rmtree(dir_path)
190190
cleaned = True
191191

192-
# 删除多余的 .spec 文件
192+
# 删除项目根目录下误放的 .spec 文件
193193
for spec_file in project_root.glob('*.spec'):
194-
if spec_file.name != Config.SPEC_FILE:
194+
if spec_file.resolve() != Config.SPEC_FILE.resolve():
195195
spec_file.unlink()
196196
print(f" 删除文件:{spec_file}")
197197
cleaned = True
@@ -211,7 +211,7 @@ def build_executable(project_root, debug=False):
211211
"""使用 PyInstaller 打包"""
212212
print_section("步骤 4: PyInstaller 打包")
213213

214-
spec_file = project_root / Config.SPEC_FILE
214+
spec_file = Config.SPEC_FILE
215215

216216
if not spec_file.exists():
217217
print(f"[ERR] Spec 文件不存在:{spec_file}")
@@ -295,7 +295,7 @@ def build_installer(project_root, iscc_path):
295295
"""使用 Inno Setup 构建安装包"""
296296
print_section("步骤 5: 创建安装包 (Inno Setup)")
297297

298-
iss_file = project_root / f"{Config.APP_NAME}.iss"
298+
iss_file = Path(__file__).with_name(f"{Config.APP_NAME}.iss")
299299

300300
if not iss_file.exists():
301301
print(f"[ERR] Inno Setup 脚本不存在:{iss_file}")
@@ -433,11 +433,11 @@ def main():
433433
formatter_class=argparse.RawDescriptionHelpFormatter,
434434
epilog="""
435435
示例:
436-
python build_app.py 基本构建(仅可执行文件)
437-
python build_app.py --clean 清理后构建
438-
python build_app.py --installer 创建安装包(需要 Inno Setup)
439-
python build_app.py --zip 创建便携版 ZIP
440-
python build_app.py --all 创建所有输出
436+
python packaging\\windows\\build_app.py 基本构建(仅可执行文件)
437+
python packaging\\windows\\build_app.py --clean 清理后构建
438+
python packaging\\windows\\build_app.py --installer 创建安装包(需要 Inno Setup)
439+
python packaging\\windows\\build_app.py --zip 创建便携版 ZIP
440+
python packaging\\windows\\build_app.py --all 创建所有输出
441441
"""
442442
)
443443

0 commit comments

Comments
 (0)