Skip to content

Commit

Permalink
PYTHON-4485 Use Hatch as Build Backend (#827)
Browse files Browse the repository at this point in the history
* PYTHON-4485 Use Hatch as Build Backend

* lint

* fix codeql

* remove setup.py

* rename test reqs

* use fetch depth

* fix benchmark

* fix codeql
  • Loading branch information
blink1073 authored Jun 13, 2024
1 parent 146e1f5 commit dadf22c
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .evergreen/benchmark-python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cd bindings/python/

/opt/mongodbtoolchain/v4/bin/python3 -m venv venv
. ./venv/bin/activate
python -m pip install --prefer-binary -r test-requirements.txt
python -m pip install --prefer-binary -r requirements-test.txt
python -m pip install -e .

export OUTPUT_FILE=results.json
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
jobs:
analyze-python:
name: Analyze Python
runs-on: "ubuntu-latest"
runs-on: "macos-latest"
timeout-minutes: 360
permissions:
# required for all workflows
Expand All @@ -24,6 +24,8 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: 3.x
Expand All @@ -43,6 +45,8 @@ jobs:
- name: Install package
run: |
cd bindings/python
export LIBMONGOCRYPT_VERSION=$(cat ./libmongocrypt-version.txt)
git fetch origin $LIBMONGOCRYPT_VERSION
bash release.sh
pip install dist/*.whl
Expand Down
16 changes: 0 additions & 16 deletions bindings/python/MANIFEST.in

This file was deleted.

14 changes: 4 additions & 10 deletions bindings/python/build-manylinux-wheel.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
#!/bin/bash -ex
cd /python

/opt/python/cp37-cp37m/bin/python -m build --wheel

# Audit wheels and write manylinux tag
for whl in dist/*none-any.whl; do
# Skip already built manylinux wheels.
if [[ "$whl" != *"manylinux"* ]]; then
auditwheel repair $whl -w dist
rm $whl
fi
done
mkdir /tmp/wheelhouse
/opt/python/cp38-cp38/bin/python -m build --wheel --outdir /tmp/wheelhouse
# Audit wheels and repair manylinux tags
auditwheel repair /tmp/wheelhouse/*.whl -w dist
36 changes: 36 additions & 0 deletions bindings/python/hatch_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""A custom hatch build hook for pymongo."""
from __future__ import annotations

import os
import sys
from pathlib import Path

from hatchling.builders.hooks.plugin.interface import BuildHookInterface


class CustomHook(BuildHookInterface):
"""The pymongocrypt build hook."""

def initialize(self, version, build_data):
"""Initialize the hook."""
if self.target_name == "sdist":
return

# Ensure wheel is marked as binary.
# On linux, we use auditwheel to set the name.
if sys.platform == "darwin":
os.environ["MACOSX_DEPLOYMENT_TARGET"] = "11.0"
build_data["tag"] = "py3-none-macosx_11_0_universal2"
patt = ".dylib"
elif os.name == "nt":
build_data["tag"] = "py3-none-win_amd64"
patt = ".dll"
else:
patt = ".so"

here = Path(__file__).parent.resolve()
dpath = here / "pymongocrypt"
for fpath in dpath.glob(f"*{patt}"):
relpath = os.path.relpath(fpath, here)
build_data["artifacts"].append(relpath)
build_data["force_include"][relpath] = relpath
2 changes: 1 addition & 1 deletion bindings/python/pymongocrypt/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "2.0.0.dev0"
__version__ = "1.10.0.dev0"

_MIN_LIBMONGOCRYPT_VERSION = "1.8.0"
19 changes: 11 additions & 8 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["setuptools>=63.0", "wheel"]
build-backend = "setuptools.build_meta"
requires = ["hatchling>1.24","hatch-requirements-txt>=0.4.1"]
build-backend = "hatchling.build"

[project]
name = "pymongocrypt"
Expand Down Expand Up @@ -42,14 +42,17 @@ classifiers = [
[project.urls]
Homepage = "https://github.com/mongodb/libmongocrypt/tree/master/bindings/python"

[tool.setuptools.dynamic]
version = {attr = "pymongocrypt.version.__version__"}
[tool.hatch.version]
path = "pymongocrypt/version.py"

[tool.setuptools.packages.find]
include = ["pymongocrypt", "pymongocrypt.asynchronous", "pymongocrypt.synchronous"]
# Used to call hatch_build.py
[tool.hatch.build.hooks.custom]

[tool.setuptools.package-data]
pymongocrypt=['*.dll', '*.so', '*.dylib']
[tool.hatch.metadata.hooks.requirements_txt]
files = ["requirements.txt"]

[tool.hatch.metadata.hooks.requirements_txt.optional-dependencies]
test = ["requirements-test.txt"]

[tool.ruff.lint]
select = [
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ if [ $(command -v docker) ]; then
if [ "Linux" = "$(uname -s)" ]; then
$PYTHON -m venv .venv
. .venv/bin/activate
test_dist dist/*.whl
test_dist dist/*linux*.whl
fi

# Build the manylinux_2_28 aarch64 wheel.
Expand Down
File renamed without changes.
46 changes: 0 additions & 46 deletions bindings/python/setup.py

This file was deleted.

0 comments on commit dadf22c

Please sign in to comment.