|
| 1 | +--- |
| 2 | +title: Python Code Style and Formatting Rules |
| 3 | +description: Rules for writing Python code with proper formatting and output standards |
| 4 | +globs: **/*.py |
| 5 | +alwaysApply: true |
| 6 | +--- |
| 7 | + |
| 8 | +## Code Quality and Formatting Tools |
| 9 | + |
| 10 | +### Code Review with Sourcery |
| 11 | + - Use Sourcery for automated code review and fixes: |
| 12 | + ```bash |
| 13 | + # Review and fix a specific file |
| 14 | + sourcery review --fix path/to/file.py |
| 15 | + |
| 16 | + # Review and fix all Python files in a directory |
| 17 | + sourcery review --fix chapters/feature_flags/local/scripts/ |
| 18 | + |
| 19 | + # Review without applying fixes (dry run) |
| 20 | + sourcery review path/to/file.py |
| 21 | + ``` |
| 22 | + - Sourcery provides suggestions for: |
| 23 | + - Code simplification and refactoring |
| 24 | + - Removing unnecessary else clauses |
| 25 | + - Simplifying conditionals |
| 26 | + - Improving variable naming |
| 27 | + - Reducing complexity |
| 28 | + - Run Sourcery before committing code to catch common issues early. |
| 29 | + - Sourcery suggestions should be reviewed and applied when they improve code readability and maintainability. |
| 30 | + |
| 31 | +## Code Output and Formatting |
| 32 | + |
| 33 | +### Prohibited Patterns |
| 34 | + |
| 35 | +- **DO NOT USE decorative separator lines:** |
| 36 | + - `print("=" * 80)` |
| 37 | + - `print("-" * 50)` |
| 38 | + - Any decorative print statements using repeated characters |
| 39 | +- **DO NOT USE empty print statements for spacing:** |
| 40 | + - `print()` used only for adding blank lines in output |
| 41 | +- **DO NOT USE bullet point summary statements:** |
| 42 | + - `print(" • AppConfig configuration was updated...")` |
| 43 | + - `print(" - Key finding: ...")` |
| 44 | + - `print(" * Summary: ...")` |
| 45 | + - Any print statements with bullet points or indented summary text |
| 46 | +- **DO NOT USE emojis in output (Python scripts only):** |
| 47 | + - `print("✅ Success")` |
| 48 | + - `print("❌ Error")` |
| 49 | + - `print("📊 Step 1: ...")` |
| 50 | + - Any emoji characters in print statements |
| 51 | + - **Exception**: Emojis and colors are OK in Makefiles |
| 52 | +- **DO NOT USE leading spaces in print statements:** |
| 53 | + - `print(" Text with leading spaces")` |
| 54 | + - `print(f" Testing etc")` |
| 55 | + - Use plain text without leading spaces for indentation |
| 56 | +
|
| 57 | +### Recommended Patterns |
| 58 | +
|
| 59 | +- **DO USE:** |
| 60 | + - Direct, informative print statements without decorative elements |
| 61 | + - Concise output that focuses on actionable information |
| 62 | + - No extra spacing or formatting beyond what's necessary |
| 63 | + - Plain text status indicators (e.g., "Success:", "Error:", "Step 1:") |
| 64 | + - **Makefiles**: Emojis and colors are acceptable, but avoid extra spacing |
| 65 | +
|
| 66 | +### Rationale |
| 67 | +
|
| 68 | +Cleaner, more professional output that's easier to parse programmatically with less visual clutter. |
0 commit comments