From 6b44e12cc5515e514fe28908cf77e048c0cba89c Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Thu, 29 Aug 2024 13:43:45 +0200 Subject: [PATCH] Gate site_packages CMake prefix Signed-off-by: Cristian Le --- README.md | 6 ++++++ src/scikit_build_core/builder/builder.py | 6 ++++-- .../resources/scikit-build.schema.json | 19 +++++++++++++++++++ .../settings/skbuild_model.py | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e369ac92..97ebc025 100644 --- a/README.md +++ b/README.md @@ -307,6 +307,12 @@ messages.after-failure = "" # A message to print after a successful build. messages.after-success = "" +# Add the wheel install path to the CMake prefix paths. +search.use-install-prefix = true + +# Add the wheel build path to the CMake prefix paths. +search.use-build-prefix = true + # List dynamic metadata fields and hook locations in this table. metadata = {} diff --git a/src/scikit_build_core/builder/builder.py b/src/scikit_build_core/builder/builder.py index db11bb4c..3d0980b8 100644 --- a/src/scikit_build_core/builder/builder.py +++ b/src/scikit_build_core/builder/builder.py @@ -132,10 +132,12 @@ def configure( # Add site-packages to the prefix path for CMake site_packages = Path(sysconfig.get_path("purelib")) - self.config.prefix_dirs.append(site_packages) + if self.settings.search.use_install_prefix: + self.config.prefix_dirs.append(site_packages) logger.debug("SITE_PACKAGES: {}", site_packages) if site_packages != DIR.parent.parent: - self.config.prefix_dirs.append(DIR.parent.parent) + if self.settings.search.use_build_prefix: + self.config.prefix_dirs.append(DIR.parent.parent) logger.debug("Extra SITE_PACKAGES: {}", site_packages) # Add the FindPython backport if needed diff --git a/src/scikit_build_core/resources/scikit-build.schema.json b/src/scikit_build_core/resources/scikit-build.schema.json index 6cfaa493..39163e09 100644 --- a/src/scikit_build_core/resources/scikit-build.schema.json +++ b/src/scikit_build_core/resources/scikit-build.schema.json @@ -93,6 +93,22 @@ } } }, + "search": { + "additionalProperties": false, + "properties": { + "use-build-prefix": { + "default": true, + "description": "Add the wheel build path to the CMake prefix paths.", + "type": "boolean" + }, + "use-install-prefix": { + "default": true, + "description": "Add the wheel install path to the CMake prefix paths.", + "type": "boolean" + } + }, + "type": "object" + }, "ninja": { "type": "object", "additionalProperties": false, @@ -599,6 +615,9 @@ "metadata": { "$ref": "#/properties/metadata" }, + "search": { + "$ref": "#/properties/search" + }, "strict-config": { "$ref": "#/properties/strict-config" }, diff --git a/src/scikit_build_core/settings/skbuild_model.py b/src/scikit_build_core/settings/skbuild_model.py index b33e0083..c6c89a59 100644 --- a/src/scikit_build_core/settings/skbuild_model.py +++ b/src/scikit_build_core/settings/skbuild_model.py @@ -80,6 +80,19 @@ class CMakeSettings: """ +@dataclasses.dataclass +class SearchSettings: + use_install_prefix: bool = True + """ + Add the wheel install path to the CMake prefix paths. + """ + + use_build_prefix: bool = True + """ + Add the wheel build path to the CMake prefix paths. + """ + + @dataclasses.dataclass class NinjaSettings: minimum_version: Optional[Version] = None @@ -325,6 +338,7 @@ class ScikitBuildSettings: install: InstallSettings = dataclasses.field(default_factory=InstallSettings) generate: List[GenerateSettings] = dataclasses.field(default_factory=list) messages: MessagesSettings = dataclasses.field(default_factory=MessagesSettings) + search: SearchSettings = dataclasses.field(default_factory=SearchSettings) metadata: Dict[str, Dict[str, Any]] = dataclasses.field(default_factory=dict) """