Skip to content

Commit 81742a7

Browse files
committed
Add settings to override/extend search paths
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
1 parent 42445ee commit 81742a7

File tree

3 files changed

+100
-8
lines changed

3 files changed

+100
-8
lines changed

src/scikit_build_core/builder/builder.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,47 @@ def configure(
123123
}
124124

125125
# Add any extra CMake modules
126-
eps = metadata.entry_points(group="cmake.module")
127-
self.config.module_dirs.extend(resources.files(ep.load()) for ep in eps)
126+
module_dirs_dict = {
127+
ep.name: resources.files(ep.load())
128+
for ep in metadata.entry_points(group="cmake.module")
129+
}
130+
if isinstance(self.settings.search.modules, dict):
131+
# Allow to override any entry-point definition
132+
module_dirs_dict.update(self.settings.search.modules)
133+
module_dirs = list(module_dirs_dict.values())
134+
if isinstance(self.settings.search.modules, list):
135+
# If it was a list, append to the entry-point definitions
136+
module_dirs += self.settings.search.modules
137+
# Remove any empty paths
138+
module_dirs = [path for path in module_dirs if path]
139+
self.config.module_dirs.extend(module_dirs)
128140

129141
# Add any extra CMake prefixes
130-
eps = metadata.entry_points(group="cmake.prefix")
131-
self.config.prefix_dirs.extend(resources.files(ep.load()) for ep in eps)
142+
prefix_dirs_dict = {
143+
ep.name: resources.files(ep.load())
144+
for ep in metadata.entry_points(group="cmake.prefix")
145+
}
146+
if isinstance(self.settings.search.prefixes, dict):
147+
# Allow to override any entry-point definition
148+
prefix_dirs_dict.update(self.settings.search.prefixes)
149+
prefix_dirs = list(prefix_dirs_dict.values())
150+
if isinstance(self.settings.search.prefixes, list):
151+
# If it was a list, append to the entry-point definitions
152+
prefix_dirs += self.settings.search.prefixes
153+
# Remove any empty paths
154+
prefix_dirs = [path for path in prefix_dirs if path]
155+
self.config.prefix_dirs.extend(prefix_dirs)
132156

133157
# Add all CMake roots
134-
eps = metadata.entry_points(group="cmake.root")
158+
prefix_roots = {
159+
ep.name: resources.files(ep.load())
160+
for ep in metadata.entry_points(group="cmake.root")
161+
}
135162
# TODO: Check for unique uppercase names
136-
self.config.prefix_roots.update(
137-
{ep.name: resources.files(ep.load()) for ep in eps}
138-
)
163+
prefix_roots.update(self.settings.search.roots)
164+
# Remove any empty paths
165+
prefix_roots = {pkg: path for pkg, path in prefix_roots.items() if path}
166+
self.config.prefix_roots.update(prefix_roots)
139167

140168
# Add site-packages to the prefix path for CMake
141169
site_packages = Path(sysconfig.get_path("purelib"))

src/scikit_build_core/resources/scikit-build.schema.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,53 @@
9696
"search": {
9797
"additionalProperties": false,
9898
"properties": {
99+
"modules": {
100+
"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`.",
101+
"oneOf": [
102+
{
103+
"type": "array",
104+
"items": {
105+
"type": "string"
106+
}
107+
},
108+
{
109+
"type": "object",
110+
"patternProperties": {
111+
".+": {
112+
"type": "string"
113+
}
114+
}
115+
}
116+
]
117+
},
118+
"prefixes": {
119+
"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`.",
120+
"oneOf": [
121+
{
122+
"type": "array",
123+
"items": {
124+
"type": "string"
125+
}
126+
},
127+
{
128+
"type": "object",
129+
"patternProperties": {
130+
".+": {
131+
"type": "string"
132+
}
133+
}
134+
}
135+
]
136+
},
137+
"roots": {
138+
"description": "Dict of package names and prefix paths. Populates `<Pkg>_ROOT`.",
139+
"type": "object",
140+
"patternProperties": {
141+
".+": {
142+
"type": "string"
143+
}
144+
}
145+
},
99146
"use-build-prefix": {
100147
"default": true,
101148
"description": "Add the wheel build path to the CMake prefix paths.",

src/scikit_build_core/settings/skbuild_model.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,23 @@ class SearchSettings:
9393
Add the wheel build path to the CMake prefix paths.
9494
"""
9595

96+
modules: Optional[Union[List[Path], Dict[str, Path]]] = None
97+
"""
98+
List or dict of CMake module search paths. Dict from is used to override
99+
another package's entry-point definition. Populates `CMAKE_MODULE_PATH`.
100+
"""
101+
102+
prefixes: Optional[Union[List[Path], Dict[str, Path]]] = None
103+
"""
104+
List or dict of CMake prefix search paths. Dict from is used to override
105+
another package's entry-point definition. Populates `CMAKE_PREFIX_PATH`.
106+
"""
107+
108+
roots: Dict[str, Path] = dataclasses.field(default_factory=dict)
109+
"""
110+
Dict of package names and prefix paths. Populates `<Pkg>_ROOT`.
111+
"""
112+
96113

97114
@dataclasses.dataclass
98115
class NinjaSettings:

0 commit comments

Comments
 (0)