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

use Literal type for valid target values #227

Merged
merged 8 commits into from
Apr 18, 2024
16 changes: 14 additions & 2 deletions src/pdm/backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@
import warnings
from fnmatch import fnmatch
from pathlib import Path
from typing import TYPE_CHECKING, Any, Iterable, Mapping, TypeVar, cast
from typing import (
TYPE_CHECKING,
Any,
Iterable,
Literal,
Mapping,
TypeAlias,
DetachHead marked this conversation as resolved.
Show resolved Hide resolved
TypeVar,
cast,
)

from pdm.backend.config import Config
from pdm.backend.exceptions import PDMWarning, ValidationError
Expand Down Expand Up @@ -81,12 +90,15 @@ def _find_top_packages(root: str) -> list[str]:
return result


Target: TypeAlias = Literal["sdist", "wheel", "editable"]


class Builder:
"""Base class for building and distributing a package from given path."""

DEFAULT_EXCLUDES = [".pdm-build"]

target: str
target: Target
hooks: list[BuildHookInterface] = [DynamicVersionBuildHook()]

def __init__(
Expand Down
4 changes: 2 additions & 2 deletions src/pdm/backend/hooks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
if TYPE_CHECKING:
from typing import Protocol

from pdm.backend.base import Builder
from pdm.backend.base import Builder, Target
else:
Protocol = object

Expand Down Expand Up @@ -44,7 +44,7 @@ def root(self) -> Path:
return self.builder.location

@property
def target(self) -> str:
def target(self) -> Target:
"""The target to build, one of 'sdist', 'wheel', 'editable'"""
return self.builder.target

Expand Down
Loading