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

Add remaining Python type annotations to build backend #10434

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
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)
Loading