|
2 | 2 |
|
3 | 3 | ## TASK PURPOSE & CRITICAL RULES
|
4 | 4 |
|
5 |
| -**PURPOSE:** Update the cookiecutter template to generate files that exactly match the reference structure in `.templates/leetcode/.example/{{cookiecutter.question_name}}/` |
| 5 | +**PURPOSE:** Update the cookiecutter template to generate files that exactly match the reference structure in `.templates/leetcode/.example/{{cookiecutter.problem_name}}/` |
6 | 6 |
|
7 | 7 | **REFERENCE DIRECTORIES (NEVER MODIFY - THESE ARE EXAMPLES):**
|
8 | 8 |
|
9 |
| -- `.templates/leetcode/.example/{{cookiecutter.question_name}}/` - Shows what the template SHOULD generate |
| 9 | +- `.templates/leetcode/.example/{{cookiecutter.problem_name}}/` - Shows what the template SHOULD generate |
10 | 10 | - `leetcode/.example/` - Generated file examples for comparison
|
11 | 11 |
|
12 | 12 | **ACTUAL TEMPLATE DIRECTORY (MODIFY THIS):**
|
13 | 13 |
|
14 |
| -- `.templates/leetcode/{{cookiecutter.question_name}}/` - The cookiecutter template files to update |
| 14 | +- `.templates/leetcode/{{cookiecutter.problem_name}}/` - The cookiecutter template files to update |
15 | 15 |
|
16 | 16 | **WORKFLOW:**
|
17 | 17 |
|
18 |
| -1. Look at `.templates/leetcode/.example/{{cookiecutter.question_name}}/` to see target structure |
19 |
| -2. Modify `.templates/leetcode/{{cookiecutter.question_name}}/` to match the reference |
20 |
| -3. Generate with `make q-gen` |
21 |
| -4. Compare generated files vs reference with `make q-validate` |
| 18 | +1. Look at `.templates/leetcode/.example/{{cookiecutter.problem_name}}/` to see target structure |
| 19 | +2. Modify `.templates/leetcode/{{cookiecutter.problem_name}}/` to match the reference |
| 20 | +3. Generate with `make p-gen` |
| 21 | +4. Compare generated files vs reference with `make p-validate` |
22 | 22 |
|
23 | 23 | **ERROR PREVENTION:** The template directory does NOT have `.example` in the path!
|
24 | 24 |
|
|
38 | 38 |
|
39 | 39 | - **Tool**: `.amazonq/plan/compare_template_files.py` (already exists - no need to implement)
|
40 | 40 | - **Usage**:
|
41 |
| - - `poetry run python .amazonq/plan/compare_template_files.py generated --question=QUESTION_NAME` - Compare generated files vs reference |
| 41 | + - `poetry run python .amazonq/plan/compare_template_files.py generated --problem=PROBLEM_NAME` - Compare generated files vs reference |
42 | 42 | - **Analysis**: Line-by-line diff of all file types
|
43 | 43 | - **Document**: Exact differences and required changes
|
44 | 44 | - **Verify**: Template variables handle all variations
|
|
48 | 48 | #### Phase 1: Add `__init__.py`
|
49 | 49 |
|
50 | 50 | - **Add**: Empty `__init__.py` file to template
|
51 |
| -- **Validate**: `make q-gen` → `make q-validate` → `make lint` |
| 51 | +- **Validate**: `make p-gen` → `make p-validate` → `make lint` |
52 | 52 |
|
53 | 53 | #### Phase 2: Fix `solution.py`
|
54 | 54 |
|
55 | 55 | - **Update**: Modern syntax (`TreeNode | None`), clean template logic
|
56 |
| -- **Validate**: `make q-gen` → `make q-validate` → `make lint` |
| 56 | +- **Validate**: `make p-gen` → `make p-validate` → `make lint` |
57 | 57 |
|
58 | 58 | #### Phase 3: Fix `tests.py`
|
59 | 59 |
|
60 | 60 | - **Update**: Relative imports (`from .solution`), clean structure
|
61 |
| -- **Validate**: `make q-gen` → `make q-validate` → `make lint` |
| 61 | +- **Validate**: `make p-gen` → `make p-validate` → `make lint` |
62 | 62 |
|
63 | 63 | #### Phase 4: Fix `README.md`
|
64 | 64 |
|
65 | 65 | - **Update**: Clean formatting, proper markdown
|
66 |
| -- **Validate**: `make q-gen` → `make q-validate` → `make lint` |
| 66 | +- **Validate**: `make p-gen` → `make p-validate` → `make lint` |
67 | 67 |
|
68 | 68 | #### Phase 5: Fix `playground.ipynb`
|
69 | 69 |
|
70 | 70 | - **Update**: Clean cells without execution state
|
71 |
| -- **Validate**: `make q-gen` → `make q-validate` → `make lint` |
| 71 | +- **Validate**: `make p-gen` → `make p-validate` → `make lint` |
72 | 72 |
|
73 | 73 | **Benefits**: Isolated debugging, safer progression, easier rollback
|
74 | 74 |
|
|
115 | 115 | ### 5. Template Generation Logic
|
116 | 116 |
|
117 | 117 | - **File**: `.templates/leetcode/gen.py` (already handles variable mapping)
|
118 |
| -- **Integration**: Works with `make q-gen QUESTION=name` (verified in Makefile) |
| 118 | +- **Integration**: Works with `make p-gen PROBLEM=name` (verified in Makefile) |
119 | 119 | - **Update**: Handle new `__init__.py` file
|
120 |
| -- **Process**: JSON → `gen.py` → cookiecutter → `leetcode/$(QUESTION)/` |
| 120 | +- **Process**: JSON → `gen.py` → cookiecutter → `leetcode/$(PROBLEM)/` |
121 | 121 |
|
122 | 122 | ### 6. Automated Validation System
|
123 | 123 |
|
124 | 124 | - **Tool**: Reusable `.amazonq/plan/compare_template_files.py`
|
125 | 125 | - **Usage**:
|
126 | 126 | ```bash
|
127 | 127 | # Validate current template generates correct files
|
128 |
| - poetry run python .amazonq/plan/compare_template_files.py generated --question=invert_binary_tree |
| 128 | + poetry run python .amazonq/plan/compare_template_files.py generated --problem=invert_binary_tree |
129 | 129 | ```
|
130 |
| -- **Makefile**: `make q-validate QUESTION=name` (implemented) |
| 130 | +- **Makefile**: `make p-validate PROBLEM=name` (implemented) |
131 | 131 | - **Test**: Template regression testing
|
132 |
| -- **Ensure**: `make q-gen` + `make lint` + `make q-test` all pass |
| 132 | +- **Ensure**: `make p-gen` + `make lint` + `make p-test` all pass |
133 | 133 |
|
134 | 134 | ### 7. Testing & Validation
|
135 | 135 |
|
136 | 136 | - **Test**: Template generation with existing JSON files
|
137 | 137 | - **Verify**: Generated files match `leetcode/.example/` structure exactly
|
138 | 138 | - **Compare**: Automated diff against reference files
|
139 |
| -- **Ensure**: `make q-gen` works seamlessly |
| 139 | +- **Ensure**: `make p-gen` works seamlessly |
140 | 140 | - **Test**: Recreation process from `.prompt/` files
|
141 | 141 | - **Validate**: Multi-problem type generation
|
142 | 142 |
|
143 | 143 | ## Key Template Variables to Ensure
|
144 | 144 |
|
145 | 145 | ```json
|
146 | 146 | {
|
147 |
| - "question_name": "snake_case_name", |
| 147 | + "problem_name": "snake_case_name", |
148 | 148 | "class_name": "PascalCaseName",
|
149 | 149 | "method_name": "snake_case_method",
|
150 | 150 | "problem_number": "226",
|
|
181 | 181 | ### Automated Validation
|
182 | 182 |
|
183 | 183 | 8. ✅ Automated diff shows no differences vs `leetcode/.example/`
|
184 |
| -9. ✅ `make q-validate` passes for all problem types |
| 184 | +9. ✅ `make p-validate` passes for all problem types |
185 | 185 | 10. ✅ Recreation from `.prompt/` works flawlessly
|
186 | 186 | 11. ✅ All linting passes (`make lint`)
|
187 |
| -12. ✅ Tests run successfully (`make q-test`) |
| 187 | +12. ✅ Tests run successfully (`make p-test`) |
188 | 188 |
|
189 | 189 | ## Files to Modify
|
190 | 190 |
|
191 | 191 | ### Template Files
|
192 | 192 |
|
193 |
| -1. `.templates/leetcode/{{cookiecutter.question_name}}/` |
| 193 | +1. `.templates/leetcode/{{cookiecutter.problem_name}}/` |
194 | 194 | - **Add**: `__init__.py` (empty file)
|
195 | 195 | - **Update**: `solution.py` (modern syntax, imports)
|
196 | 196 | - **Update**: `tests.py` (match `leetcode/.example/` format)
|
|
212 | 212 | ### Validation Tools
|
213 | 213 |
|
214 | 214 | 4. **Reusable**: `.amazonq/plan/compare_template_files.py` (handles both template and generated comparisons)
|
215 |
| -5. **New**: Makefile target `make q-validate` |
| 215 | +5. **New**: Makefile target `make p-validate` |
216 | 216 |
|
217 | 217 | ## Risk Mitigation
|
218 | 218 |
|
|
0 commit comments