|
20 | 20 | import sys
|
21 | 21 | import tempfile
|
22 | 22 | from contextlib import contextmanager
|
23 |
| -from typing import Any, Callable, Generator, Self |
| 23 | +from dataclasses import dataclass |
| 24 | +from pathlib import Path |
| 25 | +from typing import ( |
| 26 | + Any, |
| 27 | + Callable, |
| 28 | + Generator, |
| 29 | + Literal, |
| 30 | + Protocol, |
| 31 | + Self, |
| 32 | + overload, |
| 33 | +) |
24 | 34 |
|
25 | 35 | COMMASPACE = ", "
|
26 | 36 | SPACE = " "
|
27 | 37 | tag_cre = re.compile(r"(\d+)(?:\.(\d+)(?:\.(\d+))?)?(?:([ab]|rc)(\d+))?$")
|
28 | 38 |
|
29 | 39 |
|
30 |
| -# Ideas stolen from Mailman's release script, Lib/tokens.py and welease |
| 40 | +class ReleaseShelf(Protocol): |
| 41 | + def close(self) -> None: ... |
| 42 | + |
| 43 | + @overload |
| 44 | + def get(self, key: Literal["finished"], default: bool | None = None) -> bool: ... |
| 45 | + |
| 46 | + @overload |
| 47 | + def get( |
| 48 | + self, key: Literal["completed_tasks"], default: list[Task] | None = None |
| 49 | + ) -> list[Task]: ... |
| 50 | + |
| 51 | + @overload |
| 52 | + def get(self, key: Literal["gpg_key"], default: str | None = None) -> str: ... |
| 53 | + |
| 54 | + @overload |
| 55 | + def get(self, key: Literal["git_repo"], default: Path | None = None) -> Path: ... |
| 56 | + |
| 57 | + @overload |
| 58 | + def get(self, key: Literal["auth_info"], default: str | None = None) -> str: ... |
| 59 | + |
| 60 | + @overload |
| 61 | + def get(self, key: Literal["ssh_user"], default: str | None = None) -> str: ... |
| 62 | + |
| 63 | + @overload |
| 64 | + def get(self, key: Literal["sign_gpg"], default: bool | None = None) -> bool: ... |
| 65 | + |
| 66 | + @overload |
| 67 | + def get(self, key: Literal["release"], default: Tag | None = None) -> Tag: ... |
| 68 | + |
| 69 | + @overload |
| 70 | + def __getitem__(self, key: Literal["finished"]) -> bool: ... |
| 71 | + |
| 72 | + @overload |
| 73 | + def __getitem__(self, key: Literal["completed_tasks"]) -> list[Task]: ... |
| 74 | + |
| 75 | + @overload |
| 76 | + def __getitem__(self, key: Literal["gpg_key"]) -> str: ... |
| 77 | + |
| 78 | + @overload |
| 79 | + def __getitem__(self, key: Literal["git_repo"]) -> Path: ... |
| 80 | + |
| 81 | + @overload |
| 82 | + def __getitem__(self, key: Literal["auth_info"]) -> str: ... |
| 83 | + |
| 84 | + @overload |
| 85 | + def __getitem__(self, key: Literal["ssh_user"]) -> str: ... |
| 86 | + |
| 87 | + @overload |
| 88 | + def __getitem__(self, key: Literal["sign_gpg"]) -> bool: ... |
| 89 | + |
| 90 | + @overload |
| 91 | + def __getitem__(self, key: Literal["release"]) -> Tag: ... |
| 92 | + |
| 93 | + @overload |
| 94 | + def __setitem__(self, key: Literal["finished"], value: bool) -> None: ... |
| 95 | + |
| 96 | + @overload |
| 97 | + def __setitem__( |
| 98 | + self, key: Literal["completed_tasks"], value: list[Task] |
| 99 | + ) -> None: ... |
| 100 | + |
| 101 | + @overload |
| 102 | + def __setitem__(self, key: Literal["gpg_key"], value: str) -> None: ... |
| 103 | + |
| 104 | + @overload |
| 105 | + def __setitem__(self, key: Literal["git_repo"], value: Path) -> None: ... |
| 106 | + |
| 107 | + @overload |
| 108 | + def __setitem__(self, key: Literal["auth_info"], value: str) -> None: ... |
| 109 | + |
| 110 | + @overload |
| 111 | + def __setitem__(self, key: Literal["ssh_user"], value: str) -> None: ... |
| 112 | + |
| 113 | + @overload |
| 114 | + def __setitem__(self, key: Literal["sign_gpg"], value: bool) -> None: ... |
| 115 | + |
| 116 | + @overload |
| 117 | + def __setitem__(self, key: Literal["release"], value: Tag) -> None: ... |
| 118 | + |
| 119 | + |
| 120 | +@dataclass |
| 121 | +class Task: |
| 122 | + function: Callable[[ReleaseShelf], None] |
| 123 | + description: str |
| 124 | + |
| 125 | + def __call__(self, db: ReleaseShelf) -> Any: |
| 126 | + return getattr(self, "function")(db) |
31 | 127 |
|
32 | 128 |
|
33 | 129 | class Tag:
|
@@ -139,12 +235,8 @@ def run_cmd(
|
139 | 235 |
|
140 | 236 | readme_re = re.compile(r"This is Python version [23]\.\d").match
|
141 | 237 |
|
142 |
| -root = None |
143 |
| - |
144 | 238 |
|
145 | 239 | def chdir_to_repo_root() -> str:
|
146 |
| - global root |
147 |
| - |
148 | 240 | # find the root of the local CPython repo
|
149 | 241 | # note that we can't ask git, because we might
|
150 | 242 | # be in an exported directory tree!
|
|
0 commit comments