Skip to content

Commit fdf8992

Browse files
committed
ai(rules[claude]) Add CLAUDE.md for claude code
1 parent b5953b4 commit fdf8992

File tree

1 file changed

+259
-0
lines changed

1 file changed

+259
-0
lines changed

CLAUDE.md

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## CRITICAL REQUIREMENTS
6+
7+
### Test Success
8+
- ALL tests MUST pass for code to be considered complete and working
9+
- Never describe code as "working as expected" if there are ANY failing tests
10+
- Even if specific feature tests pass, failing tests elsewhere indicate broken functionality
11+
- Changes that break existing tests must be fixed before considering implementation complete
12+
- A successful implementation must pass linting, type checking, AND all existing tests
13+
14+
## Project Overview
15+
16+
libvcs is a lite, typed Python tool for:
17+
- Detecting and parsing URLs for Git, Mercurial, and Subversion repositories
18+
- Providing command abstractions for git, hg, and svn
19+
- Synchronizing repositories locally
20+
- Creating pytest fixtures for testing with temporary repositories
21+
22+
The library powers [vcspull](https://www.github.com/vcs-python/vcspull/), a tool for managing and synchronizing multiple git, svn, and mercurial repositories.
23+
24+
## Development Environment
25+
26+
This project uses:
27+
- Python 3.9+
28+
- [uv](https://github.com/astral-sh/uv) for dependency management
29+
- [ruff](https://github.com/astral-sh/ruff) for linting and formatting
30+
- [mypy](https://github.com/python/mypy) for type checking
31+
- [pytest](https://docs.pytest.org/) for testing
32+
33+
## Common Commands
34+
35+
### Setting Up Environment
36+
37+
```bash
38+
# Install dependencies
39+
uv pip install --editable .
40+
uv pip sync
41+
42+
# Install with development dependencies
43+
uv pip install --editable . -G dev
44+
```
45+
46+
### Running Tests
47+
48+
```bash
49+
# Run all tests
50+
make test
51+
# or directly with pytest
52+
uv run pytest
53+
54+
# Run a single test file
55+
uv run pytest tests/sync/test_git.py
56+
57+
# Run a specific test
58+
uv run pytest tests/sync/test_git.py::test_remotes
59+
60+
# Run tests with test watcher
61+
make start
62+
# or
63+
uv run ptw .
64+
```
65+
66+
### Linting and Type Checking
67+
68+
```bash
69+
# Run ruff for linting
70+
make ruff
71+
# or directly
72+
uv run ruff check .
73+
74+
# Format code with ruff
75+
make ruff_format
76+
# or directly
77+
uv run ruff format .
78+
79+
# Run ruff linting with auto-fixes
80+
uv run ruff check . --fix --show-fixes
81+
82+
# Run mypy for type checking
83+
make mypy
84+
# or directly
85+
uv run mypy src tests
86+
87+
# Watch mode for linting (using entr)
88+
make watch_ruff
89+
make watch_mypy
90+
```
91+
92+
### Development Workflow
93+
94+
Follow this workflow for code changes:
95+
96+
1. **Format First**: `uv run ruff format .`
97+
2. **Run Tests**: `uv run pytest`
98+
3. **Run Linting**: `uv run ruff check . --fix --show-fixes`
99+
4. **Check Types**: `uv run mypy`
100+
5. **Verify Tests Again**: `uv run pytest`
101+
102+
### Documentation
103+
104+
```bash
105+
# Build documentation
106+
make build_docs
107+
108+
# Start documentation server with auto-reload
109+
make start_docs
110+
111+
# Update documentation CSS/JS
112+
make design_docs
113+
```
114+
115+
## Code Architecture
116+
117+
libvcs is organized into three main modules:
118+
119+
1. **URL Detection and Parsing** (`libvcs.url`)
120+
- Base URL classes in `url/base.py`
121+
- VCS-specific implementations in `url/git.py`, `url/hg.py`, and `url/svn.py`
122+
- URL registry in `url/registry.py`
123+
- Constants in `url/constants.py`
124+
125+
2. **Command Abstraction** (`libvcs.cmd`)
126+
- Command classes for git, hg, and svn in `cmd/git.py`, `cmd/hg.py`, and `cmd/svn.py`
127+
- Built on top of Python's subprocess module (via `_internal/subprocess.py`)
128+
129+
3. **Repository Synchronization** (`libvcs.sync`)
130+
- Base sync classes in `sync/base.py`
131+
- VCS-specific sync implementations in `sync/git.py`, `sync/hg.py`, and `sync/svn.py`
132+
133+
4. **Internal Utilities** (`libvcs._internal`)
134+
- Subprocess wrappers in `_internal/subprocess.py`
135+
- Data structures in `_internal/dataclasses.py` and `_internal/query_list.py`
136+
- Runtime helpers in `_internal/run.py` and `_internal/shortcuts.py`
137+
138+
5. **pytest Plugin** (`libvcs.pytest_plugin`)
139+
- Provides fixtures for creating temporary repositories for testing
140+
141+
## Testing Strategy
142+
143+
libvcs uses pytest for testing with many custom fixtures. The pytest plugin (`pytest_plugin.py`) defines fixtures for creating temporary repositories for testing. These include:
144+
145+
- `create_git_remote_repo`: Creates a git repository for testing
146+
- `create_hg_remote_repo`: Creates a Mercurial repository for testing
147+
- `create_svn_remote_repo`: Creates a Subversion repository for testing
148+
- `git_repo`, `svn_repo`, `hg_repo`: Pre-made repository instances
149+
- `set_home`, `gitconfig`, `hgconfig`, `git_commit_envvars`: Environment fixtures
150+
151+
These fixtures handle setup and teardown automatically, creating isolated test environments.
152+
153+
For running tests with actual VCS commands, tests will be skipped if the corresponding VCS binary is not installed.
154+
155+
### Example Fixture Usage
156+
157+
```python
158+
def test_repo_sync(git_repo):
159+
# git_repo is already a GitSync instance with a clean repository
160+
# Use it directly in your tests
161+
assert git_repo.get_revision() == "initial"
162+
```
163+
164+
### Parameterized Tests
165+
166+
Use `typing.NamedTuple` for parameterized tests:
167+
168+
```python
169+
class RepoFixture(t.NamedTuple):
170+
test_id: str # For test naming
171+
repo_args: dict[str, t.Any]
172+
expected_result: str
173+
174+
@pytest.mark.parametrize(
175+
list(RepoFixture._fields),
176+
REPO_FIXTURES,
177+
ids=[test.test_id for test in REPO_FIXTURES],
178+
)
179+
def test_sync(
180+
# Parameters and fixtures...
181+
):
182+
# Test implementation
183+
```
184+
185+
## Coding Standards
186+
187+
### Imports
188+
189+
- Use namespace imports: `import enum` instead of `from enum import Enum`
190+
- For typing, use `import typing as t` and access via namespace: `t.NamedTuple`, etc.
191+
- Use `from __future__ import annotations` at the top of all Python files
192+
193+
### Docstrings
194+
195+
Follow NumPy docstring style for all functions and methods:
196+
197+
```python
198+
"""Short description of the function or class.
199+
200+
Detailed description using reStructuredText format.
201+
202+
Parameters
203+
----------
204+
param1 : type
205+
Description of param1
206+
param2 : type
207+
Description of param2
208+
209+
Returns
210+
-------
211+
type
212+
Description of return value
213+
"""
214+
```
215+
216+
### Git Commit Standards
217+
218+
Format commit messages as:
219+
```
220+
Component/File(commit-type[Subcomponent/method]): Concise description
221+
222+
why: Explanation of necessity or impact.
223+
what:
224+
- Specific technical changes made
225+
- Focused on a single topic
226+
227+
refs: #issue-number, breaking changes, or relevant links
228+
```
229+
230+
Common commit types:
231+
- **feat**: New features or enhancements
232+
- **fix**: Bug fixes
233+
- **refactor**: Code restructuring without functional change
234+
- **docs**: Documentation updates
235+
- **chore**: Maintenance (dependencies, tooling, config)
236+
- **test**: Test-related updates
237+
- **style**: Code style and formatting
238+
239+
Example:
240+
```
241+
url/git(feat[GitURL]): Add support for custom SSH port syntax
242+
243+
why: Enable parsing of Git URLs with custom SSH ports
244+
what:
245+
- Add port capture to SCP_REGEX pattern
246+
- Update GitURL.to_url() to include port if specified
247+
- Add tests for the new functionality
248+
249+
refs: #123
250+
```
251+
252+
## Debugging Tips
253+
254+
When stuck in debugging loops:
255+
256+
1. **Pause and acknowledge the loop**
257+
2. **Minimize to MVP**: Remove all debugging cruft and experimental code
258+
3. **Document the issue** comprehensively for a fresh approach
259+
4. **Format for portability** (using quadruple backticks)

0 commit comments

Comments
 (0)