Skip to content

Added detailed inline documentation for custom setuptools build hook #1094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 4.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions _build_backend/backend.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Import the default setuptools PEP 517 build backend under a custom alias
# This allows us to extend or override its functionality where needed
from setuptools import build_meta as _orig

# Re-use the default implementations for standard PEP 517 hook methods
prepare_metadata_for_build_wheel = _orig.prepare_metadata_for_build_wheel
build_wheel = _orig.build_wheel
build_sdist = _orig.build_sdist
get_requires_for_build_sdist = _orig.get_requires_for_build_sdist

# Override the `get_requires_for_build_wheel` function to add dynamic dependency logic
def get_requires_for_build_wheel(config_settings=None):
from packaging import version
from skbuild.exceptions import SKBuildError
Expand All @@ -13,11 +17,13 @@ def get_requires_for_build_wheel(config_settings=None):
# check if system cmake can be used if present
# if not, append cmake PyPI distribution to required packages
# scikit-build>=0.18 itself requires cmake 3.5+
# Define the minimum required version of CMake (needed by scikit-build>=0.18)
min_version = "3.5"
try:
if version.parse(get_cmake_version().split("-")[0]) < version.parse(min_version):
packages.append(f'cmake>={min_version}')
except SKBuildError:
packages.append(f'cmake>={min_version}')

# Return the final list of required packages for building the wheel
return packages