Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support multiplexed path #896

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Changes from all commits
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
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 @@
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"):

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

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/builder/builder.py#L93

Added line #L93 was not covered by tests
# pylint: disable-next=protected-access
return [Path(os.fspath(p)) for p in path._paths]

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

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/builder/builder.py#L95

Added line #L95 was not covered by tests

return [Path(os.fspath(path))]

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

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/builder/builder.py#L97

Added line #L97 was not covered by tests


@dataclasses.dataclass
class Builder:
settings: ScikitBuildSettings
Expand Down Expand Up @@ -124,11 +137,15 @@

# 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 @@
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
Loading