Skip to content

Commit f3365fc

Browse files
committed
Add development guidelines document outlining core rules, coding best practices, and error resolution strategies for the codebase.
1 parent 4f8d02f commit f3365fc

1 file changed

Lines changed: 171 additions & 0 deletions

File tree

claude.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Development Guidelines
2+
3+
This document contains critical information about working with this codebase. Follow these guidelines precisely.
4+
5+
## Core Development Rules
6+
7+
1. Package Management
8+
- ONLY use uv, NEVER pip
9+
- Installation: `uv add package`
10+
- Running tools: `uv run tool`
11+
- Upgrading: `uv add --dev package --upgrade-package package`
12+
- FORBIDDEN: `uv pip install`, `@latest` syntax
13+
14+
2. Code Quality
15+
- Type hints required for all code
16+
- Public APIs must have docstrings
17+
- Functions must be focused and small
18+
- Follow existing patterns exactly
19+
- Line length: 88 chars maximum
20+
21+
3. Testing Requirements
22+
- Framework: `uv run pytest`
23+
- Async testing: use anyio, not asyncio
24+
- Coverage: test edge cases and errors
25+
- New features require tests
26+
- Bug fixes require regression tests
27+
28+
4. Code Style
29+
- PEP 8 naming (snake_case for functions/variables)
30+
- Class names in PascalCase
31+
- Constants in UPPER_SNAKE_CASE
32+
- Document with docstrings
33+
- Use f-strings for formatting
34+
35+
- For commits fixing bugs or adding features based on user reports add:
36+
```bash
37+
git commit --trailer "Reported-by:<name>"
38+
```
39+
Where `<name>` is the name of the user.
40+
41+
- For commits related to a Github issue, add
42+
```bash
43+
git commit --trailer "Github-Issue:#<number>"
44+
```
45+
- NEVER ever mention a `co-authored-by` or similar aspects. In particular, never
46+
mention the tool used to create the commit message or PR.
47+
48+
## Development Philosophy
49+
50+
- **Simplicity**: Write simple, straightforward code
51+
- **Readability**: Make code easy to understand
52+
- **Performance**: Consider performance without sacrificing readability
53+
- **Maintainability**: Write code that's easy to update
54+
- **Testability**: Ensure code is testable
55+
- **Reusability**: Create reusable components and functions
56+
- **Less Code = Less Debt**: Minimize code footprint
57+
58+
## Coding Best Practices
59+
60+
- **Early Returns**: Use to avoid nested conditions
61+
- **Descriptive Names**: Use clear variable/function names (prefix handlers with "handle")
62+
- **Constants Over Functions**: Use constants where possible
63+
- **DRY Code**: Don't repeat yourself
64+
- **Functional Style**: Prefer functional, immutable approaches when not verbose
65+
- **Minimal Changes**: Only modify code related to the task at hand
66+
- **Function Ordering**: Define composing functions before their components
67+
- **TODO Comments**: Mark issues in existing code with "TODO:" prefix
68+
- **Simplicity**: Prioritize simplicity and readability over clever solutions
69+
- **Build Iteratively** Start with minimal functionality and verify it works before adding complexity
70+
- **Run Tests**: Test your code frequently with realistic inputs and validate outputs
71+
- **Build Test Environments**: Create testing environments for components that are difficult to validate directly
72+
- **Functional Code**: Use functional and stateless approaches where they improve clarity
73+
- **Clean logic**: Keep core logic clean and push implementation details to the edges
74+
- **File Organsiation**: Balance file organization with simplicity - use an appropriate number of files for the project scale
75+
76+
77+
## Core Components
78+
79+
- `__main__.py`: Main entry point
80+
- `api`: API for the project
81+
- `tasks`: Tasks for the project
82+
- `models`: Models for the project
83+
- `loggers`: Loggers for the project
84+
- `utils`: Utility functions for the project
85+
- `tests`: Tests for the project
86+
- `configs`: Configs for the project
87+
- `data`: Data for the project
88+
89+
Launch Command:
90+
91+
```bash
92+
python -m lmms_eval --model qwen2_5_vl --model_args pretrained=Qwen/Qwen2.5-VL-3B-Instruct,max_pixels=12845056,attn_implementation=sdpa --tasks mmmu,mme,mmlu_flan_n_shot_generative --batch_size 128 --limit 8 --device cuda:0
93+
```
94+
95+
96+
97+
98+
## Pull Requests
99+
100+
- Create a detailed message of what changed. Focus on the high level description of
101+
the problem it tries to solve, and how it is solved. Don't go into the specifics of the
102+
code unless it adds clarity.
103+
104+
- Always add `ArthurClune` as reviewer.
105+
106+
- NEVER ever mention a `co-authored-by` or similar aspects. In particular, never
107+
mention the tool used to create the commit message or PR.
108+
109+
## Python Tools
110+
111+
## Code Formatting
112+
113+
1. Ruff
114+
- Format: `uv run ruff format .`
115+
- Check: `uv run ruff check .`
116+
- Fix: `uv run ruff check . --fix`
117+
- Critical issues:
118+
- Line length (88 chars)
119+
- Import sorting (I001)
120+
- Unused imports
121+
- Line wrapping:
122+
- Strings: use parentheses
123+
- Function calls: multi-line with proper indent
124+
- Imports: split into multiple lines
125+
126+
2. Type Checking
127+
- Tool: `uv run pyright`
128+
- Requirements:
129+
- Explicit None checks for Optional
130+
- Type narrowing for strings
131+
- Version warnings can be ignored if checks pass
132+
133+
3. Pre-commit
134+
- Config: `.pre-commit-config.yaml`
135+
- Runs: on git commit
136+
- Tools: Prettier (YAML/JSON), Ruff (Python)
137+
- Ruff updates:
138+
- Check PyPI versions
139+
- Update config rev
140+
- Commit config first
141+
142+
## Error Resolution
143+
144+
1. CI Failures
145+
- Fix order:
146+
1. Formatting
147+
2. Type errors
148+
3. Linting
149+
- Type errors:
150+
- Get full line context
151+
- Check Optional types
152+
- Add type narrowing
153+
- Verify function signatures
154+
155+
2. Common Issues
156+
- Line length:
157+
- Break strings with parentheses
158+
- Multi-line function calls
159+
- Split imports
160+
- Types:
161+
- Add None checks
162+
- Narrow string types
163+
- Match existing patterns
164+
165+
3. Best Practices
166+
- Check git status before commits
167+
- Run formatters before type checks
168+
- Keep changes minimal
169+
- Follow existing patterns
170+
- Document public APIs
171+
- Test thoroughly

0 commit comments

Comments
 (0)