Skip to content

Commit

Permalink
Make build backend type annotations more generic (#10549)
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt authored Jan 13, 2025
1 parent c946e47 commit 2401878
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions python/uv/_build_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@

TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Mapping, Sequence # noqa:I001
from typing import Any # noqa:I001


def warn_config_settings(config_settings: "dict[Any, Any] | None" = None) -> None:
def warn_config_settings(config_settings: "Mapping[Any, Any] | None" = None) -> None:
import sys

if config_settings:
print("Warning: Config settings are not supported", file=sys.stderr)


def call(args: "list[str]", config_settings: "dict[Any, Any] | None" = None) -> str:
def call(
args: "Sequence[str]", config_settings: "Mapping[Any, Any] | None" = None
) -> str:
"""Invoke a uv subprocess and return the filename from stdout."""
import shutil
import subprocess
Expand All @@ -40,7 +43,7 @@ def call(args: "list[str]", config_settings: "dict[Any, Any] | None" = None) ->
if uv_bin is None:
raise RuntimeError("uv was not properly installed")
# Forward stderr, capture stdout for the filename
result = subprocess.run([uv_bin] + args, stdout=subprocess.PIPE)
result = subprocess.run([uv_bin, *args], stdout=subprocess.PIPE)
if result.returncode != 0:
sys.exit(result.returncode)
# If there was extra stdout, forward it (there should not be extra stdout)
Expand All @@ -54,7 +57,7 @@ def call(args: "list[str]", config_settings: "dict[Any, Any] | None" = None) ->


def build_sdist(
sdist_directory: str, config_settings: "dict[Any, Any] | None" = None
sdist_directory: str, config_settings: "Mapping[Any, Any] | None" = None
) -> str:
"""PEP 517 hook `build_sdist`."""
args = ["build-backend", "build-sdist", sdist_directory]
Expand All @@ -63,7 +66,7 @@ def build_sdist(

def build_wheel(
wheel_directory: str,
config_settings: "dict[Any, Any] | None" = None,
config_settings: "Mapping[Any, Any] | None" = None,
metadata_directory: "str | None" = None,
) -> str:
"""PEP 517 hook `build_wheel`."""
Expand All @@ -74,23 +77,23 @@ def build_wheel(


def get_requires_for_build_sdist(
config_settings: "dict[Any, Any] | None" = None,
) -> "list[str]":
config_settings: "Mapping[Any, Any] | None" = None,
) -> "Sequence[str]":
"""PEP 517 hook `get_requires_for_build_sdist`."""
warn_config_settings(config_settings)
return []


def get_requires_for_build_wheel(
config_settings: "dict[Any, Any] | None" = None,
) -> "list[str]":
config_settings: "Mapping[Any, Any] | None" = None,
) -> "Sequence[str]":
"""PEP 517 hook `get_requires_for_build_wheel`."""
warn_config_settings(config_settings)
return []


def prepare_metadata_for_build_wheel(
metadata_directory: str, config_settings: "dict[Any, Any] | None" = None
metadata_directory: str, config_settings: "Mapping[Any, Any] | None" = None
) -> str:
"""PEP 517 hook `prepare_metadata_for_build_wheel`."""
args = ["build-backend", "prepare-metadata-for-build-wheel", metadata_directory]
Expand All @@ -99,7 +102,7 @@ def prepare_metadata_for_build_wheel(

def build_editable(
wheel_directory: str,
config_settings: "dict[Any, Any] | None" = None,
config_settings: "Mapping[Any, Any] | None" = None,
metadata_directory: "str | None" = None,
) -> str:
"""PEP 660 hook `build_editable`."""
Expand All @@ -110,15 +113,15 @@ def build_editable(


def get_requires_for_build_editable(
config_settings: "dict[Any, Any] | None" = None,
) -> "list[str]":
config_settings: "Mapping[Any, Any] | None" = None,
) -> "Sequence[str]":
"""PEP 660 hook `get_requires_for_build_editable`."""
warn_config_settings(config_settings)
return []


def prepare_metadata_for_build_editable(
metadata_directory: str, config_settings: "dict[Any, Any] | None" = None
metadata_directory: str, config_settings: "Mapping[Any, Any] | None" = None
) -> str:
"""PEP 660 hook `prepare_metadata_for_build_editable`."""
args = ["build-backend", "prepare-metadata-for-build-editable", metadata_directory]
Expand Down

0 comments on commit 2401878

Please sign in to comment.