Skip to content

Commit fbab795

Browse files
authored
feat: implement cli (#45)
- implement cli for lcpy to gen/list leetcode problems
1 parent 1c4c78e commit fbab795

File tree

125 files changed

+1886
-915
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+1886
-915
lines changed

.amazonq/rules/development-rules.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Use snake_case for Python methods
1212
- Include type hints: `list[str]`, `dict[str, int]`, `Type | None`
1313
- Follow linting rules (black, isort, ruff, mypy)
14+
- **NO noise docstrings**: Avoid docstrings that merely restate the function name (e.g., `"""Test CLI help command."""` for `test_cli_help()`). Only add docstrings when they provide meaningful context beyond what the code itself conveys
1415

1516
## Testing
1617

.amazonq/rules/problem-creation.md

Lines changed: 14 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
When user requests a problem by **number** or **name/slug**, the assistant will:
66

7-
1. **Scrape** problem data using `.templates/leetcode/scrape.py`
7+
1. **Scrape** problem data using `lcpy scrape`
88
2. **Transform** data into proper JSON template format
99
3. **CRITICAL: Include images** - Extract image URLs from scraped data and add to readme_examples with format: `![Example N](image_url)\n\n` before code blocks
1010
- Check scraped data for image URLs in the `raw_content` field
1111
- Look for patterns: `https://assets.leetcode.com/uploads/...` or `<img alt="" src="..." />`
1212
- Common patterns: `kthtree1.jpg`, `kthtree2.jpg`, `clone_graph.png`, `container.jpg`
1313
- Images provide crucial visual context, especially for tree and graph problems
1414
- Always verify images are included in `readme_examples` and accessible
15-
4. **Create** JSON file in `.templates/leetcode/json/{problem_name}.json`
15+
4. **Create** JSON file in `leetcode_py/cli/resources/leetcode/json/problems/{problem_name}.json`
1616
5. **Update** Makefile with `PROBLEM ?= {problem_name}`
1717
6. **Generate** problem structure using `make p-gen`
1818
7. **Verify** with `make p-lint` - fix template issues in JSON if possible, or manually fix generated files if template limitations
@@ -22,15 +22,15 @@ When user requests a problem by **number** or **name/slug**, the assistant will:
2222

2323
```bash
2424
# Fetch by number
25-
poetry run python .templates/leetcode/scrape.py -n 1
25+
lcpy scrape -n 1
2626

2727
# Fetch by slug
28-
poetry run python .templates/leetcode/scrape.py -s "two-sum"
28+
lcpy scrape -s "two-sum"
2929
```
3030

3131
## JSON Template Format
3232

33-
Required fields for `.templates/leetcode/json/{problem_name}.json`:
33+
Required fields for `leetcode_py/cli/resources/leetcode/json/problems/{problem_name}.json`:
3434

3535
**CRITICAL: Use single quotes for Python strings in playground fields to avoid JSON escaping issues with Jupyter notebooks.**
3636

@@ -41,61 +41,15 @@ Required fields for `.templates/leetcode/json/{problem_name}.json`:
4141
- `playground_assertion`: Use single quotes for string literals
4242
- Double quotes in JSON + cookiecutter + Jupyter notebook = triple escaping issues
4343

44-
**Reference examples in `.templates/leetcode/examples/` for complete templates:**
45-
46-
- `basic.json5` - All standard problems (array, string, tree, linked list, etc.)
47-
- `design.json5` - Data structure design problems (LRU Cache, etc.)
48-
49-
````json
50-
{
51-
"problem_name": "two_sum",
52-
"solution_class_name": "Solution",
53-
"problem_number": "1",
54-
"problem_title": "Two Sum",
55-
"difficulty": "Easy",
56-
"topics": "Array, Hash Table",
57-
"tags": ["grind-75"],
58-
"readme_description": "Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`.",
59-
"readme_examples": [
60-
{
61-
"content": "![Example 1](https://example.com/image1.jpg)\n\n```\nInput: nums = [2,7,11,15], target = 9\nOutput: [0,1]\n```\n**Explanation:** Because nums[0] + nums[1] == 9, we return [0, 1]."
62-
}
63-
],
64-
"readme_constraints": "- 2 <= nums.length <= 10^4\n- -10^9 <= nums[i] <= 10^9\n- -10^9 <= target <= 10^9\n- Only one valid answer exists.",
65-
"readme_additional": "",
66-
"solution_imports": "",
67-
"solution_methods": [
68-
{
69-
"name": "two_sum",
70-
"parameters": "nums: list[int], target: int",
71-
"return_type": "list[int]",
72-
"dummy_return": "[]"
73-
}
74-
],
75-
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
76-
"test_class_name": "TwoSum",
77-
"test_helper_methods": [
78-
{
79-
"name": "setup_method",
80-
"parameters": "",
81-
"body": "self.solution = Solution()"
82-
}
83-
],
84-
"test_methods": [
85-
{
86-
"name": "test_two_sum",
87-
"parametrize": "nums, target, expected",
88-
"parametrize_typed": "nums: list[int], target: int, expected: list[int]",
89-
"test_cases": "[([2, 7, 11, 15], 9, [0, 1]), ([3, 2, 4], 6, [1, 2])]",
90-
"body": "result = self.solution.two_sum(nums, target)\nassert result == expected"
91-
}
92-
],
93-
"playground_imports": "from solution import Solution",
94-
"playground_test_case": "# Example test case\nnums = [2, 7, 11, 15]\ntarget = 9\nexpected = [0, 1]",
95-
"playground_execution": "result = Solution().two_sum(nums, target)\nresult",
96-
"playground_assertion": "assert result == expected"
97-
}
98-
````
44+
**Reference the complete template example:**
45+
46+
See `leetcode_py/cli/resources/leetcode/examples/example.json5` for a comprehensive template with:
47+
48+
- All field definitions and variations
49+
- Comments explaining each field
50+
- Examples for different problem types (basic, tree, linked list, design, trie)
51+
- Proper JSON escaping rules for playground fields
52+
- Multiple solution class patterns
9953

10054
## Naming Conventions
10155

.amazonq/rules/test-case-enhancement.md renamed to .amazonq/rules/test-quality-assurance.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Test Case Enhancement Rules
1+
# Test Quality Assurance Rules
22

33
## Simple Enhancement Workflow
44

@@ -7,7 +7,7 @@ When user requests test case enhancement or **test reproducibility verification*
77
### 1. Problem Resolution
88

99
- Use active file context or user-provided problem name
10-
- If unclear, run: `poetry run python .templates/check_test_cases.py --threshold=10 --max=1`
10+
- If unclear, run: `poetry run python -m leetcode_py.tools.check_test_cases --threshold=10 --max=1`
1111

1212
### 2. Enhancement Process
1313

@@ -55,20 +55,35 @@ mv .cache/leetcode/{problem_name} leetcode/{problem_name}
5555

5656
## Quick Commands
5757

58+
### CLI Commands (Recommended)
59+
5860
```bash
59-
# Find problems needing enhancement
60-
poetry run python .templates/check_test_cases.py --threshold=10
61+
# Generate enhanced problem
62+
lcpy gen -s {problem_name} -o leetcode --force
6163

6264
# Test specific problem
6365
make p-test PROBLEM={problem_name}
6466

65-
# Generate from JSON template
66-
make p-gen PROBLEM={problem_name} FORCE=1
67-
6867
# Lint check
6968
make p-lint PROBLEM={problem_name}
7069
```
7170

71+
### Development Commands
72+
73+
```bash
74+
# Find problems needing enhancement
75+
poetry run python -m leetcode_py.tools.check_test_cases --threshold=10
76+
77+
# Check all problems (no limit)
78+
poetry run python -m leetcode_py.tools.check_test_cases --threshold=10 --max=none
79+
80+
# Check with custom threshold
81+
poetry run python -m leetcode_py.tools.check_test_cases --threshold=12
82+
83+
# Generate from JSON template (uses lcpy internally)
84+
make p-gen PROBLEM={problem_name} FORCE=1
85+
```
86+
7287
## Test Reproducibility Verification
7388

7489
Use this same workflow when CI tests fail due to reproducibility issues:

.github/workflows/ci-test-reproducibility.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
fi
6363
6464
- name: Check test case count
65-
run: poetry run python .templates/check_test_cases.py --threshold=10 --max=100
65+
run: poetry run python -m leetcode_py.tools.check_test_cases --threshold=10 --max=none
6666

6767
- name: Backup existing problems
6868
run: |

.github/workflows/ci-test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ jobs:
3333
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
3434

3535
- name: Install dependencies
36-
run: poetry install --no-interaction --no-ansi
36+
run: |
37+
poetry install --no-interaction --no-ansi
38+
poetry run pip install -e .
3739
3840
- name: Cache Graphviz installation
3941
id: cache-graphviz

.templates/check_test_cases.py

Lines changed: 0 additions & 95 deletions
This file was deleted.

.templates/leetcode/gen.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

.templates/leetcode/scrape.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Use an LLM assistant (Cursor, GitHub Copilot Chat, Amazon Q) with the rule files
1313

1414
### 2. Enhance Test Cases
1515

16-
- Include `.amazonq/rules/test-case-enhancement.md` in your LLM context
16+
- Include `.amazonq/rules/test-quality-assurance.md` in your LLM context
1717
- Ask: "Enhance test cases for [problem_name] problem"
1818

1919
### 3. Improve Helper Classes

0 commit comments

Comments
 (0)