开发环境搭建
环境准备
1. Python 环境
推荐使用 pyenv 管理 Python 版本:
2. Poetry 安装
3. 开发工具
推荐使用 VSCode 作为开发环境:
- 安装 VSCode
 - 安装扩展:
 - Python
 - Pylance
 - Python Test Explorer
 - GitLens
 - Python Docstring Generator
 
4. 克隆项目
项目设置
1. 安装依赖
2. 配置 IDE
VSCode 设置
创建 .vscode/settings.json:
{
  "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
  "python.formatting.provider": "black",
  "python.linting.enabled": true,
  "python.linting.pylintEnabled": true,
  "python.testing.pytestEnabled": true,
  "editor.formatOnSave": true,
  "editor.rulers": [88],
  "files.trimTrailingWhitespace": true
}
PyCharm 设置
- 打开项目设置
 - 配置 Python 解释器:选择 Poetry 环境
 - 启用 Black 格式化
 - 配置 pytest 为默认测试运行器
 
开发工作流
1. 创建新分支
2. 运行测试
# 运行所有测试
poetry run pytest
# 运行特定测试文件
poetry run pytest tests/test_window.py
# 运行带覆盖率的测试
poetry run pytest --cov=watchcat
3. 代码质量检查
# 运行 black 格式化
poetry run black .
# 运行 pylint
poetry run pylint watchcat
# 运行 mypy 类型检查
poetry run mypy watchcat
4. 构建文档
调试技巧
使用 VSCode 调试
- 创建 
.vscode/launch.json: 
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "justMyCode": false
    },
    {
      "name": "Python: WatchCat",
      "type": "python",
      "request": "launch",
      "module": "watchcat",
      "console": "integratedTerminal",
      "justMyCode": false
    }
  ]
}