Skip to content

Commit

Permalink
fix: support multiplexed path (#896)
Browse files Browse the repository at this point in the history
Pulling out this fix from
#880 for inclusion
in a patch release.

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Cristian Le <cristian.le@mpsd.mpg.de>
  • Loading branch information
henryiii and LecrisUT committed Sep 10, 2024
1 parent a3df152 commit 37daf61
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/scikit_build_core/builder/builder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import dataclasses
import os
import re
import shlex
import sys
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand All @@ -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:
Expand Down

0 comments on commit 37daf61

Please sign in to comment.