From 56bc3418919a34bc1da5bb2cebbf48fc1d842139 Mon Sep 17 00:00:00 2001 From: DetachHead <57028336+DetachHead@users.noreply.github.com> Date: Thu, 4 Apr 2024 18:15:37 +1000 Subject: [PATCH 1/8] use `Literal` type for valid target values --- src/pdm/backend/base.py | 6 ++++-- src/pdm/backend/hooks/base.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pdm/backend/base.py b/src/pdm/backend/base.py index 0487f43..e6a7fb4 100644 --- a/src/pdm/backend/base.py +++ b/src/pdm/backend/base.py @@ -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 @@ -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__( diff --git a/src/pdm/backend/hooks/base.py b/src/pdm/backend/hooks/base.py index 1eaff20..6d64f92 100644 --- a/src/pdm/backend/hooks/base.py +++ b/src/pdm/backend/hooks/base.py @@ -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 @@ -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 From a567f5f24445669f90c3d3fda89880c2794f115a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 4 Apr 2024 08:16:39 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pdm/backend/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pdm/backend/base.py b/src/pdm/backend/base.py index e6a7fb4..ef6be53 100644 --- a/src/pdm/backend/base.py +++ b/src/pdm/backend/base.py @@ -83,6 +83,7 @@ def _find_top_packages(root: str) -> list[str]: Target: TypeAlias = Literal["sdist", "wheel", "editable"] + class Builder: """Base class for building and distributing a package from given path.""" From 6390b95784494324ffbcde9f508aad5bc1622466 Mon Sep 17 00:00:00 2001 From: DetachHead <57028336+DetachHead@users.noreply.github.com> Date: Thu, 4 Apr 2024 19:35:21 +1000 Subject: [PATCH 3/8] fix missing import --- src/pdm/backend/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pdm/backend/base.py b/src/pdm/backend/base.py index ef6be53..f68be38 100644 --- a/src/pdm/backend/base.py +++ b/src/pdm/backend/base.py @@ -7,7 +7,7 @@ import warnings from fnmatch import fnmatch from pathlib import Path -from typing import TYPE_CHECKING, Any, Iterable, Mapping, TypeAlias, TypeVar, cast +from typing import TYPE_CHECKING, Any, Iterable, Literal, Mapping, TypeAlias, TypeVar, cast from pdm.backend.config import Config from pdm.backend.exceptions import PDMWarning, ValidationError From 86763e7488710397d550cf227c5ca7ceec286e7b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 4 Apr 2024 09:36:46 +0000 Subject: [PATCH 4/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pdm/backend/base.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pdm/backend/base.py b/src/pdm/backend/base.py index f68be38..fa3b925 100644 --- a/src/pdm/backend/base.py +++ b/src/pdm/backend/base.py @@ -7,7 +7,16 @@ import warnings from fnmatch import fnmatch from pathlib import Path -from typing import TYPE_CHECKING, Any, Iterable, Literal, Mapping, TypeAlias, TypeVar, cast +from typing import ( + TYPE_CHECKING, + Any, + Iterable, + Literal, + Mapping, + TypeAlias, + TypeVar, + cast, +) from pdm.backend.config import Config from pdm.backend.exceptions import PDMWarning, ValidationError From cb07df192a2f3ea39a1c8074b33d318671ba93d2 Mon Sep 17 00:00:00 2001 From: DetachHead <57028336+DetachHead@users.noreply.github.com> Date: Thu, 4 Apr 2024 19:42:56 +1000 Subject: [PATCH 5/8] remove `TypeAlias` import since it's not needed and doesn't exist on older python versions --- src/pdm/backend/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pdm/backend/base.py b/src/pdm/backend/base.py index fa3b925..7a18082 100644 --- a/src/pdm/backend/base.py +++ b/src/pdm/backend/base.py @@ -13,7 +13,6 @@ Iterable, Literal, Mapping, - TypeAlias, TypeVar, cast, ) @@ -90,7 +89,7 @@ def _find_top_packages(root: str) -> list[str]: return result -Target: TypeAlias = Literal["sdist", "wheel", "editable"] +Target = Literal["sdist", "wheel", "editable"] class Builder: From 4a66d3041c84d1c88599b1433259acb7b963deb8 Mon Sep 17 00:00:00 2001 From: DetachHead <57028336+DetachHead@users.noreply.github.com> Date: Thu, 4 Apr 2024 19:52:08 +1000 Subject: [PATCH 6/8] use `typeing_extensions.Literal` for python 3.7 --- src/pdm/backend/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pdm/backend/base.py b/src/pdm/backend/base.py index 7a18082..ac35544 100644 --- a/src/pdm/backend/base.py +++ b/src/pdm/backend/base.py @@ -11,11 +11,11 @@ TYPE_CHECKING, Any, Iterable, - Literal, Mapping, TypeVar, cast, ) +from typing_extensions import Literal from pdm.backend.config import Config from pdm.backend.exceptions import PDMWarning, ValidationError From 0d8d1d25269769893a5b5a6d19d2b1c9f2510b40 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 4 Apr 2024 09:53:18 +0000 Subject: [PATCH 7/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pdm/backend/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pdm/backend/base.py b/src/pdm/backend/base.py index ac35544..cc164b2 100644 --- a/src/pdm/backend/base.py +++ b/src/pdm/backend/base.py @@ -15,6 +15,7 @@ TypeVar, cast, ) + from typing_extensions import Literal from pdm.backend.config import Config From e83ff3109b99d48df77aba3b0225ce484f528391 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Thu, 18 Apr 2024 15:32:31 +0800 Subject: [PATCH 8/8] Update src/pdm/backend/base.py --- src/pdm/backend/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pdm/backend/base.py b/src/pdm/backend/base.py index cc164b2..7a18082 100644 --- a/src/pdm/backend/base.py +++ b/src/pdm/backend/base.py @@ -11,13 +11,12 @@ TYPE_CHECKING, Any, Iterable, + Literal, Mapping, TypeVar, cast, ) -from typing_extensions import Literal - from pdm.backend.config import Config from pdm.backend.exceptions import PDMWarning, ValidationError from pdm.backend.hooks import BuildHookInterface, Context