Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Official Python driver for MongoDB.

## Tech Stack
- **Build/env:** `hatch` — use `hatch run test:test` and `hatch run test:test-async`, not `pytest` directly
- **Task runner:** `just` (Justfile at repo root)
- **Linter/formatter:** `ruff` via pre-commit
- **Type checker:** `mypy` (strict)
Expand All @@ -13,37 +12,31 @@ Official Python driver for MongoDB.
> **Never** run `pip install bson`. PyMongo ships its own `bson`; the PyPI `bson` package silently breaks things.

## Project Structure
- `pymongo/synchronous/` — sync driver (MongoClient, Collection, Database, etc.) generated from `pymongo/asynchronous/` using unasync
- `pymongo/asynchronous/` — async API, mirrors `pymongo/synchronous/`
- `pymongo/asynchronous/` — async driver (AsyncMongoClient, AsyncCollection, etc.)
- `pymongo/synchronous/` — sync driver (MongoClient, Collection, etc.) generated from `pymongo/asynchronous/` using `just synchro`
- `bson/` — BSON implementation
- `gridfs/` — GridFS API
- `test/` — sync test suite
- `test/asynchronous/` — async test suite, mirrors `test/`
- `test/asynchronous/` — async test suite
- `test/` — sync test suite (generated from `test/asynchronous/` by `just synchro`) and shared test suite
- `test/unified_format/` — cross-driver spec tests (Unified Test Format)
- `tools/convert_test_to_async.py` — generates async test stubs from sync tests

Do not edit files in `pymongo/synchronous/` or mirrored files in `test/` directly: they are generated by `just synchro` from `pymongo/asynchronous/` and `test/asynchronous/`.
A file in `test/` is mirrored if a file of the same name exists in `test/asynchronous/`.

## Commands
```bash
just install # set up venv + pre-commit hook
just typing-mypy # type check
just run lint-manual # ruff linter

hatch run test:test # run sync tests
hatch run test:test-async # run async tests

MONGODB_VERSION=8.0 just run-server # start a local MongoDB server
just install # set up venv + pre-commit hooks
just typing # type check
just lint-manual # pre-commit linting and synchro
just synchro # generate synchronous driver and mirrored tests
just test # run all tests
just test test/asynchronous # run async tests
Comment thread
NoahStapp marked this conversation as resolved.
Resolved
MONGODB_VERSION=8.0 just run-server # start a local MongoDB 8.0 server
```

## Testing
Tests require a live MongoDB server (`just run-server` above).

Never modify pymongo/synchronous code first; update the async counterpart and run our `tools/synchro.py` script:
1. Make changes in `pymongo/asynchronous` or top-level `pymongo/` files and `test/`.
2. Run `tools/convert_test_to_async.py` on the sync test file to generate a starting-point async version.
3. Manually complete the async version in `test/asynchronous/`.

Do not edit files in `pymongo/synchronous/` or mirrored files in `test/` directly — they are auto-generated by `tools/synchro.py` from `pymongo/asynchronous/` and `test/asynchronous/`. Only edit them if the change includes a `_IS_SYNC` statement.

Async functions must not call blocking I/O.

New features need integration tests. Bug fixes need regression tests.
Expand Down
5 changes: 5 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ lint *args="": && resync
lint-manual *args="": && resync
uvx pre-commit run --all-files --hook-stage manual {{args}}

# Run synchro
[group('lint')]
synchro: && resync
uvx pre-commit run --all-files synchro

# Run pytest (e.g. just test test/test_uri_parser.py)
[group('test')]
test *args="-v --durations=5 --maxfail=10": && resync
Expand Down
Loading