shunk031-python-uv-workflow

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Python 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

工作流程

  1. Use
    uv
    as the default toolchain for Python projects.
  2. Run scripts with
    uv run <script>
    .
  3. Write tests when behavior changes and verify expected behavior.
  4. Add standard dev dependencies with
    uv
    .
  5. Install pre-commit hooks after dependency setup.
  6. Create
    .pre-commit-config.yaml
    when missing.
  7. Create
    Makefile
    with
    setup
    target when missing.
  8. For refactoring from non-
    uv
    originals, align dependencies, raise coverage, and verify output parity.
  9. Construct Python paths from a source-file anchor rather than a hard-coded absolute path string:
    • Bad:
      Path("/path/to") / "hoge"
    • Good:
      Path(__file__).parents[N] / "path" / "to" / "hoge"
      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.
  1. 将
    uv
    作为Python项目的默认工具链。
  2. 使用
    uv run <script>
    运行脚本。
  3. 当行为发生变化时编写测试,并验证预期行为。
  4. 使用
    uv
    添加标准开发依赖。
  5. 依赖设置完成后安装预提交钩子。
  6. 若缺少
    .pre-commit-config.yaml
    则创建该文件。
  7. 若缺少
    Makefile
    则创建包含
    setup
    目标的
    Makefile
    。
  8. 对于从非
    uv
    项目重构而来的代码,需对齐依赖、提高覆盖率并验证输出一致性。
  9. 从源文件锚点构建Python路径,而非使用硬编码的绝对路径字符串:
    • 错误写法:
      Path("/path/to") / "hoge"
    • 正确写法:
      Path(__file__).parents[N] / "path" / "to" / "hoge"
      将路径锚定到源文件可确保在迁移或跨工作树时仍能正常工作,而无需依赖主机系统的布局。允许通过CLI参数或环境变量提供显式根路径;仅禁止硬编码的绝对路径字符串。

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