|
4 | 4 |
|
5 | 5 | ### Modern Python Project Template | Cookiecutter | Best Practices | Production-Ready |
6 | 6 |
|
7 | | -[](https://python.org) |
| 7 | +[](https://python.org) |
8 | 8 | [](https://github.com/astral-sh/ruff) |
9 | 9 | [](https://pre-commit.com/) |
10 | 10 | [](LICENSE) |
|
38 | 38 |
|
39 | 39 | ```mermaid |
40 | 40 | flowchart LR |
41 | | - subgraph DEV["🖥️ Development"] |
42 | | - A["✏️ Write<br/>Code"] --> B["💾 Save<br/>File"] |
| 41 | + subgraph DEV["Development Phase"] |
| 42 | + A[Write Code] -->|save| B[Save File] |
43 | 43 | end |
44 | 44 |
|
45 | | - subgraph VCS["📦 Version Control"] |
46 | | - B --> C["📝 Stage<br/>Changes"] |
47 | | - C --> D["✅ Commit"] |
48 | | - D --> E["🚀 Push<br/>to Remote"] |
| 45 | + subgraph VCS["Version Control"] |
| 46 | + B -->|stage| C[Stage Changes] |
| 47 | + C -->|commit| D[Commit] |
| 48 | + D -->|push| E[Push to Remote] |
49 | 49 | end |
50 | 50 |
|
51 | | - subgraph GATES["🛡️ Automated Quality Gates"] |
| 51 | + subgraph GATES["Quality Gates"] |
52 | 52 | direction TB |
53 | | - D -.-> G1["🔍 Ruff<br/>Lint + Format"] |
54 | | - D -.-> G2["🔷 Mypy<br/>Type Check"] |
55 | | - D -.-> G3["🔒 Bandit<br/>Security Scan"] |
56 | | - D -.-> G4["📋 Commitizen<br/>Conventional Commits"] |
| 53 | + G1[Ruff - Lint & Format] |
| 54 | + G2[Mypy - Type Check] |
| 55 | + G3[Bandit - Security Scan] |
| 56 | + G4[Commitizen - Commit Validation] |
57 | 57 | end |
58 | 58 |
|
59 | | - style DEV fill:#e1f5fe,stroke:#01579b |
60 | | - style VCS fill:#f3e5f5,stroke:#4a148c |
61 | | - style GATES fill:#fff3e0,stroke:#e65100 |
| 59 | + D -.->|triggers| G1 |
| 60 | + D -.->|triggers| G2 |
| 61 | + D -.->|triggers| G3 |
| 62 | + D -.->|triggers| G4 |
62 | 63 | ``` |
63 | 64 |
|
64 | 65 | ### Project Structure |
65 | 66 |
|
66 | 67 | ```mermaid |
67 | 68 | flowchart TB |
68 | | - subgraph ROOT["📁 project_name/"] |
| 69 | + subgraph ROOT["project_name/"] |
69 | 70 | direction TB |
70 | | - subgraph SRC["📂 src/"] |
71 | | - subgraph PKG["📂 project_name/"] |
72 | | - INIT["📄 __init__.py<br/><small>Package init</small>"] |
73 | | - MAIN["📄 main.py<br/><small>Core logic</small>"] |
74 | | - CLI["📄 my_cli.py<br/><small>Typer CLI</small>"] |
75 | | - RICH["📄 rich_demo.py<br/><small>Rich UI demos</small>"] |
| 71 | + subgraph SRC["src/"] |
| 72 | + subgraph PKG["project_name/"] |
| 73 | + INIT["__init__.py"] |
| 74 | + MAIN["main.py"] |
| 75 | + CLI["my_cli.py"] |
| 76 | + RICH["rich_demo.py"] |
76 | 77 | end |
77 | 78 | end |
78 | | - subgraph TESTS["📂 tests/"] |
79 | | - TEST["📄 test_main.py<br/><small>Pytest suite</small>"] |
| 79 | + subgraph TESTS["tests/"] |
| 80 | + TEST["test_main.py"] |
80 | 81 | end |
81 | | - PYPROJ["📄 pyproject.toml<br/><small>Unified config</small>"] |
82 | | - PRECOMMIT["📄 .pre-commit-config.yaml<br/><small>Git hooks</small>"] |
83 | | - README["📄 README.md<br/><small>Documentation</small>"] |
84 | | - GITIGNORE["📄 .gitignore"] |
| 82 | + PYPROJ["pyproject.toml"] |
| 83 | + PRECOMMIT[".pre-commit-config.yaml"] |
| 84 | + README["README.md"] |
| 85 | + GITIGNORE[".gitignore"] |
85 | 86 | end |
86 | 87 |
|
87 | | - style ROOT fill:#e8f5e9,stroke:#2e7d32 |
88 | | - style SRC fill:#e3f2fd,stroke:#1565c0 |
89 | | - style PKG fill:#fff8e1,stroke:#f9a825 |
90 | | - style TESTS fill:#fce4ec,stroke:#c2185b |
| 88 | + INIT ---|Package initialization| PKG |
| 89 | + MAIN ---|Core application logic| PKG |
| 90 | + CLI ---|Typer CLI interface| PKG |
| 91 | + RICH ---|Rich terminal demos| PKG |
| 92 | + TEST ---|Pytest test suite| TESTS |
| 93 | + PYPROJ ---|Unified Python config| ROOT |
| 94 | + PRECOMMIT ---|Git hooks config| ROOT |
91 | 95 | ``` |
92 | 96 |
|
93 | 97 | --- |
@@ -122,7 +126,7 @@ flowchart TB |
122 | 126 | ## 🚀 Quick Start |
123 | 127 |
|
124 | 128 | ### Prerequisites |
125 | | -- Python {{ cookiecutter.python_version }}+ |
| 129 | +- Python 3.11+ |
126 | 130 | - [Cookiecutter](https://cookiecutter.readthedocs.io/) (`pip install cookiecutter`) |
127 | 131 |
|
128 | 132 | ### Generate Your Project |
@@ -152,49 +156,36 @@ pre-commit install --install-hooks |
152 | 156 | ## 📦 Tool Stack |
153 | 157 |
|
154 | 158 | ```mermaid |
155 | | -%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#e8f5e9', 'primaryBorderColor': '#2e7d32'}}}%% |
156 | 159 | flowchart TB |
157 | | - subgraph TOOLCHAIN["🐍 MODERN PYTHON TOOLCHAIN"] |
158 | | - direction TB |
159 | | - subgraph ROW1[" "] |
160 | | - direction LR |
161 | | - subgraph RUFF["🔍 RUFF<br/>Linting & Formatting"] |
162 | | - R1["✓ Replaces Black"] |
163 | | - R2["✓ Replaces isort"] |
164 | | - R3["✓ Replaces Flake8"] |
165 | | - R4["⚡ 10-100x faster"] |
166 | | - end |
167 | | - subgraph MYPY["🔷 MYPY<br/>Type Checking"] |
168 | | - M1["✓ Strict mode"] |
169 | | - M2["✓ Type inference"] |
170 | | - M3["✓ Plugin support"] |
171 | | - M4["✓ IDE integration"] |
172 | | - end |
| 160 | + subgraph TOOLCHAIN["Modern Python Toolchain"] |
| 161 | + direction LR |
| 162 | + subgraph LINT["Linting & Formatting"] |
| 163 | + RUFF[Ruff] |
173 | 164 | end |
174 | | - subgraph ROW2[" "] |
175 | | - direction LR |
176 | | - subgraph PYTEST["🧪 PYTEST<br/>Testing"] |
177 | | - P1["✓ Async support"] |
178 | | - P2["✓ Coverage report"] |
179 | | - P3["✓ Fixtures"] |
180 | | - P4["✓ Parameterized"] |
181 | | - end |
182 | | - subgraph BANDIT["🔒 BANDIT<br/>Security"] |
183 | | - B1["✓ SAST scanning"] |
184 | | - B2["✓ OWASP checks"] |
185 | | - B3["✓ CI integration"] |
186 | | - B4["✓ Custom rules"] |
187 | | - end |
| 165 | + subgraph TYPE["Type Checking"] |
| 166 | + MYPY[Mypy] |
| 167 | + end |
| 168 | + subgraph TEST["Testing"] |
| 169 | + PYTEST[Pytest] |
| 170 | + end |
| 171 | + subgraph SEC["Security"] |
| 172 | + BANDIT[Bandit] |
188 | 173 | end |
189 | 174 | end |
190 | 175 |
|
191 | | - style TOOLCHAIN fill:#fafafa,stroke:#424242 |
192 | | - style RUFF fill:#d7ff64,stroke:#827717 |
193 | | - style MYPY fill:#bbdefb,stroke:#1565c0 |
194 | | - style PYTEST fill:#fff9c4,stroke:#f9a825 |
195 | | - style BANDIT fill:#ffcdd2,stroke:#c62828 |
196 | | - style ROW1 fill:transparent,stroke:transparent |
197 | | - style ROW2 fill:transparent,stroke:transparent |
| 176 | + RUFF ---|Replaces Black, isort, Flake8| LINT |
| 177 | + RUFF ---|10-100x faster| LINT |
| 178 | + MYPY ---|Strict mode enabled| TYPE |
| 179 | + MYPY ---|Full type inference| TYPE |
| 180 | + PYTEST ---|Async & coverage support| TEST |
| 181 | + PYTEST ---|Fixtures & parameterized| TEST |
| 182 | + BANDIT ---|SAST scanning| SEC |
| 183 | + BANDIT ---|OWASP compliance| SEC |
| 184 | +
|
| 185 | + CODE[Your Code] -->|lint & format| RUFF |
| 186 | + CODE -->|type check| MYPY |
| 187 | + CODE -->|test| PYTEST |
| 188 | + CODE -->|security scan| BANDIT |
198 | 189 | ``` |
199 | 190 |
|
200 | 191 | --- |
@@ -236,32 +227,30 @@ dev = [ |
236 | 227 |
|
237 | 228 | ```mermaid |
238 | 229 | flowchart TD |
239 | | - A["📝 <b>git add .</b><br/><small>Stage changes</small>"] --> B["💬 <b>git commit -m 'feat: ...'</b><br/><small>Create commit</small>"] |
| 230 | + A[git add .] -->|stage changes| B[git commit] |
240 | 231 |
|
241 | | - B --> HOOKS |
| 232 | + B -->|triggers| HOOKS |
242 | 233 |
|
243 | | - subgraph HOOKS["🔗 PRE-COMMIT HOOKS"] |
| 234 | + subgraph HOOKS["Pre-commit Hooks"] |
244 | 235 | direction TB |
245 | | - H1["1️⃣ <b>ruff check --fix</b><br/><small>Auto-fix lint issues</small>"] |
246 | | - H2["2️⃣ <b>ruff format</b><br/><small>Format code</small>"] |
247 | | - H3["3️⃣ <b>mypy</b><br/><small>Type check</small>"] |
248 | | - H4["4️⃣ <b>bandit</b><br/><small>Security scan</small>"] |
249 | | - H5["5️⃣ <b>commitizen</b><br/><small>Validate message</small>"] |
250 | | - H1 --> H2 --> H3 --> H4 --> H5 |
| 236 | + H1[ruff check --fix] |
| 237 | + H2[ruff format] |
| 238 | + H3[mypy] |
| 239 | + H4[bandit] |
| 240 | + H5[commitizen] |
| 241 | + H1 -->|auto-fix lint| H2 |
| 242 | + H2 -->|format code| H3 |
| 243 | + H3 -->|type check| H4 |
| 244 | + H4 -->|security scan| H5 |
| 245 | + H5 -->|validate message| DONE[Hooks Complete] |
251 | 246 | end |
252 | 247 |
|
253 | | - HOOKS --> CHECK{All Checks<br/>Pass?} |
254 | | -
|
255 | | - CHECK -->|"✅ Yes"| SUCCESS["🎉 <b>Commit Succeeds</b><br/><small>Changes recorded</small>"] |
256 | | - CHECK -->|"❌ No"| FAIL["🔧 <b>Commit Blocked</b><br/><small>Fix issues & retry</small>"] |
257 | | - FAIL --> A |
| 248 | + HOOKS --> CHECK{All Checks Pass?} |
258 | 249 |
|
259 | | - style A fill:#e3f2fd,stroke:#1565c0 |
260 | | - style B fill:#e3f2fd,stroke:#1565c0 |
261 | | - style HOOKS fill:#fff3e0,stroke:#e65100 |
262 | | - style CHECK fill:#f3e5f5,stroke:#7b1fa2 |
263 | | - style SUCCESS fill:#e8f5e9,stroke:#2e7d32 |
264 | | - style FAIL fill:#ffebee,stroke:#c62828 |
| 250 | + CHECK -->|yes| SUCCESS[Commit Succeeds] |
| 251 | + CHECK -->|no| FAIL[Commit Blocked] |
| 252 | + FAIL -->|fix issues| A |
| 253 | + SUCCESS -->|optional| PUSH[git push] |
265 | 254 | ``` |
266 | 255 |
|
267 | 256 | ### Commands Reference |
|
0 commit comments