From 07ed8ea194a324005b6acc8ef3e23dec9c08e43d Mon Sep 17 00:00:00 2001 From: Yichen Yan Date: Fri, 15 Aug 2025 12:04:17 +0800 Subject: [PATCH 1/2] Add exclude-exts options --- docs/configuration/index.md | 14 ++++++++++++++ src/scikit_build_core/build/_wheelfile.py | 4 ++-- src/scikit_build_core/build/wheel.py | 2 +- src/scikit_build_core/settings/skbuild_model.py | 13 +++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/docs/configuration/index.md b/docs/configuration/index.md index 14c899e76..f334fef87 100644 --- a/docs/configuration/index.md +++ b/docs/configuration/index.md @@ -329,6 +329,20 @@ wheel.exclude = ["**.pyx"] Previously these were matched on the source path, rather than the wheel path, and didn't apply to CMake output. +You can exclude files from the built wheel based on file extension +as well (not guaranteed to be respected by editable installs): + +```toml +[tool.scikit-build] +wheel.exclude-exts = [".c", ".cuh", ".h"] +``` + +Default value: `[".pyc", ".pyo"]` + +:::{versionadded} 0.12 + +Support to exclude based on file extension. + ::: :::{note} diff --git a/src/scikit_build_core/build/_wheelfile.py b/src/scikit_build_core/build/_wheelfile.py index 84fd46afd..bd7b3540b 100644 --- a/src/scikit_build_core/build/_wheelfile.py +++ b/src/scikit_build_core/build/_wheelfile.py @@ -148,7 +148,7 @@ def dist_info_contents(self) -> dict[str, bytes]: } def build( - self, wheel_dirs: Mapping[str, Path], exclude: Sequence[str] = () + self, wheel_dirs: Mapping[str, Path], exclude: Sequence[str] = (), exclude_exts: Sequence[str] = () ) -> None: (targetlib,) = {"platlib", "purelib"} & set(wheel_dirs) assert { @@ -175,7 +175,7 @@ def build( continue if any(x.endswith(".dist-info") for x in filename.parts): continue - if filename.suffix in {".pyc", ".pyo"}: + if filename.suffix in exclude_exts: continue relpath = filename.relative_to(path) if exclude_spec.match_file(relpath): diff --git a/src/scikit_build_core/build/wheel.py b/src/scikit_build_core/build/wheel.py index 670419d33..db47352bc 100644 --- a/src/scikit_build_core/build/wheel.py +++ b/src/scikit_build_core/build/wheel.py @@ -495,7 +495,7 @@ def _build_wheel_impl_impl( ), wheel_dirs["metadata"], ) as wheel: - wheel.build(wheel_dirs, exclude=settings.wheel.exclude) + wheel.build(wheel_dirs, exclude=settings.wheel.exclude, exclude_exts=settings.wheel.exclude_exts) str_pkgs = ( str(Path.cwd().joinpath(p).parent.resolve()) for p in packages.values() diff --git a/src/scikit_build_core/settings/skbuild_model.py b/src/scikit_build_core/settings/skbuild_model.py index a83abd2f8..d6e79e19e 100644 --- a/src/scikit_build_core/settings/skbuild_model.py +++ b/src/scikit_build_core/settings/skbuild_model.py @@ -1,4 +1,5 @@ import dataclasses +from functools import partial from pathlib import Path from typing import Any, Dict, List, Literal, Optional, TypedDict, Union @@ -309,6 +310,18 @@ class WheelSettings: may not respect this exclusion. """ + exclude_exts: List[str] = dataclasses.field( + default_factory=lambda: [".pyc", ".pyo"], + metadata=SettingsFieldMetadata(display_default="true"), + ) + """ + A set of file extensions to exclude from the wheel. + + This is additive to the SDist/Wheel exclude patterns. This applies to the final paths + in the wheel, and can exclude files from CMake output as well. Editable installs + may not respect this exclusion. + """ + build_tag: str = "" """ The build tag to use for the wheel. If empty, no build tag is used. From 5bf701b3c47d0e11a3c5002e99cb5ba70793c72a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 15 Aug 2025 04:09:29 +0000 Subject: [PATCH 2/2] style: pre-commit fixes --- docs/configuration/index.md | 4 ++-- src/scikit_build_core/build/_wheelfile.py | 5 ++++- src/scikit_build_core/build/wheel.py | 6 +++++- src/scikit_build_core/settings/skbuild_model.py | 1 - 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/configuration/index.md b/docs/configuration/index.md index f334fef87..c02e7e191 100644 --- a/docs/configuration/index.md +++ b/docs/configuration/index.md @@ -329,8 +329,8 @@ wheel.exclude = ["**.pyx"] Previously these were matched on the source path, rather than the wheel path, and didn't apply to CMake output. -You can exclude files from the built wheel based on file extension -as well (not guaranteed to be respected by editable installs): +You can exclude files from the built wheel based on file extension as well (not +guaranteed to be respected by editable installs): ```toml [tool.scikit-build] diff --git a/src/scikit_build_core/build/_wheelfile.py b/src/scikit_build_core/build/_wheelfile.py index bd7b3540b..39d55ffd5 100644 --- a/src/scikit_build_core/build/_wheelfile.py +++ b/src/scikit_build_core/build/_wheelfile.py @@ -148,7 +148,10 @@ def dist_info_contents(self) -> dict[str, bytes]: } def build( - self, wheel_dirs: Mapping[str, Path], exclude: Sequence[str] = (), exclude_exts: Sequence[str] = () + self, + wheel_dirs: Mapping[str, Path], + exclude: Sequence[str] = (), + exclude_exts: Sequence[str] = (), ) -> None: (targetlib,) = {"platlib", "purelib"} & set(wheel_dirs) assert { diff --git a/src/scikit_build_core/build/wheel.py b/src/scikit_build_core/build/wheel.py index db47352bc..79b154719 100644 --- a/src/scikit_build_core/build/wheel.py +++ b/src/scikit_build_core/build/wheel.py @@ -495,7 +495,11 @@ def _build_wheel_impl_impl( ), wheel_dirs["metadata"], ) as wheel: - wheel.build(wheel_dirs, exclude=settings.wheel.exclude, exclude_exts=settings.wheel.exclude_exts) + wheel.build( + wheel_dirs, + exclude=settings.wheel.exclude, + exclude_exts=settings.wheel.exclude_exts, + ) str_pkgs = ( str(Path.cwd().joinpath(p).parent.resolve()) for p in packages.values() diff --git a/src/scikit_build_core/settings/skbuild_model.py b/src/scikit_build_core/settings/skbuild_model.py index d6e79e19e..0837e5554 100644 --- a/src/scikit_build_core/settings/skbuild_model.py +++ b/src/scikit_build_core/settings/skbuild_model.py @@ -1,5 +1,4 @@ import dataclasses -from functools import partial from pathlib import Path from typing import Any, Dict, List, Literal, Optional, TypedDict, Union