Skip to content

Commit 37daf61

Browse files
henryiiiLecrisUT
andauthored
fix: support multiplexed path (#896)
Pulling out this fix from #880 for inclusion in a patch release. --------- Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: Cristian Le <[email protected]>
1 parent a3df152 commit 37daf61

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/scikit_build_core/builder/builder.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import dataclasses
4+
import os
45
import re
56
import shlex
67
import sys
@@ -84,6 +85,18 @@ def _filter_env_cmake_args(env_cmake_args: list[str]) -> Generator[str, None, No
8485
yield arg
8586

8687

88+
def _sanitize_path(path: os.PathLike[str]) -> list[Path]:
89+
# This handles classes like:
90+
# MultiplexedPath from importlib.resources.readers (3.11+)
91+
# MultiplexedPath from importlib.readers (3.10)
92+
# MultiplexedPath from importlib_resources.readers
93+
if hasattr(path, "_paths"):
94+
# pylint: disable-next=protected-access
95+
return [Path(os.fspath(p)) for p in path._paths]
96+
97+
return [Path(os.fspath(path))]
98+
99+
87100
@dataclasses.dataclass
88101
class Builder:
89102
settings: ScikitBuildSettings
@@ -124,11 +137,15 @@ def configure(
124137

125138
# Add any extra CMake modules
126139
eps = metadata.entry_points(group="cmake.module")
127-
self.config.module_dirs.extend(resources.files(ep.load()) for ep in eps)
140+
self.config.module_dirs.extend(
141+
p for ep in eps for p in _sanitize_path(resources.files(ep.load()))
142+
)
128143

129144
# Add any extra CMake prefixes
130145
eps = metadata.entry_points(group="cmake.prefix")
131-
self.config.prefix_dirs.extend(resources.files(ep.load()) for ep in eps)
146+
self.config.prefix_dirs.extend(
147+
p for ep in eps for p in _sanitize_path(resources.files(ep.load()))
148+
)
132149

133150
# Add site-packages to the prefix path for CMake
134151
site_packages = Path(sysconfig.get_path("purelib"))
@@ -137,6 +154,7 @@ def configure(
137154
if site_packages != DIR.parent.parent:
138155
self.config.prefix_dirs.append(DIR.parent.parent)
139156
logger.debug("Extra SITE_PACKAGES: {}", DIR.parent.parent)
157+
logger.debug("PATH: {}", sys.path)
140158

141159
# Add the FindPython backport if needed
142160
if self.config.cmake.version < self.settings.backport.find_python:

0 commit comments

Comments
 (0)