From a09eb91dcec4916912dd376b8b50f18221882a24 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 | 4 ++++ src/scikit_build_core/builder/builder.py | 13 +++++++------ .../resources/scikit-build.schema.json | 14 ++++++++++++++ src/scikit_build_core/settings/skbuild_model.py | 11 +++++++++++ tests/test_skbuild_settings.py | 2 +- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c62a9f58..1048637e 100644 --- a/README.md +++ b/README.md @@ -308,6 +308,10 @@ messages.after-failure = "" # A message to print after a successful build. messages.after-success = "" +# Add the install (or build isolation) site_packages folder to the CMake prefix +# paths. +use-site-packages = 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 437265f4..cc52773a 100644 --- a/src/scikit_build_core/builder/builder.py +++ b/src/scikit_build_core/builder/builder.py @@ -149,12 +149,13 @@ 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) - logger.debug("SITE_PACKAGES: {}", site_packages) - if site_packages != DIR.parent.parent: - self.config.prefix_dirs.append(DIR.parent.parent) - logger.debug("Extra SITE_PACKAGES: {}", DIR.parent.parent) - logger.debug("PATH: {}", sys.path) + if self.settings.search.use_site_packages: + 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) + logger.debug("Extra SITE_PACKAGES: {}", DIR.parent.parent) + logger.debug("PATH: {}", sys.path) # Add the FindPython backport if needed if self.config.cmake.version < self.settings.backport.find_python: diff --git a/src/scikit_build_core/resources/scikit-build.schema.json b/src/scikit_build_core/resources/scikit-build.schema.json index 2f77d20f..4dcb2b00 100644 --- a/src/scikit_build_core/resources/scikit-build.schema.json +++ b/src/scikit_build_core/resources/scikit-build.schema.json @@ -93,6 +93,17 @@ } } }, + "search": { + "additionalProperties": false, + "properties": { + "use-site-packages": { + "default": true, + "description": "Add the install (or build isolation) site_packages folder to the CMake prefix paths.", + "type": "boolean" + } + }, + "type": "object" + }, "ninja": { "type": "object", "additionalProperties": false, @@ -599,6 +610,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 3251dc5e..16fd8fc6 100644 --- a/src/scikit_build_core/settings/skbuild_model.py +++ b/src/scikit_build_core/settings/skbuild_model.py @@ -18,6 +18,7 @@ "MessagesSettings", "NinjaSettings", "SDistSettings", + "SearchSettings", "ScikitBuildSettings", "WheelSettings", ] @@ -80,6 +81,15 @@ class CMakeSettings: """ +@dataclasses.dataclass +class SearchSettings: + use_site_packages: bool = True + """ + Add the install (or build isolation) site_packages folder to the CMake prefix + paths. + """ + + @dataclasses.dataclass class NinjaSettings: minimum_version: Optional[Version] = None @@ -326,6 +336,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) """ diff --git a/tests/test_skbuild_settings.py b/tests/test_skbuild_settings.py index 442eaa84..e5efda58 100644 --- a/tests/test_skbuild_settings.py +++ b/tests/test_skbuild_settings.py @@ -400,7 +400,7 @@ def test_skbuild_settings_pyproject_toml_broken( == """\ ERROR: Unrecognized options in pyproject.toml: tool.scikit-build.cmake.verison -> Did you mean: tool.scikit-build.cmake.version, tool.scikit-build.cmake.verbose, tool.scikit-build.cmake.define? - tool.scikit-build.logger -> Did you mean: tool.scikit-build.logging, tool.scikit-build.generate, tool.scikit-build.fail? + tool.scikit-build.logger -> Did you mean: tool.scikit-build.logging, tool.scikit-build.generate, tool.scikit-build.search? """.split() )