Skip to content

Commit

Permalink
Add remaining Python type annotations to build backend (#10434)
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt authored Jan 10, 2025
1 parent 7bf514d commit f4f1587
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions python/uv/_build_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
them while IDEs and type checker can see through the quotes.
"""

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Any # noqa:I001

def warn_config_settings(config_settings: "dict | None" = None):

def warn_config_settings(config_settings: "dict[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 | None" = None) -> str:
def call(args: "list[str]", config_settings: "dict[Any, Any] | None" = None) -> str:
"""Invoke a uv subprocess and return the filename from stdout."""
import shutil
import subprocess
Expand All @@ -49,65 +53,73 @@ def call(args: "list[str]", config_settings: "dict | None" = None) -> str:
return stdout[-1].strip()


def build_sdist(sdist_directory: str, config_settings: "dict | None" = None):
def build_sdist(
sdist_directory: str, config_settings: "dict[Any, Any] | None" = None
) -> str:
"""PEP 517 hook `build_sdist`."""
args = ["build-backend", "build-sdist", sdist_directory]
return call(args, config_settings)


def build_wheel(
wheel_directory: str,
config_settings: "dict | None" = None,
config_settings: "dict[Any, Any] | None" = None,
metadata_directory: "str | None" = None,
):
) -> str:
"""PEP 517 hook `build_wheel`."""
args = ["build-backend", "build-wheel", wheel_directory]
if metadata_directory:
args.extend(["--metadata-directory", metadata_directory])
return call(args, config_settings)


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


def get_requires_for_build_wheel(config_settings: "dict | None" = None):
def get_requires_for_build_wheel(
config_settings: "dict[Any, Any] | None" = None,
) -> "list[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 | None" = None
):
metadata_directory: str, config_settings: "dict[Any, Any] | None" = None
) -> str:
"""PEP 517 hook `prepare_metadata_for_build_wheel`."""
args = ["build-backend", "prepare-metadata-for-build-wheel", metadata_directory]
return call(args, config_settings)


def build_editable(
wheel_directory: str,
config_settings: "dict | None" = None,
config_settings: "dict[Any, Any] | None" = None,
metadata_directory: "str | None" = None,
):
) -> str:
"""PEP 660 hook `build_editable`."""
args = ["build-backend", "build-editable", wheel_directory]
if metadata_directory:
args.extend(["--metadata-directory", metadata_directory])
return call(args, config_settings)


def get_requires_for_build_editable(config_settings: "dict | None" = None):
def get_requires_for_build_editable(
config_settings: "dict[Any, Any] | None" = None,
) -> "list[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 | None" = None
):
metadata_directory: str, config_settings: "dict[Any, Any] | None" = None
) -> str:
"""PEP 660 hook `prepare_metadata_for_build_editable`."""
args = ["build-backend", "prepare-metadata-for-build-editable", metadata_directory]
return call(args, config_settings)

0 comments on commit f4f1587

Please sign in to comment.