- 克隆仓库:
git clone https://github.com/guyue55/py_example.git
cd py_example- 安装开发依赖(含测试与 lint 工具):
pip install -e ".[dev]"pytestruff check .- Fork 项目仓库
- 创建功能分支
- 提交变更
- 运行测试确保通过
- 提交 Pull Request
- 遵循语义化版本规范。
- 唯一手写版本位于
src/example/__init__.py的__version__。 pyproject.toml通过dynamic = ["version"]从该值自动派生,无需手动同步, 不要在 pyproject 里再写静态version。- 每次发布在
CHANGELOG.md记录变更(Keep a Changelog 格式)。
推荐方式:Trusted Publishing(OIDC),无需在仓库中保存 API token。 完整流程见 docs/PUBLISHING.md,GitHub Actions 已提供
.github/workflows/publish.yml(推送v*.*.*标签即自动发布)。
本地自检步骤:
先安装依赖
python -m pip install --upgrade build twine- 构建分发包:
python -m build- 检查包是否符合PyPI的要求
python -m twine check dist/*- 打版本标签并推送(触发自动发布):
git tag v0.2.0
git push origin v0.2.0注意事项
- 模板本身不发布:本仓库包名为占位符
example,请先用scripts/rename_template.py改名后再发布。 - API token(可选):若不使用 Trusted Publishing,上传到 PyPI 需要 API token,没有的话先去网站注册账号再生成(https://pypi.org/)。
- 避免每次都要输入 token:设置
$HOME/.pypirc[pypi] username = __token__ password = pypi-xxxxxx