From b0e753276285f8ea379cb16bdf9c15974a92ac17 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Fri, 8 Mar 2024 12:42:21 +0000 Subject: [PATCH 1/3] use custom PEP517 build backend to require cmake conditionally Fixes https://github.com/rougier/freetype-py/issues/183 `pip install --no-binary freetype-py freetype-py` will no longer attempt to download and install cmake in pip's temporary build environment, unless FREETYPEPY_BUNDLE_FT environment variable was set in order to compile the bundled FreeType shared library. This makes the installation of a pure Python freetype-py (using system-wide FreeType library) quicker and doesn't require one to force --no-build-isolation just to prevent cmake from being installed unnecessarily. --- _custom_build/backend.py | 25 +++++++++++++++++++++++++ pyproject.toml | 6 ++++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 _custom_build/backend.py diff --git a/_custom_build/backend.py b/_custom_build/backend.py new file mode 100644 index 0000000..b95a223 --- /dev/null +++ b/_custom_build/backend.py @@ -0,0 +1,25 @@ +"""Custom PEP 517 build backend to provide different dependencies for wheel builds. + +We need some extra dependencies when we build a wheel that bundles the FreeType +shared library (triggered when FREETYPEPY_BUNDLE_FT environment variable is set), +as opposed to a pure Python wheel (py3-none-any.whl). + +For more info see: + +https://setuptools.pypa.io/en/latest/build_meta.html#dynamic-build-dependencies-and-other-build-meta-tweaks + +https://github.com/rougier/freetype-py/issues/183 +""" + +import os +from setuptools import build_meta as _orig +from setuptools.build_meta import * + + +def get_requires_for_build_wheel(config_settings=None): + build_wheel_deps = _orig.get_requires_for_build_wheel(config_settings) + + if os.environ.get("FREETYPEPY_BUNDLE_FT"): + build_wheel_deps += ["certifi", "cmake"] + + return build_wheel_deps diff --git a/pyproject.toml b/pyproject.toml index 61ffc85..4c6a602 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,5 @@ [build-system] -requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4", "certifi", "cmake"] -build-backend = "setuptools.build_meta" +requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"] +# https://setuptools.pypa.io/en/latest/build_meta.html#dynamic-build-dependencies-and-other-build-meta-tweaks +build-backend = "backend" +backend-path = ["_custom_build"] From 0b194f6589180febe6c2c4e42674b44009b13bae Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Fri, 8 Mar 2024 12:49:33 +0000 Subject: [PATCH 2/3] [ci] Update cibuildwheel to latest --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a63404a..7f39cba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,7 +56,7 @@ jobs: platforms: all - name: Build wheels - uses: pypa/cibuildwheel@v2.12.3 + uses: pypa/cibuildwheel@v2.16.5 env: CIBW_BUILD: ${{ matrix.cibw_build }} CIBW_ARCHS: "auto64" From 3673068012cba8e3e14ee1a6454d97330a451480 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Fri, 8 Mar 2024 12:58:15 +0000 Subject: [PATCH 3/3] backend.py: add hook for get_requires_for_build_editable as well --- _custom_build/backend.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/_custom_build/backend.py b/_custom_build/backend.py index b95a223..0b0ab28 100644 --- a/_custom_build/backend.py +++ b/_custom_build/backend.py @@ -23,3 +23,8 @@ def get_requires_for_build_wheel(config_settings=None): build_wheel_deps += ["certifi", "cmake"] return build_wheel_deps + + +def get_requires_for_build_editable(config_settings=None): + # ensure pip install -e . uses same build deps as regular pip install/wheel + return get_requires_for_build_wheel(config_settings)