Skip to content

Commit

Permalink
fix: avoid providing prepare-metadata methods if rebuild is True
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Sep 20, 2024
1 parent ca529d6 commit d85e655
Showing 1 changed file with 44 additions and 18 deletions.
62 changes: 44 additions & 18 deletions src/scikit_build_core/build/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import sys

from .._compat import tomllib

__all__ = [
"build_editable",
"build_sdist",
Expand Down Expand Up @@ -66,29 +68,53 @@ def build_editable(
raise SystemExit(1) from None


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

Check warning on line 76 in src/scikit_build_core/build/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/build/__init__.py#L75-L76

Added lines #L75 - L76 were not covered by tests

return _build_wheel_impl(
None, config_settings, metadata_directory, editable=False
).wheel_filename # actually returns the dist-info directory
overrides = pyproject.get("tool", {}).get("scikit-build", {}).get("overrides", [])
for override in overrides:
if_override = override.get("if", {})
if if_override.get("failed", False) or if_override.get("any", {}).get(

Check warning on line 81 in src/scikit_build_core/build/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/build/__init__.py#L80-L81

Added lines #L80 - L81 were not covered by tests
"failed", False
):
return False

Check warning on line 84 in src/scikit_build_core/build/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/build/__init__.py#L84

Added line #L84 was not covered by tests

return True

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

from .wheel import _build_wheel_impl
if _has_safe_metadata():

return _build_wheel_impl(
None, config_settings, metadata_directory, editable=True
).wheel_filename # actually returns the dist-info directory
def prepare_metadata_for_build_wheel(
metadata_directory: str,
config_settings: dict[str, list[str] | str] | None = None,
) -> str:
"""Prepare metadata for building a wheel. Does not build the wheel. Returns the dist-info directory."""
from .wheel import _build_wheel_impl

return _build_wheel_impl(
None, config_settings, metadata_directory, editable=False
).wheel_filename # actually returns the dist-info directory

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

from .wheel import _build_wheel_impl

return _build_wheel_impl(
None, config_settings, metadata_directory, editable=True
).wheel_filename # actually returns the dist-info directory

__all__ += [
"prepare_metadata_for_build_wheel",
"prepare_metadata_for_build_editable",
]


def build_sdist(
Expand Down

0 comments on commit d85e655

Please sign in to comment.