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 <cristian.le@mpsd.mpg.de>
  • Loading branch information
LecrisUT committed Aug 29, 2024
1 parent 1124da7 commit 6b44e12
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
6 changes: 4 additions & 2 deletions src/scikit_build_core/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 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,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,
Expand Down Expand Up @@ -599,6 +615,9 @@
"metadata": {
"$ref": "#/properties/metadata"
},
"search": {
"$ref": "#/properties/search"
},
"strict-config": {
"$ref": "#/properties/strict-config"
},
Expand Down
14 changes: 14 additions & 0 deletions src/scikit_build_core/settings/skbuild_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
"""
Expand Down

0 comments on commit 6b44e12

Please sign in to comment.