Skip to content

Commit d74c0d6

Browse files
NoahStappJibola
authored andcommitted
PYTHON-5817 - Add "Project Structure and Asyncio Considerations" section to CONTRIBUTING.md (mongodb#2788)
Co-authored-by: Jib <Jibzade@gmail.com>
1 parent 5d94001 commit d74c0d6

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

CONTRIBUTING.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,20 @@ python3 ./.evergreen/scripts/resync-all-specs.py
505505

506506
Follow the [Python Driver Release Process Wiki](https://wiki.corp.mongodb.com/display/DRIVERS/Python+Driver+Release+Process).
507507

508-
## Asyncio considerations
508+
## Project Structure and Asyncio Considerations
509509

510-
PyMongo adds asyncio capability by modifying the source files in `*/asynchronous` to `*/synchronous` using
511-
[unasync](https://github.com/python-trio/unasync/) and some custom transforms.
510+
This section describes the layout of the `pymongo/` package.
512511

513-
Where possible, edit the code in `*/asynchronous/*.py` and not the synchronous files.
514-
You can run `pre-commit run --all-files synchro` before running tests if you are testing synchronous code.
512+
Within `pymongo/`, the code is further divided into the `pymongo/asynchronous` and `pymongo/synchronous` subdirectories.
513+
Files in `pymongo/synchronous` are generated from `pymongo/asynchronous` using the `synchro` pre-commit hook, which uses [unasync](https://github.com/python-trio/unasync/) and some custom transforms.
514+
515+
As a result, **all modifications** within `pymongo` must be made in either the top-level `pymongo` directory when they have to exhibit differing behavior between sync and async contexts or the `pymongo/asynchronous` directory, not `pymongo/synchronous`.
516+
Any changes made directly to files in the `pymongo/synchronous` directory will be overwritten by the `synchro` hook when it is run, which happens automatically on commit.
517+
518+
Some top-level files (e.g. `pymongo/collection.py`) are re-export files for existing import compatibility and should not be modified directly.
519+
The other top-level files (e.g. `pymongo/network_layer.py`, `pymongo/pool_shared.py`) contain either shared code used in both the asynchronous and synchronous APIs, or code that is very different between the two APIs and therefore cannot be generated from the async version using `synchro`.
520+
521+
Run `pre-commit run --all-files synchro` before running tests to generate the latest version of the synchronous code.
515522

516523
To prevent the `synchro` hook from accidentally overwriting code, it first checks to see whether a sync version
517524
of a file is changing and not its async counterpart, and will fail.

0 commit comments

Comments
 (0)