Skip to content

Commit d9a4f68

Browse files
committed
chore: add CLAUDE.md
1 parent 32746ac commit d9a4f68

1 file changed

Lines changed: 133 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
asynctnt is a high-performance async Python connector for Tarantool database, built with Python/Cython/C for asyncio. Requires Python 3.9+ and supports Tarantool 1.10+.
8+
9+
## Virtual Environments
10+
11+
This project uses `uv` for package management. Use `uv pip` instead of plain `pip`.
12+
13+
### Naming Convention
14+
15+
Virtual environments follow the pattern `.venv<PYTHON_VERSION>`:
16+
- `.venv314` - Python 3.14 (main development environment, latest stable)
17+
- `.venv313` - Python 3.13
18+
- `.venv314t` - Python 3.14 free-threaded (no-GIL)
19+
- `.venv311pypy` - PyPy 3.11
20+
21+
### Creating a Virtual Environment
22+
23+
```bash
24+
# List available Python versions
25+
uv python list
26+
27+
# Create a new venv
28+
uv venv --python=3.14 .venv314
29+
uv venv --python=3.13 .venv313
30+
uv venv --python=3.14t .venv314t
31+
```
32+
33+
### Using a Virtual Environment
34+
35+
Either activate the environment first:
36+
```bash
37+
source .venv314/bin/activate
38+
make quicktest
39+
```
40+
41+
Or use binaries directly:
42+
```bash
43+
.venv314/bin/python -c "import asynctnt"
44+
.venv314/bin/pytest tests/test_op_select.py
45+
```
46+
47+
## Build & Development Commands
48+
49+
```bash
50+
# Install for local development
51+
make local
52+
53+
# Install with test and docs dependencies
54+
make build
55+
56+
# Install with Cython debug symbols
57+
make debug
58+
59+
# Run tests (requires running Tarantool instance)
60+
make quicktest # Single test run
61+
make test # Full suite: PYTHONASYNCIODEBUG + normal + uvloop
62+
63+
# Run a single test file or test
64+
uv run --active pytest tests/test_op_select.py
65+
uv run --active pytest tests/test_op_select.py::SelectTestCase::test_select_all
66+
67+
# Code quality
68+
make lint # Check formatting (ruff format --check) + linting (ruff check)
69+
make style # Auto-format with ruff
70+
71+
# Coverage
72+
make coverage
73+
74+
# Build documentation
75+
make docs
76+
```
77+
78+
## Testing
79+
80+
Tests require a Tarantool instance. The test framework manages instance lifecycle automatically:
81+
- Set `TARANTOOL_DOCKER_VERSION` to run Tarantool in Docker (e.g., `2.11`)
82+
- Set `USE_UVLOOP=1` to run tests with uvloop
83+
- Tests use `unittest.TestCase` with a custom metaclass that wraps async test methods
84+
85+
Test classes inherit from `TarantoolTestCase` which provides:
86+
- Automatic Tarantool instance start/stop
87+
- `self.conn` - connected asynctnt.Connection
88+
- `self.tnt` - Tarantool instance handle
89+
- `ensure_version(min=, max=)` decorator for version-specific tests
90+
91+
## Architecture
92+
93+
### Code Layers
94+
95+
1. **Public API** (`asynctnt/connection.py`, `asynctnt/api.py`)
96+
- `Connection` class: entry point, manages lifecycle, auto-reconnect
97+
- `Api` base class: defines all database operations (select, insert, call, eval, execute, etc.)
98+
99+
2. **Protocol Layer** (`asynctnt/iproto/` - Cython)
100+
- `protocol.pyx`: Core IProto binary protocol implementation
101+
- `db.pyx`: Request/response handling
102+
- `response.pyx`: Response parsing, TarantoolTuple creation
103+
- `schema.pyx`: Schema fetching and caching
104+
- `requests/`: Individual request type builders (select.pyx, insert.pyx, etc.)
105+
- `ext/`: Type extension handlers (decimal, uuid, datetime, interval, error)
106+
107+
3. **C Layer** (`asynctnt/iproto/tupleobj/`, `third_party/msgpuck/`)
108+
- Custom TarantoolTuple object (C extension)
109+
- msgpuck: MessagePack encoding/decoding library
110+
111+
### Key Classes
112+
113+
- `Connection`: Main connection class with auto-reconnect, schema management
114+
- `TarantoolTuple`: Hybrid tuple/dict result object (access by index or field name)
115+
- `PreparedStatement`: SQL prepared statement wrapper
116+
- `Stream`: MVCC transaction stream
117+
118+
### Exception Hierarchy
119+
120+
```
121+
TarantoolError
122+
├── TarantoolSchemaError
123+
├── TarantoolDatabaseError (has code, message)
124+
└── TarantoolNetworkError
125+
└── TarantoolNotConnectedError
126+
```
127+
128+
## Key Files
129+
130+
- `setup.py`: Cython compilation config, extension module build
131+
- `asynctnt/__init__.py`: Public API exports
132+
- `asynctnt/instance.py`: Tarantool instance management for tests
133+
- `tests/_testbase.py`: Test infrastructure, TarantoolTestCase base class

0 commit comments

Comments
 (0)