Skip to content

Commit caf7176

Browse files
authored
PYTHON-4953 Add contributing guide and improve helper scripts (#980)
1 parent 2d37ee8 commit caf7176

File tree

16 files changed

+182
-74
lines changed

16 files changed

+182
-74
lines changed

.evergreen/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ functions:
306306
script: |
307307
set -ex
308308
cd ./libmongocrypt/bindings/python
309-
PYTHON=${PYTHON} ./release.sh
309+
PYTHON=${PYTHON} ./scripts/release.sh
310310
311311
"upload python release":
312312
- command: archive.targz_pack

.github/workflows/codeql-python.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ jobs:
5555
- name: Install package
5656
run: |
5757
cd bindings/python
58-
export LIBMONGOCRYPT_VERSION=$(cat ./libmongocrypt-version.txt)
58+
export LIBMONGOCRYPT_VERSION=$(cat ./scripts/libmongocrypt-version.txt)
5959
git fetch origin $LIBMONGOCRYPT_VERSION
60-
bash release.sh
60+
bash ./scripts/release.sh
6161
pip install dist/*.whl
6262
6363
- name: Perform CodeQL Analysis

.github/workflows/dist-python.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ jobs:
5454

5555
- name: Build and test dist files
5656
run: |
57-
export LIBMONGOCRYPT_VERSION=$(cat ./libmongocrypt-version.txt)
57+
export LIBMONGOCRYPT_VERSION=$(cat ./scripts/libmongocrypt-version.txt)
5858
git fetch origin $LIBMONGOCRYPT_VERSION
59-
bash ./release.sh
59+
bash ./scripts/release.sh
6060
6161
- uses: actions/upload-artifact@v4
6262
with:

.github/workflows/test-python.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
if: github.repository_owner == 'mongodb'
4141
runs-on: ${{ matrix.os }}
4242
strategy:
43+
fail-fast: false
4344
matrix:
4445
os: [ubuntu-latest, windows-latest, macos-latest]
4546
python-version: ["3.8", "3.13"]
@@ -59,6 +60,6 @@ jobs:
5960
if [ "${{ matrix.python-version }}" == "3.13" ]; then
6061
export PIP_PRE=1
6162
fi
62-
export LIBMONGOCRYPT_VERSION=$(cat ./libmongocrypt-version.txt)
63+
export LIBMONGOCRYPT_VERSION=$(cat ./scripts/libmongocrypt-version.txt)
6364
git fetch origin $LIBMONGOCRYPT_VERSION
64-
bash ./release.sh
65+
bash ./scripts/release.sh

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ repos:
5353
language: system
5454
types: [shell]
5555

56+
- repo: local
57+
hooks:
58+
- id: synchro
59+
name: synchro
60+
entry: bash ./bindings/python/scripts/synchro.sh
61+
language: python
62+
require_serial: true
63+
fail_fast: true
64+
additional_dependencies:
65+
- ruff==0.1.3
66+
- unasync
67+
5668
- repo: https://github.com/astral-sh/ruff-pre-commit
5769
# Ruff version.
5870
rev: v0.1.3

bindings/python/.evergreen/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ for PYTHON_BINARY in "${PYTHONS[@]}"; do
8686
done
8787

8888
# Verify the sbom file
89-
LIBMONGOCRYPT_VERSION=$(cat ./libmongocrypt-version.txt)
89+
LIBMONGOCRYPT_VERSION=$(cat ./scripts/libmongocrypt-version.txt)
9090
EXPECTED="pkg:github/mongodb/libmongocrypt@$LIBMONGOCRYPT_VERSION"
9191
if grep -q $EXPECTED sbom.json; then
9292
echo "SBOM is up to date!"

bindings/python/CONTRIBUTING.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Contributing to PyMongoCrypt
2+
3+
## Asyncio considerations
4+
PyMongoCrypt adds asyncio capability by modifying the source files in */asynchronous to */synchronous using [unasync](https://github.com/python-trio/unasync/) and some custom transforms.
5+
6+
Where possible, edit the code in `*/asynchronous/*.py` and not the synchronous files. You can run `pre-commit run --all-files synchro` before running tests if you are testing synchronous code.
7+
8+
To prevent the synchro hook from accidentally overwriting code, it first checks to see whether a sync version of a file is changing and not its async counterpart, and will fail. In the unlikely scenario that you want to override this behavior, first export `OVERRIDE_SYNCHRO_CHECK=1`.
9+
10+
Sometimes, the synchro hook will fail and introduce changes many previously unmodified files. This is due to static Python errors, such as missing imports, incorrect syntax, or other fatal typos. To resolve these issues, run `pre-commit run --all-files --hook-stage manual ruff` and fix all reported errors before running the synchro hook again.
11+
12+
## Updating the libmongocrypt bindings
13+
14+
To update the libmongocrypt bindings in `pymongocrypt/binding.py`, run the following script:
15+
16+
```bash
17+
python scripts/update_binding.py
18+
```
19+
20+
## Update the bundled version of libmongocrypt
21+
22+
To update the bundled version of libmongocrypt, run the following script:
23+
24+
```bash
25+
bash script/update-version.sh <new-version>
26+
```
27+
28+
This will set the version in `scripts/libmongocrypt-version.sh` and update `sbom.json` to reflect
29+
the new vendored version of `libmongocrypt`.
30+
31+
## Building wheels
32+
33+
To build wheels, run `scripts/release.sh`. It will build the appropriate wheel for the current system
34+
on Windows and MacOS. If docker is available on Linux or MacOS, it will build the manylinux wheels.

bindings/python/pymongocrypt/binding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _parse_version(version):
2929

3030
ffi = cffi.FFI()
3131

32-
# Generated with strip_header.py
32+
# Start embedding from update_binding.py
3333
ffi.cdef(
3434
"""/*
3535
* Copyright 2019-present MongoDB, Inc.
@@ -1468,6 +1468,7 @@ def _parse_version(version):
14681468
// DEPRECATED: Support "rangePreview" has been removed in favor of "range".
14691469
"""
14701470
)
1471+
# End embedding from update_binding.py
14711472

14721473

14731474
def _to_string(cdata):

0 commit comments

Comments
 (0)