Skip to content

Commit d85e655

Browse files
committed
fix: avoid providing prepare-metadata methods if rebuild is True
Signed-off-by: Henry Schreiner <[email protected]>
1 parent ca529d6 commit d85e655

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

src/scikit_build_core/build/__init__.py

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import sys
88

9+
from .._compat import tomllib
10+
911
__all__ = [
1012
"build_editable",
1113
"build_sdist",
@@ -66,29 +68,53 @@ def build_editable(
6668
raise SystemExit(1) from None
6769

6870

69-
def prepare_metadata_for_build_wheel(
70-
metadata_directory: str,
71-
config_settings: dict[str, list[str] | str] | None = None,
72-
) -> str:
73-
"""Prepare metadata for building a wheel. Does not build the wheel. Returns the dist-info directory."""
74-
from .wheel import _build_wheel_impl
71+
def _has_safe_metadata() -> bool:
72+
try:
73+
with open("pyproject.toml", "rb") as f: # noqa: PTH123
74+
pyproject = tomllib.load(f)
75+
except FileNotFoundError:
76+
return True
7577

76-
return _build_wheel_impl(
77-
None, config_settings, metadata_directory, editable=False
78-
).wheel_filename # actually returns the dist-info directory
78+
overrides = pyproject.get("tool", {}).get("scikit-build", {}).get("overrides", [])
79+
for override in overrides:
80+
if_override = override.get("if", {})
81+
if if_override.get("failed", False) or if_override.get("any", {}).get(
82+
"failed", False
83+
):
84+
return False
7985

86+
return True
8087

81-
def prepare_metadata_for_build_editable(
82-
metadata_directory: str,
83-
config_settings: dict[str, list[str] | str] | None = None,
84-
) -> str:
85-
"""Prepare metadata for building a wheel. Does not build the wheel. Returns the dist-info directory."""
8688

87-
from .wheel import _build_wheel_impl
89+
if _has_safe_metadata():
8890

89-
return _build_wheel_impl(
90-
None, config_settings, metadata_directory, editable=True
91-
).wheel_filename # actually returns the dist-info directory
91+
def prepare_metadata_for_build_wheel(
92+
metadata_directory: str,
93+
config_settings: dict[str, list[str] | str] | None = None,
94+
) -> str:
95+
"""Prepare metadata for building a wheel. Does not build the wheel. Returns the dist-info directory."""
96+
from .wheel import _build_wheel_impl
97+
98+
return _build_wheel_impl(
99+
None, config_settings, metadata_directory, editable=False
100+
).wheel_filename # actually returns the dist-info directory
101+
102+
def prepare_metadata_for_build_editable(
103+
metadata_directory: str,
104+
config_settings: dict[str, list[str] | str] | None = None,
105+
) -> str:
106+
"""Prepare metadata for building a wheel. Does not build the wheel. Returns the dist-info directory."""
107+
108+
from .wheel import _build_wheel_impl
109+
110+
return _build_wheel_impl(
111+
None, config_settings, metadata_directory, editable=True
112+
).wheel_filename # actually returns the dist-info directory
113+
114+
__all__ += [
115+
"prepare_metadata_for_build_wheel",
116+
"prepare_metadata_for_build_editable",
117+
]
92118

93119

94120
def build_sdist(

0 commit comments

Comments
 (0)