shunk031-python-uv-workflow
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePython UV Workflow
Python UV 工作流程
Overview
概述
Use this workflow to keep Python implementation and refactoring aligned with repository policy.
使用此工作流程可确保Python代码的实现与重构符合仓库规范。
Read Acknowledgement
阅读确认
- After reading this skill, say:
🐍 I read shunk031-python-uv-workflow.
- 阅读完此技能后,请说:
🐍 I read shunk031-python-uv-workflow.
Workflow
工作流程
- Use as the default toolchain for Python projects.
uv - Run scripts with .
uv run <script> - Write tests when behavior changes and verify expected behavior.
- Add standard dev dependencies with .
uv - Install pre-commit hooks after dependency setup.
- Create when missing.
.pre-commit-config.yaml - Create with
Makefiletarget when missing.setup - For refactoring from non-originals, align dependencies, raise coverage, and verify output parity.
uv - Construct Python paths from a source-file anchor rather than a hard-coded absolute path string:
- Bad:
Path("/path/to") / "hoge" - Good: Anchoring paths to the source file keeps them working after relocation and across worktrees without coupling them to a host layout. Explicit roots supplied through a CLI argument or environment variable are allowed; only hard-coded absolute path strings are forbidden.
Path(__file__).parents[N] / "path" / "to" / "hoge"
- Bad:
- 将作为Python项目的默认工具链。
uv - 使用运行脚本。
uv run <script> - 当行为发生变化时编写测试,并验证预期行为。
- 使用添加标准开发依赖。
uv - 依赖设置完成后安装预提交钩子。
- 若缺少则创建该文件。
.pre-commit-config.yaml - 若缺少则创建包含
Makefile目标的setup。Makefile - 对于从非项目重构而来的代码,需对齐依赖、提高覆盖率并验证输出一致性。
uv - 从源文件锚点构建Python路径,而非使用硬编码的绝对路径字符串:
- 错误写法:
Path("/path/to") / "hoge" - 正确写法:将路径锚定到源文件可确保在迁移或跨工作树时仍能正常工作,而无需依赖主机系统的布局。允许通过CLI参数或环境变量提供显式根路径;仅禁止硬编码的绝对路径字符串。
Path(__file__).parents[N] / "path" / "to" / "hoge"
- 错误写法:
Testing Expectations
测试要求
- Add tests before refactoring.
- Prefer real data over mocks and monkeypatches when feasible.
- Target coverage expansion toward 90%+ for refactoring tasks.
Use python-uv-rules.md for exact commands and canonical hook configuration.
- 重构前先添加测试。
- 在可行的情况下,优先使用真实数据而非模拟对象(mocks)和猴子补丁(monkeypatches)。
- 重构任务的覆盖率目标需提升至90%以上。
如需确切命令和标准钩子配置,请参考python-uv-rules.md