Python Auto-Dev Skill
Complete automation for Python development: generate code from specs, add tests, debug, and optimize—all with the configured conda environment.
Quick Start
When a user provides a coding task:
- 1. Generate Python code based on their requirements
- Write unit tests using pytest or unittest
- Run tests and capture output
- Debug failures automatically
- Optimize with profiling and linting
- Deliver final code with test report
All operations use the py311 conda environment at C:\anaconda3\condabin\conda.bat and store files under H:\code\Daily.
Workflow
Phase 1: Code Generation
Use scripts/generate_code.py to create Python code from a specification. The script accepts:
- -
spec: Natural language description of what the code should do - INLINECODE5 : Where to save the generated file (default:
H:\code\Daily\generated_<timestamp>.py)
The generated code should include:
- - Type hints
- Docstrings
- Basic error handling
- Modular design
Phase 2: Test Creation
After code is generated, use scripts/create_tests.py to produce comprehensive unit tests:
- - Tests edge cases
- Tests error conditions
- Uses pytest fixtures where appropriate
- Outputs to INLINECODE8
Phase 3: Test Execution & Debugging
Run tests with scripts/run_tests.py:
- - Activates the conda environment
- Executes pytest with verbose output
- Captures results in a report file
If tests fail, invoke scripts/debug_code.py:
- - Analyzes traceback
- Suggests fixes
- Can patch the code automatically (with confirmation)
Phase 4: Optimization
Once tests pass, use scripts/optimize_code.py:
- - Runs profiling (cProfile)
- Checks code quality (pylint/flake8)
- Suggests optimizations
- Can apply safe optimizations automatically
Scripts Reference
All scripts are designed to be called directly by Codex. They handle conda activation internally.
- -
scripts/generate_code.py - Generate Python from spec - INLINECODE13 - Create pytest/unittest suite
- INLINECODE14 - Execute tests and report
- INLINECODE15 - Analyze failures and suggest/patch
- INLINECODE16 - Profile and improve code quality
See references/script-usage.md for detailed parameter descriptions and examples.
Integration Notes
- - Default conda path is hard-coded for this setup; modify scripts if path changes.
- All project files are isolated to
H:\code\Daily to keep workspace clean. - Scripts assume Windows environment (conda .bat activation).
- Output reports are saved as JSON and plain text for further processing.
When to Use This Skill
Use this skill when the task involves creating new Python code with a complete development pipeline. It's ideal for:
- - Rapid prototyping
- Educational examples
- Automated script generation
- Refactoring tasks with test coverage
- Optimization of existing code
Do not use for non-Python languages or when conda environment is unavailable.
Python 自动开发技能
根据规格生成代码、添加测试、调试和优化——全部在配置好的conda环境中完成,实现Python开发的完全自动化。
快速开始
当用户提供编码任务时:
- 1. 根据需求生成Python代码
- 使用pytest或unittest编写单元测试
- 运行测试并捕获输出
- 自动调试失败项
- 通过性能分析和代码检查进行优化
- 交付最终代码及测试报告
所有操作均使用位于C:\anaconda3\condabin\conda.bat的py311 conda环境,文件存储在H:\code\Daily目录下。
工作流程
第一阶段:代码生成
使用scripts/generate_code.py根据规格说明创建Python代码。该脚本接受以下参数:
- - spec:代码功能的自然语言描述
- outputpath:生成文件的保存路径(默认:H:\code\Daily\generated<时间戳>.py)
生成的代码应包含:
第二阶段:测试创建
代码生成后,使用scripts/create_tests.py生成全面的单元测试:
- - 测试边界情况
- 测试错误条件
- 在适当位置使用pytest夹具
- 输出到H:\code\Daily\tests\目录
第三阶段:测试执行与调试
使用scripts/run_tests.py运行测试:
- - 激活conda环境
- 以详细输出模式执行pytest
- 将结果捕获到报告文件中
如果测试失败,调用scripts/debug_code.py:
- - 分析回溯信息
- 提出修复建议
- 可自动修补代码(需确认)
第四阶段:优化
测试通过后,使用scripts/optimize_code.py:
- - 运行性能分析(cProfile)
- 检查代码质量(pylint/flake8)
- 提出优化建议
- 可自动应用安全优化
脚本参考
所有脚本设计为可直接由Codex调用。它们内部处理conda激活。
- - scripts/generatecode.py - 根据规格生成Python代码
- scripts/createtests.py - 创建pytest/unittest测试套件
- scripts/runtests.py - 执行测试并生成报告
- scripts/debugcode.py - 分析失败原因并提出建议/修补
- scripts/optimize_code.py - 性能分析并改进代码质量
详细参数说明和示例请参见references/script-usage.md。
集成说明
- - 默认conda路径已为此配置硬编码;路径变更时需修改脚本。
- 所有项目文件隔离在H:\code\Daily目录中,保持工作区整洁。
- 脚本假设Windows环境(conda .bat激活方式)。
- 输出报告以JSON和纯文本格式保存,便于后续处理。
何时使用此技能
当任务涉及创建带有完整开发流水线的新Python代码时使用此技能。适用于:
- - 快速原型开发
- 教学示例
- 自动化脚本生成
- 需要测试覆盖的重构任务
- 现有代码优化
不适用于非Python语言或conda环境不可用的情况。