From 37daf6106abd2cfac2c0bb1468c8dc0214469ad7 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 10 Sep 2024 15:50:45 -0400 Subject: [PATCH] fix: support multiplexed path (#896) Pulling out this fix from https://github.com/scikit-build/scikit-build-core/pull/880 for inclusion in a patch release. --------- Signed-off-by: Henry Schreiner Co-authored-by: Cristian Le --- src/scikit_build_core/builder/builder.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/scikit_build_core/builder/builder.py b/src/scikit_build_core/builder/builder.py index acbe114c..437265f4 100644 --- a/src/scikit_build_core/builder/builder.py +++ b/src/scikit_build_core/builder/builder.py @@ -1,6 +1,7 @@ from __future__ import annotations import dataclasses +import os import re import shlex import sys @@ -84,6 +85,18 @@ def _filter_env_cmake_args(env_cmake_args: list[str]) -> Generator[str, None, No yield arg +def _sanitize_path(path: os.PathLike[str]) -> list[Path]: + # This handles classes like: + # MultiplexedPath from importlib.resources.readers (3.11+) + # MultiplexedPath from importlib.readers (3.10) + # MultiplexedPath from importlib_resources.readers + if hasattr(path, "_paths"): + # pylint: disable-next=protected-access + return [Path(os.fspath(p)) for p in path._paths] + + return [Path(os.fspath(path))] + + @dataclasses.dataclass class Builder: settings: ScikitBuildSettings @@ -124,11 +137,15 @@ 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) + self.config.module_dirs.extend( + p for ep in eps for p in _sanitize_path(resources.files(ep.load())) + ) # 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) + self.config.prefix_dirs.extend( + p for ep in eps for p in _sanitize_path(resources.files(ep.load())) + ) # Add site-packages to the prefix path for CMake site_packages = Path(sysconfig.get_path("purelib")) @@ -137,6 +154,7 @@ def configure( if site_packages != DIR.parent.parent: self.config.prefix_dirs.append(DIR.parent.parent) logger.debug("Extra SITE_PACKAGES: {}", DIR.parent.parent) + logger.debug("PATH: {}", sys.path) # Add the FindPython backport if needed if self.config.cmake.version < self.settings.backport.find_python: