|
| 1 | +--- |
| 2 | +description: Python Development Rules for RobotCode |
| 3 | +applyTo: **/*.py |
| 4 | +--- |
| 5 | + |
| 6 | +# Python Development Rules |
| 7 | + |
| 8 | +<ai_meta> |
| 9 | + <parsing_rules> |
| 10 | + - Process XML blocks first for structured data |
| 11 | + - Execute instructions in sequential order |
| 12 | + - Use exact patterns and templates provided |
| 13 | + - Follow MUST/ALWAYS/REQUIRED directives strictly |
| 14 | + </parsing_rules> |
| 15 | + <file_conventions> |
| 16 | + - encoding: UTF-8 |
| 17 | + - line_endings: LF |
| 18 | + - indent: 2 spaces |
| 19 | + - package_structure: packages/ directory |
| 20 | + </file_conventions> |
| 21 | +</ai_meta> |
| 22 | + |
| 23 | +## Package Development |
| 24 | + |
| 25 | +### Package Structure |
| 26 | +- **ALWAYS** develop in packages/ directory |
| 27 | +- **REQUIRED** follow package-based architecture |
| 28 | +- **MUST** use proper __init__.py files for package imports |
| 29 | + |
| 30 | +### Code Style Standards |
| 31 | +- **Formatting:** Follow Black code style with line length 88 |
| 32 | +- **Imports:** isort with profile=black |
| 33 | +- **Type Hints:** Required for all public APIs |
| 34 | +- **Docstrings:** Google style for modules, classes, and functions |
| 35 | + |
| 36 | +### Environment Setup |
| 37 | +```bash |
| 38 | +hatch run install-packages # Install all packages in development mode |
| 39 | +``` |
| 40 | + |
| 41 | +### Testing Commands |
| 42 | +```bash |
| 43 | +hatch run test.rf70:test # Test with Robot Framework 7.0 |
| 44 | +hatch run test.rf70.py311:test # Specific Python + RF combination |
| 45 | +hatch run cov # Run with coverage reporting |
| 46 | +pytest --regtest2-reset # Update test snapshots |
| 47 | +``` |
| 48 | + |
| 49 | +### Code Quality |
| 50 | +```bash |
| 51 | +hatch run lint:all # All linting checks (black, isort, flake8) |
| 52 | +hatch run lint:fix # Auto-fix style issues |
| 53 | +``` |
| 54 | + |
| 55 | +## CLI Error Handling Pattern |
| 56 | + |
| 57 | +**REQUIRED** pattern for all CLI tools: |
| 58 | +```python |
| 59 | +try: |
| 60 | + result = execute_command() |
| 61 | +except Exception as e: |
| 62 | + app.error(f"Failed to execute: {e}") |
| 63 | +``` |
| 64 | + |
| 65 | +## Package-Specific Guidelines |
| 66 | + |
| 67 | +### Core Package (`packages/core/`) |
| 68 | +- **Base utilities and shared functionality** |
| 69 | +- **MUST** be importable by all other packages |
| 70 | +- **NO** dependencies on other RobotCode packages |
| 71 | + |
| 72 | +### Language Server (`packages/language_server/`) |
| 73 | +- **LSP implementation for IDE integration** |
| 74 | +- **ALWAYS** use asyncio patterns |
| 75 | +- **REQUIRED** proper error isolation per workspace |
| 76 | + |
| 77 | +### Debugger (`packages/debugger/`) |
| 78 | +- **Debug Adapter Protocol implementation** |
| 79 | +- **MUST** handle multi-workspace scenarios |
| 80 | +- **REQUIRED** proper session management |
| 81 | + |
| 82 | +### Runner (`packages/runner/`) |
| 83 | +- **Enhanced Robot Framework execution tools** |
| 84 | +- **ALWAYS** use Robot Framework native parser |
| 85 | +- **REQUIRED** configuration via robot.toml |
| 86 | + |
| 87 | +### Testing Requirements |
| 88 | + |
| 89 | +### Matrix Testing |
| 90 | +- **COMPREHENSIVE** testing across Python 3.8-3.13 |
| 91 | +- **MATRIX** testing with Robot Framework 5.0-7.3 |
| 92 | +- **INTEGRATION** tests in tests/robotcode/ with real scenarios |
| 93 | +- **SNAPSHOT** testing with pytest regtest2 |
| 94 | + |
| 95 | +### Test Execution |
| 96 | +- **USE** `pytest --regtest2-reset` to update snapshots |
| 97 | +- **RUN** specific environments: `hatch run test.rf70.py311:test` |
| 98 | +- **COVERAGE** reporting with `hatch run cov` |
| 99 | + |
| 100 | +## Configuration System |
| 101 | + |
| 102 | +### robot.toml Configuration |
| 103 | +- **IMPLEMENT** robot.toml parsing throughout CLI and language server |
| 104 | +- **SUPPORT** profile management and inheritance |
| 105 | +- **VALIDATE** configuration options |
| 106 | + |
| 107 | +### Multi-Platform Consistency |
| 108 | +- **ENSURE** consistent behavior across VS Code and IntelliJ |
| 109 | +- **MAINTAIN** unified configuration approach |
| 110 | +- **DOCUMENT** platform-specific differences |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +*These Python development rules ensure consistent, high-quality code across all RobotCode packages.* |
0 commit comments