Skip to content

Commit 651c0fe

Browse files
committed
feat(打包): 重构打包流程并添加PyPI发布支持
重构打包系统,将PyPI作为主要发布渠道: 1. 添加GitHub Actions工作流用于构建和发布Python包 2. 更新pyproject.toml使用动态版本管理 3. 完善打包文档说明 4. 添加.pypirc到.gitignore 5. 更新README添加安装说明
1 parent cb30af4 commit 651c0fe

7 files changed

Lines changed: 254 additions & 65 deletions

File tree

.github/copilot-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +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
1314
- 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.
1415

1516
## High-level architecture

.github/workflows/publish-pypi.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Publish Python package
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
workflow_dispatch:
8+
inputs:
9+
repository:
10+
description: Publish target
11+
required: true
12+
default: testpypi
13+
type: choice
14+
options:
15+
- testpypi
16+
- pypi
17+
18+
jobs:
19+
build-package:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Check out repository
24+
uses: actions/checkout@v4
25+
with:
26+
submodules: recursive
27+
28+
- name: Set up Python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: "3.11"
32+
33+
- name: Install packaging tools
34+
run: |
35+
python -m pip install --upgrade pip
36+
python -m pip install build twine
37+
38+
- name: Build distributions
39+
run: python -m build
40+
41+
- name: Check distributions
42+
run: python -m twine check dist/*
43+
44+
- name: Upload build artifacts
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: python-package-distributions
48+
path: dist/*
49+
if-no-files-found: error
50+
51+
publish-testpypi:
52+
if: github.event_name == 'workflow_dispatch' && inputs.repository == 'testpypi'
53+
needs: build-package
54+
runs-on: ubuntu-latest
55+
environment: testpypi
56+
permissions:
57+
id-token: write
58+
59+
steps:
60+
- name: Download distributions
61+
uses: actions/download-artifact@v4
62+
with:
63+
name: python-package-distributions
64+
path: dist
65+
66+
- name: Publish to TestPyPI
67+
uses: pypa/gh-action-pypi-publish@release/v1
68+
with:
69+
repository-url: https://test.pypi.org/legacy/
70+
71+
publish-pypi:
72+
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.repository == 'pypi')
73+
needs: build-package
74+
runs-on: ubuntu-latest
75+
environment: pypi
76+
permissions:
77+
id-token: write
78+
79+
steps:
80+
- name: Download distributions
81+
uses: actions/download-artifact@v4
82+
with:
83+
name: python-package-distributions
84+
path: dist
85+
86+
- name: Publish to PyPI
87+
uses: pypa/gh-action-pypi-publish@release/v1
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Python package
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
build-package:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Check out repository
16+
uses: actions/checkout@v4
17+
with:
18+
submodules: recursive
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: "3.11"
24+
25+
- name: Install packaging tools
26+
run: |
27+
python -m pip install --upgrade pip
28+
python -m pip install build twine
29+
30+
- name: Build distributions
31+
run: python -m build
32+
33+
- name: Check distributions
34+
run: python -m twine check dist/*
35+
36+
- name: Upload build artifacts
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: python-package-distributions
40+
path: dist/*
41+
if-no-files-found: error

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
__pycache__/
44
*.py[cod]
55
.env
6+
.pypirc
67

78
# IDE
89
.vscode/

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ pip install -r requirements.txt
2626

2727
Some optional workflows, especially GUI and geometry import/export, rely on heavyweight packages such as VTK, PyQt5, and `pythonocc-core`.
2828

29+
## Installation
30+
31+
### PyPI (preferred after publication)
32+
33+
```bash
34+
pip install pymeshgen
35+
```
36+
37+
Available entry points after installation:
38+
39+
```bash
40+
pymeshgen --case ".\config\30p30n.json"
41+
pymeshgen-gui
42+
```
43+
44+
### Local development
45+
46+
```bash
47+
pip install -e .
48+
```
49+
2950
## Quick start
3051

3152
### Command line
@@ -123,14 +144,16 @@ python -m unittest unittests.test_bowyer_watson.TestBowyerWatsonJSONConfig.test_
123144

124145
## Packaging
125146

147+
PyMeshGen now prioritizes **Python package distribution through PyPI**.
148+
126149
For standard Python source and wheel builds:
127150

128151
```bash
129152
python -m pip install build
130153
python -m build
131154
```
132155

133-
For Windows executable packaging, see [`README_PACKAGING.md`](./README_PACKAGING.md).
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.
134157

135158
## License
136159

README_PACKAGING.md

Lines changed: 98 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,126 @@
1-
# PyMeshGen 打包工具使用说明
1+
# PyMeshGen Packaging and Publishing Guide
22

3-
## 🚀 快速开始
3+
## Preferred distribution path
44

5-
### 标准 Python 分发构建
5+
PyMeshGen now treats **Python packaging as the primary release path**:
6+
7+
1. build `sdist` + `wheel`
8+
2. validate the distributions
9+
3. publish to **PyPI**
10+
4. keep Windows executable packaging as an optional secondary path
11+
12+
For most users, the intended installation target is:
13+
14+
```bash
15+
pip install pymeshgen
16+
```
17+
18+
## Standard Python package build
619

720
```bash
8-
python -m pip install build
21+
python -m pip install --upgrade build twine
922
python -m build
23+
python -m twine check dist/*
1024
```
1125

12-
构建产物会输出到 `dist/`,这是当前推荐的源码包 / wheel 构建方式。`setup.py` 仅保留为兼容层,不再作为主要入口。
26+
Artifacts are written to `dist/`:
1327

14-
### 一键打包(推荐)
28+
| File | Description |
29+
|------|-------------|
30+
| `dist/pymeshgen-<version>.tar.gz` | Source distribution |
31+
| `dist/pymeshgen-<version>-py3-none-any.whl` | Wheel |
1532

16-
**Windows 用户**:双击运行 `build.bat`
33+
Versioning is sourced from the repository `VERSION` file. Update `VERSION` before creating a release tag.
1734

18-
**命令行方式**
19-
```bash
20-
# 基本打包(仅生成可执行文件)
21-
python build_app.py
35+
## PyPI publishing
2236

23-
# 清理后打包并创建 ZIP 便携版
24-
python build_app.py --clean --zip
37+
### Recommended: GitHub Actions + Trusted Publisher
2538

26-
# 创建所有格式(可执行文件 + 安装包 + ZIP)
27-
python build_app.py --all
39+
This repository now includes:
40+
41+
- `.github/workflows/python-package.yml` — builds and validates the Python package on push / pull request
42+
- `.github/workflows/publish-pypi.yml` — publishes to TestPyPI or PyPI through GitHub Actions
43+
44+
### One-time PyPI setup
45+
46+
In **PyPI** and **TestPyPI**, configure a Trusted Publisher for this repository:
47+
48+
- **Owner**: `cfd-dev`
49+
- **Repository**: `PyMeshGen`
50+
- **Workflow**: `publish-pypi.yml`
51+
- **Environment**:
52+
- `testpypi` for TestPyPI
53+
- `pypi` for PyPI
54+
55+
After that:
56+
57+
- **Manual TestPyPI publish**: run the `Publish Python package` workflow with `repository = testpypi`
58+
- **Official PyPI publish**: create a GitHub Release from a version tag such as `v1.0.1`
59+
60+
### Release flow
61+
62+
1. Update `VERSION`
63+
2. Commit changes
64+
3. Tag the release
65+
```bash
66+
git tag v1.0.1
67+
git push origin master --tags
68+
```
69+
4. Draft / publish the GitHub Release
70+
5. GitHub Actions publishes the wheel and sdist to PyPI
71+
72+
## Manual fallback publishing
73+
74+
If you need to publish from a local machine instead of GitHub Actions:
75+
76+
```bash
77+
python -m pip install --upgrade build twine
78+
python -m build
79+
python -m twine check dist/*
80+
python -m twine upload dist/*
2881
```
2982

30-
## 📦 输出文件
83+
For TestPyPI:
3184

32-
| 文件 | 位置 | 说明 |
33-
|------|------|------|
34-
| Python 源码包 / Wheel | `dist/` | 标准 Python 分发产物(`python -m build`|
35-
| 可执行文件 | `dist/PyMeshGen.exe` | 独立运行的程序 |
36-
| ZIP 便携版 | `releases/PyMeshGen-v*.zip` | 压缩的便携版本 |
37-
| Windows 安装包 | `installer/PyMeshGen-Setup-*.exe` | 标准安装程序(需 Inno Setup) |
85+
```bash
86+
python -m twine upload --repository testpypi dist/*
87+
```
3888

39-
## 🔧 命令行参数
89+
If you use a local `.pypirc`, keep it out of the repository. `.gitignore` already excludes it.
4090

41-
| 参数 | 说明 |
42-
|------|------|
43-
| `--clean` | 清理之前的构建文件 |
44-
| `--debug` | 启用调试模式(显示控制台窗口) |
45-
| `--installer` | 创建 Inno Setup 安装包 |
46-
| `--zip` | 创建 ZIP 便携版 |
47-
| `--all` | 创建所有输出格式 |
48-
| `--skip-clean` | 跳过清理步骤 |
91+
## Installing the published package
4992

50-
## 📋 前置要求
93+
### CLI
5194

52-
### 必需
53-
- Python 3.8+
54-
- pip 包管理器
55-
- `build`(用于标准 Python 包构建)
95+
```bash
96+
pip install pymeshgen
97+
pymeshgen --case ".\config\30p30n.json"
98+
```
5699

57-
### 可选
58-
- **Inno Setup**:用于创建 Windows 安装包(如不需要安装包可忽略)
100+
### GUI
59101

60-
## 🛠️ 配置文件
102+
```bash
103+
pip install pymeshgen
104+
pymeshgen-gui
105+
```
61106

62-
### PyInstaller 配置
63-
编辑 `PyMeshGen.spec` 文件自定义:
64-
- 包含的模块和数据文件
65-
- 图标
66-
- 版本信息
107+
GUI usage still depends on GUI/runtime dependencies such as `PyQt5`, `vtk`, and `pythonocc-core`.
67108

68-
### Python 包构建配置
69-
标准 Python 包构建配置位于:
70-
- `pyproject.toml`:PEP 517/518/621 元数据与构建入口
71-
- `setup.py`:仅保留非包资源收集的兼容层
72-
- `MANIFEST.in`:源码分发时需要包含的附加资源
109+
## Optional Windows application packaging
73110

74-
### Inno Setup 配置
75-
编辑 `PyMeshGen.iss` 文件自定义:
76-
- 安装程序界面
77-
- 安装目录
78-
- 快捷方式
111+
Windows executable packaging is still available, but it is no longer the primary distribution mechanism.
79112

80-
## ⚠️ 注意事项
113+
```bash
114+
python build_app.py
115+
python build_app.py --all
116+
```
81117

82-
1. **打包时间**:首次打包约需 15-20 分钟(依赖大量科学计算库)
83-
2. **文件大小**:可执行文件约 2-3GB(包含所有依赖)
84-
3. **Inno Setup**:如未安装,脚本会自动跳过安装包创建
118+
Typical outputs:
85119

86-
## 📖 详细文档
120+
| File | Location |
121+
|------|----------|
122+
| Executable | `dist/PyMeshGen.exe` |
123+
| Portable ZIP | `releases/PyMeshGen-v*.zip` |
124+
| Windows installer | `installer/PyMeshGen-Setup-*.exe` |
87125

88-
- PyInstaller 文档:https://pyinstaller.org/
89-
- build 文档:https://build.pypa.io/
90-
- Inno Setup 文档:https://jrsoftware.org/ishelp/
126+
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.

0 commit comments

Comments
 (0)