Skip to content

Commit

Permalink
use Literal type for valid target values
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead authored Apr 4, 2024
1 parent feb9fc7 commit 56bc341
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/pdm/backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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, Mapping, TypeAlias, TypeVar, cast

from pdm.backend.config import Config
from pdm.backend.exceptions import PDMWarning, ValidationError
Expand Down Expand Up @@ -81,12 +81,14 @@ 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

0 comments on commit 56bc341

Please sign in to comment.