tablish 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tablish/__init__.py +87 -0
- tablish/__main__.py +8 -0
- tablish/cli.py +266 -0
- tablish/config.py +418 -0
- tablish/py.typed +0 -0
- tablish/release.py +904 -0
- tablish/t.py +38 -0
- tablish-1.0.0.dist-info/METADATA +132 -0
- tablish-1.0.0.dist-info/RECORD +13 -0
- tablish-1.0.0.dist-info/WHEEL +5 -0
- tablish-1.0.0.dist-info/entry_points.txt +2 -0
- tablish-1.0.0.dist-info/licenses/LICENSE +21 -0
- tablish-1.0.0.dist-info/top_level.txt +1 -0
tablish/__init__.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Release automation CLI for publishing Python packages to PyPI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .cli import (
|
|
6
|
+
formatReleaseMetadata as formatReleaseMetadata,
|
|
7
|
+
main as main,
|
|
8
|
+
parseArgs as parseArgs,
|
|
9
|
+
supportsColor as supportsColor,
|
|
10
|
+
)
|
|
11
|
+
from .config import (
|
|
12
|
+
DEFAULT_BUILD_DIRS as DEFAULT_BUILD_DIRS,
|
|
13
|
+
DEFAULT_CHECK_MANIFEST_ARGS as DEFAULT_CHECK_MANIFEST_ARGS,
|
|
14
|
+
DEFAULT_COMMIT_MESSAGE as DEFAULT_COMMIT_MESSAGE,
|
|
15
|
+
DEFAULT_PYPI_SECRET_KEY as DEFAULT_PYPI_SECRET_KEY,
|
|
16
|
+
DEFAULT_SECRETS_FILE as DEFAULT_SECRETS_FILE,
|
|
17
|
+
DEFAULT_SEMVER_FILE as DEFAULT_SEMVER_FILE,
|
|
18
|
+
DEFAULT_TAG_FORMAT as DEFAULT_TAG_FORMAT,
|
|
19
|
+
DEFAULT_TAG_MESSAGE as DEFAULT_TAG_MESSAGE,
|
|
20
|
+
DEFAULT_TEST_PYPI_SECRET_KEY as DEFAULT_TEST_PYPI_SECRET_KEY,
|
|
21
|
+
DEFAULT_TEST_PYPI_URL as DEFAULT_TEST_PYPI_URL,
|
|
22
|
+
GeneratedFileConfig as GeneratedFileConfig,
|
|
23
|
+
ReleaseError as ReleaseError,
|
|
24
|
+
TablishConfig as TablishConfig,
|
|
25
|
+
loadConfig as loadConfig,
|
|
26
|
+
parseConfigData as parseConfigData,
|
|
27
|
+
)
|
|
28
|
+
from .release import (
|
|
29
|
+
MetadataItem as MetadataItem,
|
|
30
|
+
ReleaseMetadata as ReleaseMetadata,
|
|
31
|
+
ReleaseOptions as ReleaseOptions,
|
|
32
|
+
ReleaseResult as ReleaseResult,
|
|
33
|
+
bumpSemver as bumpSemver,
|
|
34
|
+
cleanBuildArtifacts as cleanBuildArtifacts,
|
|
35
|
+
collectReleaseMetadata as collectReleaseMetadata,
|
|
36
|
+
createRelease as createRelease,
|
|
37
|
+
ensureSecretsGitIgnored as ensureSecretsGitIgnored,
|
|
38
|
+
findToolCommand as findToolCommand,
|
|
39
|
+
getDirtyFiles as getDirtyFiles,
|
|
40
|
+
gitTagExists as gitTagExists,
|
|
41
|
+
inProjectRoot as inProjectRoot,
|
|
42
|
+
isGitIgnored as isGitIgnored,
|
|
43
|
+
loadPyPiToken as loadPyPiToken,
|
|
44
|
+
parseSemver as parseSemver,
|
|
45
|
+
resolveSecretsPath as resolveSecretsPath,
|
|
46
|
+
runCommand as runCommand,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
"DEFAULT_BUILD_DIRS",
|
|
51
|
+
"DEFAULT_CHECK_MANIFEST_ARGS",
|
|
52
|
+
"DEFAULT_COMMIT_MESSAGE",
|
|
53
|
+
"DEFAULT_PYPI_SECRET_KEY",
|
|
54
|
+
"DEFAULT_SECRETS_FILE",
|
|
55
|
+
"DEFAULT_SEMVER_FILE",
|
|
56
|
+
"DEFAULT_TAG_FORMAT",
|
|
57
|
+
"DEFAULT_TAG_MESSAGE",
|
|
58
|
+
"DEFAULT_TEST_PYPI_SECRET_KEY",
|
|
59
|
+
"DEFAULT_TEST_PYPI_URL",
|
|
60
|
+
"GeneratedFileConfig",
|
|
61
|
+
"MetadataItem",
|
|
62
|
+
"ReleaseError",
|
|
63
|
+
"ReleaseMetadata",
|
|
64
|
+
"ReleaseOptions",
|
|
65
|
+
"ReleaseResult",
|
|
66
|
+
"TablishConfig",
|
|
67
|
+
"bumpSemver",
|
|
68
|
+
"cleanBuildArtifacts",
|
|
69
|
+
"collectReleaseMetadata",
|
|
70
|
+
"createRelease",
|
|
71
|
+
"ensureSecretsGitIgnored",
|
|
72
|
+
"findToolCommand",
|
|
73
|
+
"formatReleaseMetadata",
|
|
74
|
+
"getDirtyFiles",
|
|
75
|
+
"gitTagExists",
|
|
76
|
+
"inProjectRoot",
|
|
77
|
+
"isGitIgnored",
|
|
78
|
+
"loadConfig",
|
|
79
|
+
"loadPyPiToken",
|
|
80
|
+
"main",
|
|
81
|
+
"parseArgs",
|
|
82
|
+
"parseConfigData",
|
|
83
|
+
"parseSemver",
|
|
84
|
+
"resolveSecretsPath",
|
|
85
|
+
"runCommand",
|
|
86
|
+
"supportsColor",
|
|
87
|
+
]
|
tablish/__main__.py
ADDED
tablish/cli.py
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"""Command-line interface for tablish."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import importlib.metadata
|
|
7
|
+
import os
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from . import t
|
|
13
|
+
from .config import ReleaseError
|
|
14
|
+
from .release import (
|
|
15
|
+
MetadataItem,
|
|
16
|
+
ReleaseMetadata,
|
|
17
|
+
ReleaseOptions,
|
|
18
|
+
collectReleaseMetadata,
|
|
19
|
+
createRelease,
|
|
20
|
+
parseSemver,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
_BUMP_TYPES: t.Final[dict[str, t.BumpType]] = {
|
|
24
|
+
"break": "break",
|
|
25
|
+
"major": "major",
|
|
26
|
+
"feature": "feature",
|
|
27
|
+
"minor": "minor",
|
|
28
|
+
"bugfix": "bugfix",
|
|
29
|
+
"patch": "patch",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
_ANSI_RESET: t.Final[str] = "\033[0m"
|
|
33
|
+
_ANSI_BOLD: t.Final[str] = "\033[1m"
|
|
34
|
+
_ANSI_DIM: t.Final[str] = "\033[2m"
|
|
35
|
+
_ANSI_RED_BOLD: t.Final[str] = "\033[1;31m"
|
|
36
|
+
_ANSI_GREEN: t.Final[str] = "\033[32m"
|
|
37
|
+
_ANSI_GREEN_BOLD: t.Final[str] = "\033[1;32m"
|
|
38
|
+
_ANSI_YELLOW: t.Final[str] = "\033[33m"
|
|
39
|
+
_ANSI_MAGENTA_BOLD: t.Final[str] = "\033[1;35m"
|
|
40
|
+
_ANSI_CYAN: t.Final[str] = "\033[36m"
|
|
41
|
+
_ANSI_CYAN_BOLD: t.Final[str] = "\033[1;36m"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def supportsColor(stream: t.SupportsIsatty | None = None) -> bool:
|
|
45
|
+
"""Return True if ANSI color output is supported for stream."""
|
|
46
|
+
if os.environ.get("NO_COLOR"):
|
|
47
|
+
return False
|
|
48
|
+
forceColor = os.environ.get("FORCE_COLOR") or os.environ.get("CLICOLOR_FORCE")
|
|
49
|
+
if forceColor and forceColor != "0":
|
|
50
|
+
return True
|
|
51
|
+
if os.environ.get("CLICOLOR") == "0":
|
|
52
|
+
return False
|
|
53
|
+
if os.environ.get("TERM", "") == "dumb":
|
|
54
|
+
return False
|
|
55
|
+
targetStream: t.SupportsIsatty = sys.stdout if stream is None else stream
|
|
56
|
+
try:
|
|
57
|
+
if not targetStream.isatty():
|
|
58
|
+
return False
|
|
59
|
+
except OSError:
|
|
60
|
+
return False
|
|
61
|
+
if sys.platform == "win32":
|
|
62
|
+
return (
|
|
63
|
+
any(key in os.environ for key in ("WT_SESSION", "ANSICON", "TERM"))
|
|
64
|
+
or os.environ.get("TERM_PROGRAM") == "vscode"
|
|
65
|
+
)
|
|
66
|
+
return True
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _paint(text: str, code: str, *, useColor: bool) -> str:
|
|
70
|
+
"""Wrap text in ANSI escape codes when useColor is enabled."""
|
|
71
|
+
if not useColor or not code:
|
|
72
|
+
return text
|
|
73
|
+
return f"{code}{text}{_ANSI_RESET}"
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _formatBadge(item: MetadataItem) -> tuple[str, str]:
|
|
77
|
+
"""Return (plainBadgeText, ansiColorCode) for a metadata item's provenance or status."""
|
|
78
|
+
if item.source == "explicit":
|
|
79
|
+
return ("[explicit]", _ANSI_GREEN_BOLD)
|
|
80
|
+
if item.source == "cli":
|
|
81
|
+
label = f"[cli: {item.sourceDetail}]" if item.sourceDetail else "[cli]"
|
|
82
|
+
return (label, _ANSI_MAGENTA_BOLD)
|
|
83
|
+
if item.source == "inferred":
|
|
84
|
+
label = f"[default: {item.sourceDetail}]" if item.sourceDetail else "[default]"
|
|
85
|
+
return (label, _ANSI_CYAN)
|
|
86
|
+
if item.source == "default":
|
|
87
|
+
label = f"[default: {item.sourceDetail}]" if item.sourceDetail else "[default]"
|
|
88
|
+
return (label, _ANSI_DIM)
|
|
89
|
+
if item.status == "error":
|
|
90
|
+
label = f"[error: {item.sourceDetail}]" if item.sourceDetail else "[error]"
|
|
91
|
+
return (label, _ANSI_RED_BOLD)
|
|
92
|
+
if item.status == "warning":
|
|
93
|
+
label = f"[warning: {item.sourceDetail}]" if item.sourceDetail else "[warning]"
|
|
94
|
+
return (label, _ANSI_YELLOW)
|
|
95
|
+
if item.status == "ok":
|
|
96
|
+
label = f"[ok: {item.sourceDetail}]" if item.sourceDetail else "[ok]"
|
|
97
|
+
return (label, _ANSI_GREEN)
|
|
98
|
+
if item.sourceDetail:
|
|
99
|
+
return (f"[{item.sourceDetail}]", _ANSI_CYAN)
|
|
100
|
+
return ("", "")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def formatReleaseMetadata(metadata: ReleaseMetadata, *, useColor: bool = False) -> str:
|
|
104
|
+
"""Format resolved publish metadata into aligned, optionally colored sections."""
|
|
105
|
+
keyWidth = max((len(item.key) for item in metadata.items), default=0) + 2
|
|
106
|
+
valueWidth = 38
|
|
107
|
+
|
|
108
|
+
lines: list[str] = []
|
|
109
|
+
currentSection: str | None = None
|
|
110
|
+
for item in metadata.items:
|
|
111
|
+
if item.section != currentSection:
|
|
112
|
+
if currentSection is not None:
|
|
113
|
+
lines.append("")
|
|
114
|
+
lines.append(_paint(item.section, _ANSI_CYAN_BOLD, useColor=useColor))
|
|
115
|
+
currentSection = item.section
|
|
116
|
+
|
|
117
|
+
paddedKey = item.key.ljust(keyWidth)
|
|
118
|
+
if item.source in ("explicit", "cli"):
|
|
119
|
+
styledKey = _paint(paddedKey, _ANSI_BOLD, useColor=useColor)
|
|
120
|
+
else:
|
|
121
|
+
styledKey = paddedKey
|
|
122
|
+
|
|
123
|
+
valueColor = ""
|
|
124
|
+
if item.status == "error":
|
|
125
|
+
valueColor = _ANSI_RED_BOLD
|
|
126
|
+
elif item.status == "warning":
|
|
127
|
+
valueColor = _ANSI_YELLOW
|
|
128
|
+
|
|
129
|
+
badgeText, badgeColor = _formatBadge(item)
|
|
130
|
+
if badgeText:
|
|
131
|
+
padSpaces = max(2, valueWidth - len(item.value))
|
|
132
|
+
styledValue = _paint(item.value, valueColor, useColor=useColor)
|
|
133
|
+
styledBadge = _paint(badgeText, badgeColor, useColor=useColor)
|
|
134
|
+
lines.append(f" {styledKey}{styledValue}{' ' * padSpaces}{styledBadge}")
|
|
135
|
+
else:
|
|
136
|
+
styledValue = _paint(item.value, valueColor, useColor=useColor)
|
|
137
|
+
lines.append(f" {styledKey}{styledValue}")
|
|
138
|
+
|
|
139
|
+
for detail in item.details:
|
|
140
|
+
lines.append(f" {' ' * keyWidth}- {detail}")
|
|
141
|
+
|
|
142
|
+
return "\n".join(lines)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _getPackageVersion() -> str:
|
|
146
|
+
"""Return the installed tablish package version, or fallback to semver.txt."""
|
|
147
|
+
try:
|
|
148
|
+
return importlib.metadata.version("tablish")
|
|
149
|
+
except importlib.metadata.PackageNotFoundError:
|
|
150
|
+
semverFile = Path(__file__).resolve().parent.parent / "semver.txt"
|
|
151
|
+
if semverFile.is_file():
|
|
152
|
+
return semverFile.read_text(encoding="utf-8").strip()
|
|
153
|
+
return "0.0.0"
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _buildArgParser() -> argparse.ArgumentParser:
|
|
157
|
+
"""Create the CLI argument parser for tablish."""
|
|
158
|
+
parser = argparse.ArgumentParser(
|
|
159
|
+
prog="tablish",
|
|
160
|
+
description="Release a Python project to PyPI using [tool.tablish] in pyproject.toml.",
|
|
161
|
+
)
|
|
162
|
+
parser.add_argument(
|
|
163
|
+
"target",
|
|
164
|
+
metavar="{break,feature,bugfix,major,minor,patch,MAJOR.MINOR.PATCH,info}",
|
|
165
|
+
help=(
|
|
166
|
+
"Bump type (break/major, feature/minor, bugfix/patch), explicit MAJOR.MINOR.PATCH version, "
|
|
167
|
+
+ "or 'info' to print publish metadata."
|
|
168
|
+
),
|
|
169
|
+
)
|
|
170
|
+
parser.add_argument(
|
|
171
|
+
"--test",
|
|
172
|
+
dest="test",
|
|
173
|
+
action="store_true",
|
|
174
|
+
help="Upload to test.pypi.org instead (rolls back version files and skips git commit/tag/push).",
|
|
175
|
+
)
|
|
176
|
+
parser.add_argument(
|
|
177
|
+
"--dry-run",
|
|
178
|
+
dest="dry_run",
|
|
179
|
+
action="store_true",
|
|
180
|
+
help="Run checks and build/validate artifacts without uploading or pushing to git.",
|
|
181
|
+
)
|
|
182
|
+
parser.add_argument(
|
|
183
|
+
"--skip-lint",
|
|
184
|
+
dest="skip_lint",
|
|
185
|
+
action="store_true",
|
|
186
|
+
help="Skip running the configured lint command before building (still runs check-manifest if enabled).",
|
|
187
|
+
)
|
|
188
|
+
parser.add_argument(
|
|
189
|
+
"--no-tag",
|
|
190
|
+
dest="no_tag",
|
|
191
|
+
action="store_true",
|
|
192
|
+
help="Skip creating and pushing the git release tag.",
|
|
193
|
+
)
|
|
194
|
+
parser.add_argument(
|
|
195
|
+
"--verbose-pypi",
|
|
196
|
+
dest="verbose_pypi",
|
|
197
|
+
action="store_true",
|
|
198
|
+
help="Pass --verbose to `twine upload` for full PyPI responses and error messages.",
|
|
199
|
+
)
|
|
200
|
+
parser.add_argument(
|
|
201
|
+
"-C",
|
|
202
|
+
"--project-dir",
|
|
203
|
+
dest="project_dir",
|
|
204
|
+
type=Path,
|
|
205
|
+
default=None,
|
|
206
|
+
help="Path to the target project root directory (defaults to current working directory).",
|
|
207
|
+
)
|
|
208
|
+
parser.add_argument(
|
|
209
|
+
"-V",
|
|
210
|
+
"--version",
|
|
211
|
+
action="version",
|
|
212
|
+
version=f"%(prog)s {_getPackageVersion()}",
|
|
213
|
+
)
|
|
214
|
+
return parser
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def parseArgs(argv: t.Sequence[str] | None = None) -> tuple[ReleaseOptions, Path | None]:
|
|
218
|
+
"""Parse CLI arguments into ReleaseOptions and an optional project directory."""
|
|
219
|
+
parser = _buildArgParser()
|
|
220
|
+
args = parser.parse_args(argv)
|
|
221
|
+
|
|
222
|
+
rawTarget: str = args.target
|
|
223
|
+
isInfo = rawTarget == "info"
|
|
224
|
+
bump: t.BumpType | None = None if isInfo else _BUMP_TYPES.get(rawTarget)
|
|
225
|
+
explicitVersion: t.Semver | None = None
|
|
226
|
+
if not isInfo and bump is None:
|
|
227
|
+
try:
|
|
228
|
+
explicitVersion = parseSemver(rawTarget)
|
|
229
|
+
except ReleaseError:
|
|
230
|
+
parser.error(
|
|
231
|
+
f"invalid release target {rawTarget!r}: expected 'break'/'major', "
|
|
232
|
+
+ "'feature'/'minor', 'bugfix'/'patch', a MAJOR.MINOR.PATCH version, or 'info'.",
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
options = ReleaseOptions(
|
|
236
|
+
bump=bump,
|
|
237
|
+
version=explicitVersion,
|
|
238
|
+
test=bool(args.test),
|
|
239
|
+
dryRun=bool(args.dry_run),
|
|
240
|
+
skipLint=bool(args.skip_lint),
|
|
241
|
+
noTag=bool(args.no_tag),
|
|
242
|
+
verbosePypi=bool(args.verbose_pypi),
|
|
243
|
+
info=isInfo,
|
|
244
|
+
)
|
|
245
|
+
return (options, args.project_dir)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def main(argv: t.Sequence[str] | None = None) -> int:
|
|
249
|
+
"""Entry point for the tablish CLI."""
|
|
250
|
+
try:
|
|
251
|
+
options, projectDir = parseArgs(argv)
|
|
252
|
+
if options.info:
|
|
253
|
+
metadata = collectReleaseMetadata(options, projectRoot=projectDir)
|
|
254
|
+
print(formatReleaseMetadata(metadata, useColor=supportsColor(sys.stdout)))
|
|
255
|
+
return 0
|
|
256
|
+
createRelease(options, projectRoot=projectDir, onMessage=print)
|
|
257
|
+
except ReleaseError as exc:
|
|
258
|
+
print(f"Error: {exc}", file=sys.stderr)
|
|
259
|
+
return 1
|
|
260
|
+
except subprocess.CalledProcessError as exc:
|
|
261
|
+
print(f"Error: Command failed with exit code {exc.returncode}.", file=sys.stderr)
|
|
262
|
+
return exc.returncode or 1
|
|
263
|
+
except KeyboardInterrupt:
|
|
264
|
+
print("\nRelease cancelled.", file=sys.stderr)
|
|
265
|
+
return 130
|
|
266
|
+
return 0
|