Skip to content

Commit

Permalink
Merge pull request #184 from rougier/pep517-custom-backend
Browse files Browse the repository at this point in the history
use custom PEP517 build backend to require cmake conditionally
  • Loading branch information
anthrotype authored Mar 8, 2024
2 parents 8f9fb51 + 3673068 commit 4edac0d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 30 additions & 0 deletions _custom_build/backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""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


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)
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 4edac0d

Please sign in to comment.