-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PYTHON-4953 Add contributing guide and improve helper scripts
- Loading branch information
Showing
12 changed files
with
174 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Contributing to PyMongoCrypt | ||
|
||
## Asyncio considerations | ||
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. | ||
|
||
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. | ||
|
||
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`. | ||
|
||
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. | ||
|
||
## Updating the libmongocrypt bindings | ||
|
||
To update the libmongocrypt bindings in `pymongocrypt/binding.py`, run the following script: | ||
|
||
```bash | ||
python scripts/update_binding.py | ||
``` | ||
|
||
## Update the bundled version of libmongocrypt | ||
|
||
To update the bundled version of libmongocrypt, run the following script: | ||
|
||
```bash | ||
bash script/update-version.sh <new-version> | ||
``` | ||
|
||
This will set the version in `scripts/libmongocrypt-version.sh` and update `sbom.json` to reflect | ||
the new vendored version of `libmongocrypt`. | ||
|
||
## Building wheels | ||
|
||
To build wheels, run `scripts/release.sh`. It will build the appropriate wheel for the current system | ||
on Windows and MacOS. If docker is available on Linux or MacOS, it will build the manylinux wheels. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
SCRIPT_DIR=$(dirname ${BASH_SOURCE:-$0}) | ||
|
||
python $SCRIPT_DIR/synchro.py "$@" | ||
python -m ruff check $SCRIPT_DIR/../pymongocrypt/synchronous --fix --silent |
19 changes: 16 additions & 3 deletions
19
bindings/python/update-sbom.sh → bindings/python/scripts/update-version.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
#!/bin/bash | ||
|
||
set -eux | ||
set -eu | ||
|
||
LIBMONGOCRYPT_VERSION=$(cat ./libmongocrypt-version.txt) | ||
SCRIPT_DIR=$(dirname ${BASH_SOURCE:-$0}) | ||
|
||
if [ -z "${1:-}" ]; then | ||
echo "Provide the new version of libmongocrypt!" | ||
exit 1 | ||
fi | ||
|
||
LIBMONGOCRYPT_VERSION=$1 | ||
|
||
echo $LIBMONGOCRYPT_VERSION > libmongocrypt-version.txt | ||
|
||
pushd $SCRIPT_DIR/.. | ||
if [ $(command -v podman) ]; then | ||
DOCKER=podman | ||
else | ||
DOCKER=docker | ||
fi | ||
|
||
echo "pkg:github/mongodb/libmongocrypt@$LIBMONGOCRYPT_VERSION" > purls.txt | ||
$DOCKER run --platform="linux/amd64" -it --rm -v $(pwd):$(pwd) artifactory.corp.mongodb.com/release-tools-container-registry-public-local/silkbomb:1.0 update --purls=$(pwd)/purls.txt -o $(pwd)/sbom.json | ||
$DOCKER run --platform="linux/amd64" -it --rm -v $(pwd):$(pwd) artifactory.corp.mongodb.com/release-tools-container-registry-public-local/silkbomb:2.0 update --purls=$(pwd)/purls.txt -o $(pwd)/sbom.json | ||
rm purls.txt | ||
|
||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright 2019-present MongoDB, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Update pymongocrypt/bindings.py using mongocrypt.h. | ||
""" | ||
|
||
import re | ||
from pathlib import Path | ||
|
||
DROP_RE = re.compile(r"^\s*(#|MONGOCRYPT_EXPORT)") | ||
HERE = Path(__file__).absolute().parent | ||
|
||
|
||
# itertools.pairwise backport for Python 3.9 support. | ||
def pairwise(iterable): | ||
# pairwise('ABCDEFG') → AB BC CD DE EF FG | ||
|
||
iterator = iter(iterable) | ||
a = next(iterator, None) | ||
|
||
for b in iterator: | ||
yield a, b | ||
a = b | ||
|
||
|
||
def strip_file(content): | ||
fold = content.replace("\\\n", " ") | ||
all_lines = [*fold.split("\n"), ""] | ||
keep_lines = (line for line in all_lines if not DROP_RE.match(line)) | ||
fin = "" | ||
for line, peek in pairwise(keep_lines): | ||
if peek == "" and line == "": | ||
# Drop adjacent empty lines | ||
continue | ||
yield line | ||
fin = peek | ||
yield fin | ||
|
||
|
||
def update_bindings(): | ||
header_file = HERE.parent.parent.parent / "src/mongocrypt.h" | ||
with header_file.open(encoding="utf-8") as fp: | ||
header_lines = strip_file(fp.read()) | ||
|
||
target = HERE.parent / "pymongocrypt/binding.py" | ||
source_lines = target.read_text().splitlines() | ||
new_lines = [] | ||
skip = False | ||
for line in source_lines: | ||
if not skip: | ||
new_lines.append(line) | ||
if line.strip() == "# Start embedding from update_binding.py": | ||
skip = True | ||
new_lines.append("ffi.cdef(") | ||
new_lines.append('"""') | ||
new_lines.extend(header_lines) | ||
if line.strip() == "# End embedding from update_binding.py": | ||
new_lines.append('"""') | ||
new_lines.append(")") | ||
new_lines.append(line) | ||
skip = False | ||
|
||
|
||
if __name__ == "__main__": | ||
update_bindings() |
This file was deleted.
Oops, something went wrong.