Skip to content

Commit

Permalink
Gate site_packages CMake prefix
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian Le <[email protected]>
  • Loading branch information
LecrisUT committed Sep 24, 2024
1 parent f0ae319 commit a09eb91
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
13 changes: 7 additions & 6 deletions src/scikit_build_core/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions src/scikit_build_core/resources/scikit-build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -599,6 +610,9 @@
"metadata": {
"$ref": "#/properties/metadata"
},
"search": {
"$ref": "#/properties/search"
},
"strict-config": {
"$ref": "#/properties/strict-config"
},
Expand Down
11 changes: 11 additions & 0 deletions src/scikit_build_core/settings/skbuild_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"MessagesSettings",
"NinjaSettings",
"SDistSettings",
"SearchSettings",
"ScikitBuildSettings",
"WheelSettings",
]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_skbuild_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)

Expand Down

0 comments on commit a09eb91

Please sign in to comment.