diff --git a/docs/configuration/index.md b/docs/configuration/index.md index 14c899e76..c02e7e191 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..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] = () + self, + wheel_dirs: Mapping[str, Path], + exclude: Sequence[str] = (), + exclude_exts: Sequence[str] = (), ) -> None: (targetlib,) = {"platlib", "purelib"} & set(wheel_dirs) assert { @@ -175,7 +178,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..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) + 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..0837e5554 100644 --- a/src/scikit_build_core/settings/skbuild_model.py +++ b/src/scikit_build_core/settings/skbuild_model.py @@ -309,6 +309,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.