Skip to content

Commit 34f18e8

Browse files
committed
feat(pypi): allow dirty workspace, recreat setup.py, check return codes
1 parent 56249be commit 34f18e8

1 file changed

Lines changed: 39 additions & 21 deletions

File tree

clit/dev.py

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class PyPICommands:
119119
"""Commands executed by this helper script."""
120120

121121
# https://github.com/peritus/bumpversion
122-
BUMP_VERSION = "bumpversion {part}"
122+
BUMP_VERSION = "bumpversion {allow_dirty} {part}"
123123
BUMP_VERSION_DRY_RUN = f"{BUMP_VERSION} --dry-run --verbose"
124124

125125
# https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-cli
@@ -130,8 +130,7 @@ class PyPICommands:
130130
# https://poetry.eustace.io/
131131
BUILD_POETRY = "poetry build"
132132

133-
GIT_ADD = "git add ."
134-
GIT_COMMIT = "git commit -m'{}'"
133+
GIT_ADD_AND_COMMIT = "git add . && git commit -m'{}' --no-verify"
135134
GIT_PUSH = "git push"
136135
GIT_TAG = "git tag v{}"
137136

@@ -151,10 +150,24 @@ def pypi():
151150

152151

153152
@pypi.command()
154-
@click.option("--part", default="minor", type=click.Choice(["major", "minor", "patch"]))
155-
def full(part):
153+
@click.option(
154+
"--part",
155+
"-p",
156+
default="minor",
157+
type=click.Choice(["major", "minor", "patch"]),
158+
help="Which part of the version number to bump",
159+
)
160+
@click.option(
161+
"--allow-dirty", "-d", default=False, is_flag=True, type=bool, help="Allow bumpversion to run on a dirty repo"
162+
)
163+
@click.pass_context
164+
def full(ctx, part, allow_dirty: bool):
156165
"""The full process to upload to PyPI (bump version, changelog, package, upload)."""
157-
bump_dry_run_cmd = PyPICommands.BUMP_VERSION_DRY_RUN.format(part=part)
166+
# Recreate the setup.py
167+
ctx.invoke(setup_py)
168+
169+
allow_dirty_option = "--allow-dirty" if allow_dirty else ""
170+
bump_dry_run_cmd = PyPICommands.BUMP_VERSION_DRY_RUN.format(allow_dirty=allow_dirty_option, part=part)
158171
bump = shell(bump_dry_run_cmd)
159172
if bump.returncode != 0:
160173
exit(bump.returncode)
@@ -167,7 +180,7 @@ def full(part):
167180
print(f"New version: {new_version}\nCommit message: {commit_message}")
168181
prompt("Were all versions correctly bumped?")
169182

170-
shell(PyPICommands.BUMP_VERSION.format(part=part))
183+
shell(PyPICommands.BUMP_VERSION.format(allow_dirty=allow_dirty_option, part=part))
171184
shell(f"{PyPICommands.CHANGELOG} -s")
172185

173186
try:
@@ -185,24 +198,28 @@ def full(part):
185198
prompt("Is the git diff correct?")
186199

187200
prompt(
188-
"Last confirmation (point of no return):"
201+
"Last confirmation (point of no return):\n"
189202
+ "Changes will be committed, files will be uploaded to PyPI, a GitHub release will be created"
190203
)
191204

192-
print("Add files, commit and push")
193-
for command in (PyPICommands.GIT_ADD, PyPICommands.GIT_COMMIT.format(commit_message), PyPICommands.GIT_PUSH):
194-
shell(command)
195-
196-
print("Create the tag but don't push it yet (conventional-github-releaser will do that)")
197-
shell(PyPICommands.GIT_TAG.format(new_version))
198-
199-
print("Upload the files to PyPI via Twine")
200-
shell(PyPICommands.TWINE_UPLOAD)
201-
202-
print("Create a GitHub release")
203-
shell(PyPICommands.GITHUB_RELEASE)
205+
commands = (
206+
("Add all files and commit (skipping hooks)", PyPICommands.GIT_ADD_AND_COMMIT.format(commit_message)),
207+
("Push", PyPICommands.GIT_PUSH),
208+
(
209+
"Create the tag but don't push it yet (conventional-github-releaser will do that)",
210+
PyPICommands.GIT_TAG.format(new_version),
211+
),
212+
("Upload the files to PyPI via Twine", PyPICommands.TWINE_UPLOAD),
213+
("Create a GitHub release", PyPICommands.GITHUB_RELEASE),
214+
)
215+
for header, command in commands:
216+
while True:
217+
click.secho(f"\n>>> {header}", fg="bright_white")
218+
if shell(command).returncode == 0:
219+
break
220+
prompt("Something went wrong, running the same command again.", fg="red")
204221

205-
print(f"The new version {new_version} was uploaded to PyPI")
222+
click.secho(f"The new version {new_version} was uploaded to PyPI! ✨ 🍰 ✨", fg="bright_white")
206223

207224

208225
@pypi.command()
@@ -220,6 +237,7 @@ def extra_poetry():
220237
@extra_poetry.command()
221238
def setup_py():
222239
"""Use poetry to generate a setup.py file from pyproject.toml."""
240+
rmtree("./dist")
223241
shell("poetry build")
224242
shell("tar -xvzf dist/*.gz --strip-components 1 */setup.py")
225243
shell("black setup.py")

0 commit comments

Comments
 (0)