Skip to content

Commit

Permalink
Add settings to override/extend search paths
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 42445ee commit 81742a7
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 8 deletions.
44 changes: 36 additions & 8 deletions src/scikit_build_core/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,47 @@ def configure(
}

# Add any extra CMake modules
eps = metadata.entry_points(group="cmake.module")
self.config.module_dirs.extend(resources.files(ep.load()) for ep in eps)
module_dirs_dict = {
ep.name: resources.files(ep.load())
for ep in metadata.entry_points(group="cmake.module")
}
if isinstance(self.settings.search.modules, dict):
# Allow to override any entry-point definition
module_dirs_dict.update(self.settings.search.modules)
module_dirs = list(module_dirs_dict.values())
if isinstance(self.settings.search.modules, list):
# If it was a list, append to the entry-point definitions
module_dirs += self.settings.search.modules
# Remove any empty paths
module_dirs = [path for path in module_dirs if path]
self.config.module_dirs.extend(module_dirs)

# Add any extra CMake prefixes
eps = metadata.entry_points(group="cmake.prefix")
self.config.prefix_dirs.extend(resources.files(ep.load()) for ep in eps)
prefix_dirs_dict = {
ep.name: resources.files(ep.load())
for ep in metadata.entry_points(group="cmake.prefix")
}
if isinstance(self.settings.search.prefixes, dict):
# Allow to override any entry-point definition
prefix_dirs_dict.update(self.settings.search.prefixes)
prefix_dirs = list(prefix_dirs_dict.values())
if isinstance(self.settings.search.prefixes, list):
# If it was a list, append to the entry-point definitions
prefix_dirs += self.settings.search.prefixes
# Remove any empty paths
prefix_dirs = [path for path in prefix_dirs if path]
self.config.prefix_dirs.extend(prefix_dirs)

# Add all CMake roots
eps = metadata.entry_points(group="cmake.root")
prefix_roots = {
ep.name: resources.files(ep.load())
for ep in metadata.entry_points(group="cmake.root")
}
# TODO: Check for unique uppercase names
self.config.prefix_roots.update(
{ep.name: resources.files(ep.load()) for ep in eps}
)
prefix_roots.update(self.settings.search.roots)
# Remove any empty paths
prefix_roots = {pkg: path for pkg, path in prefix_roots.items() if path}
self.config.prefix_roots.update(prefix_roots)

# Add site-packages to the prefix path for CMake
site_packages = Path(sysconfig.get_path("purelib"))
Expand Down
47 changes: 47 additions & 0 deletions src/scikit_build_core/resources/scikit-build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,53 @@
"search": {
"additionalProperties": false,
"properties": {
"modules": {
"description": "List or dict of CMake module search paths. Dict from is used to override another package's entry-point definition. Populates `CMAKE_MODULE_PATH`.",
"oneOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "object",
"patternProperties": {
".+": {
"type": "string"
}
}
}
]
},
"prefixes": {
"description": "List or dict of CMake prefix search paths. Dict from is used to override another package's entry-point definition. Populates `CMAKE_PREFIX_PATH`.",
"oneOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "object",
"patternProperties": {
".+": {
"type": "string"
}
}
}
]
},
"roots": {
"description": "Dict of package names and prefix paths. Populates `<Pkg>_ROOT`.",
"type": "object",
"patternProperties": {
".+": {
"type": "string"
}
}
},
"use-build-prefix": {
"default": true,
"description": "Add the wheel build path to the CMake prefix paths.",
Expand Down
17 changes: 17 additions & 0 deletions src/scikit_build_core/settings/skbuild_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ class SearchSettings:
Add the wheel build path to the CMake prefix paths.
"""

modules: Optional[Union[List[Path], Dict[str, Path]]] = None
"""
List or dict of CMake module search paths. Dict from is used to override
another package's entry-point definition. Populates `CMAKE_MODULE_PATH`.
"""

prefixes: Optional[Union[List[Path], Dict[str, Path]]] = None
"""
List or dict of CMake prefix search paths. Dict from is used to override
another package's entry-point definition. Populates `CMAKE_PREFIX_PATH`.
"""

roots: Dict[str, Path] = dataclasses.field(default_factory=dict)
"""
Dict of package names and prefix paths. Populates `<Pkg>_ROOT`.
"""


@dataclasses.dataclass
class NinjaSettings:
Expand Down

0 comments on commit 81742a7

Please sign in to comment.