Skip to content

Commit

Permalink
chore: use Literal type for valid target values (#227)
Browse files Browse the repository at this point in the history
* use `Literal` type for valid target values

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix missing import

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove `TypeAlias` import since it's not needed and doesn't exist on older python versions

* use `typeing_extensions.Literal` for python 3.7

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update src/pdm/backend/base.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Frost Ming <[email protected]>
  • Loading branch information
3 people authored Apr 18, 2024
1 parent 32e3a33 commit a210b72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/pdm/backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
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,
TypeVar,
cast,
)

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


Target = 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 a210b72

Please sign in to comment.