Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ known-local-folder = ["pathutils"]
"importlib_metadata".msg = "Use scikit_build_core._compat.importlib.metadata instead."
"importlib.resources".msg = "Use scikit_build_core._compat.importlib.resources instead."
"importlib_resources".msg = "Use scikit_build_core._compat.importlib.resources instead."
"importlib.readers".msg = "Use scikit_build_core._compat.importlib.readers instead."
"pyproject_metadata".msg = "Use scikit_build_core._vendor.pyproject_metadata instead."


Expand Down
24 changes: 24 additions & 0 deletions src/scikit_build_core/_compat/importlib/readers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations

import sys
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from pathlib import Path

if sys.version_info < (3, 10):
# Readers and MultiplexedPath were introduced in 3.10, so nothing should output a MultiplexedPath
# It is also tricky because it is unclear if the `resource_loader` when calling `import` would create
# either importlib.readers.MultiplexedPath or importlib_resources.MultiplexedPath.
# Creating a dummy class instead so that if it fails, it fails completely (and mypy is made happy)
class MultiplexedPath:
_paths: list[Path]
else:
# From 3.11 this is an alias of importlib.resources.readers
from importlib.readers import MultiplexedPath

__all__ = ["MultiplexedPath"]


def __dir__() -> list[str]:
return __all__
20 changes: 18 additions & 2 deletions src/scikit_build_core/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from .. import __version__
from .._compat.importlib import metadata, resources
from .._compat.importlib.readers import MultiplexedPath
from .._logging import logger
from ..resources import find_python
from .generator import set_environment_for_gen
Expand All @@ -22,6 +23,7 @@
)

if TYPE_CHECKING:
import os
from collections.abc import Generator, Iterable, Mapping, Sequence

from packaging.version import Version
Expand Down Expand Up @@ -84,6 +86,15 @@ def _filter_env_cmake_args(env_cmake_args: list[str]) -> Generator[str, None, No
yield arg


# Type-hinting for Traversable is rather hard because they were introduced in python 3.11.
# This avoids introducing importlib_resources dependency that may not be used in the actual package loader
def _sanitize_path(path: os.PathLike[str]) -> list[Path]:
if isinstance(path, MultiplexedPath):
# pylint: disable-next=protected-access
return path._paths
return [Path(path)]


@dataclasses.dataclass
class Builder:
settings: ScikitBuildSettings
Expand Down Expand Up @@ -124,11 +135,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 +152,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