Skip to content

Commit

Permalink
WIP: prepare dry run
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed Apr 19, 2021
1 parent eaa741c commit 93d631d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Changelog
=========

- :feature:`-` ``packaging.release.prepare`` grew a ``dry_run`` flag to match
the rest of its friends.
- :bug:`- major` ``packaging.release.prepare`` now generates annotated Git tags
instead of lightweight ones. This was a perplexing oversight (Git has always
intended annotated tags to be used for release purposes) so we're considering
Expand Down
34 changes: 24 additions & 10 deletions invocations/packaging/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,24 @@ def all_(c, dry_run=False):
.. versionchanged:: 2.1
Added the ``dry_run`` flag.
"""
prepare(c)
prepare(c, dry_run=dry_run)
publish(c, dry_run=dry_run)
push(c, dry_run=dry_run)


@task
def prepare(c):
def prepare(c, dry_run=False):
"""
Edit changelog & version, git commit, and git tag, to set up for release.
:param bool dry_run:
Whether to take any actual actions or just say what might occur.
Default: ``False``.
.. versionchanged:: 2.1
Added the ``dry_run`` parameter.
.. versionchanged:: 2.1
Generate annotated git tags instead of lightweight ones.
"""
# Print dry-run/status/actions-to-take data & grab programmatic result
# TODO: maybe expand the enum-based stuff to have values that split up
Expand All @@ -293,8 +302,9 @@ def prepare(c):
# transmitted from status() into here...
actions, state = status(c)
# TODO: unless nothing-to-do in which case just say that & exit 0
if not confirm("Take the above actions?"):
raise Exit("Aborting.")
if not dry_run:
if not confirm("Take the above actions?"):
raise Exit("Aborting.")

# TODO: factor out what it means to edit a file:
# - $EDITOR or explicit expansion of it in case no shell involved
Expand All @@ -306,15 +316,15 @@ def prepare(c):
# TODO: identify top of list and inject a ready-made line? Requires vim
# assumption...GREAT opportunity for class/method based tasks!
cmd = "$EDITOR {.packaging.changelog_file}".format(c)
c.run(cmd, pty=True, hide=False)
c.run(cmd, pty=True, hide=False, dry=dry_run)
# Version file!
if actions.version == VersionFile.NEEDS_BUMP:
version_file = os.path.join(
_find_package(c),
c.packaging.get("version_module", "_version") + ".py",
)
cmd = "$EDITOR {}".format(version_file)
c.run(cmd, pty=True, hide=False)
c.run(cmd, pty=True, hide=False, dry=dry_run)
if actions.tag == Tag.NEEDS_CUTTING:
# Commit, if necessary, so the tag includes everything.
# NOTE: this strips out untracked files. effort.
Expand All @@ -323,11 +333,15 @@ def prepare(c):
c.run(
'git commit -am "Cut {}"'.format(state.expected_version),
hide=False,
dry=dry_run,
)
# Tag!
c.run("git tag -a {}".format(state.expected_version), hide=False)
# TODO: print something to clarify/confirm tag was cut, if not just
# adding echo=True to above
c.run(
'git tag -a {} -m ""'.format(state.expected_version),
hide=False,
dry=dry_run,
echo=True,
)


def _release_line(c):
Expand Down Expand Up @@ -799,7 +813,7 @@ def push(c, dry_run=False):
Push current branch and tags to default Git remote.
"""
kwargs = dict(echo=True) if dry_run else dict()
opts = " --dry-run" if dry_run else ""
opts = " --dry-run --no-verify" if dry_run else ""
c.run("git push --follow-tags{}".format(opts), **kwargs)


Expand Down
2 changes: 1 addition & 1 deletion tests/packaging/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def commits_and_adds_git_tag_when_needs_cutting(self, _):
check = 'git status --porcelain | egrep -v "^\\?"'
c.run.assert_any_call(check, hide=True, warn=True)
commit = 'git commit -am "Cut {}"'.format(version)
tag = "git tag -a {}".format(version)
tag = 'git tag -a {} -m ""'.format(version)
for cmd in (commit, tag):
c.run.assert_any_call(cmd, hide=False)

Expand Down

0 comments on commit 93d631d

Please sign in to comment.