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 c9454cd
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 8 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,17 @@ search.use-install-prefix = true
# Add the wheel build path to the CMake prefix paths.
search.use-build-prefix = true

# List or dict of CMake module search paths. Dict from is used to override
# another package's entry-point definition. Populates `CMAKE_MODULE_PATH`.
search.modules = ""

# List or dict of CMake prefix search paths. Dict from is used to override
# another package's entry-point definition. Populates `CMAKE_PREFIX_PATH`.
search.prefixes = ""

# Dict of package names and prefix paths. Populates `<Pkg>_ROOT`.
search.roots = {}

# List dynamic metadata fields and hook locations in this table.
metadata = {}

Expand Down
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)

Check warning on line 132 in src/scikit_build_core/builder/builder.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/builder/builder.py#L132

Added line #L132 was not covered by tests
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

Check warning on line 136 in src/scikit_build_core/builder/builder.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/builder/builder.py#L136

Added line #L136 was not covered by tests
# 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)

Check warning on line 148 in src/scikit_build_core/builder/builder.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/builder/builder.py#L148

Added line #L148 was not covered by tests
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

Check warning on line 152 in src/scikit_build_core/builder/builder.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/builder/builder.py#L152

Added line #L152 was not covered by tests
# 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
62 changes: 62 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 Expand Up @@ -540,6 +587,21 @@
}
}
},
"search": {
"type": "object",
"additionalProperties": false,
"properties": {
"modules": {
"$ref": "#/$defs/inherit"
},
"prefixes": {
"$ref": "#/$defs/inherit"
},
"roots": {
"$ref": "#/$defs/inherit"
}
}
},
"wheel": {
"type": "object",
"additionalProperties": false,
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 c9454cd

Please sign in to comment.