-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
329 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
"""Do the checks and tasks that have to happen after doing a release. | ||
""" | ||
from __future__ import unicode_literals | ||
|
||
import logging | ||
import sys | ||
|
||
from zest.releaser import baserelease | ||
from zest.releaser import utils | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
HISTORY_HEADER = '%(new_version)s (unreleased)' | ||
COMMIT_MSG = 'Bumped version for %(release)s release.' | ||
|
||
DATA = { | ||
# Documentation for self.data. You get runtime warnings when something is | ||
# in self.data that is not in this list. Embarrasment-driven | ||
# documentation! | ||
'workingdir': 'Original working directory', | ||
'reporoot': 'Root of the version control repository', | ||
'name': 'Name of the project being released', | ||
'new_version': 'New development version (so 1.1)', | ||
'commit_msg': 'Message template used when committing.', | ||
'headings': 'Extracted headings from the history file', | ||
'history_file': 'Filename of history/changelog file (when found)', | ||
'history_last_release': ( | ||
'Full text of all history entries of the current release'), | ||
'history_header': 'Header template used for 1st history header', | ||
'history_lines': 'List with all history file lines (when found)', | ||
'history_encoding': 'The detected encoding of the history file', | ||
'history_insert_line_here': ( | ||
'Line number where an extra changelog entry can be inserted.'), | ||
'original_version': 'Version before bump (e.g. 1.0.dev0)', | ||
'breaking': 'True if we handle a breaking (major) change', | ||
'feature': 'True if we handle a feature (minor) change', | ||
'release': 'Type of release: breaking, feature, normal', | ||
} | ||
|
||
|
||
class BumpVersion(baserelease.Basereleaser): | ||
"""Add a changelog entry. | ||
self.data holds data that can optionally be changed by plugins. | ||
""" | ||
|
||
def __init__(self, vcs=None, breaking=False, feature=False): | ||
baserelease.Basereleaser.__init__(self, vcs=vcs) | ||
# Prepare some defaults for potential overriding. | ||
if breaking: | ||
release = 'breaking' | ||
elif feature: | ||
release = 'feature' | ||
else: | ||
release = 'normal' | ||
self.data.update(dict( | ||
history_header=HISTORY_HEADER, | ||
breaking=breaking, | ||
feature=feature, | ||
release=release, | ||
commit_msg=COMMIT_MSG)) | ||
|
||
def prepare(self): | ||
"""Prepare self.data by asking about new dev version""" | ||
print('Checking version bump for {} release.'.format( | ||
self.data['release'])) | ||
if not utils.sanity_check(self.vcs): | ||
logger.critical("Sanity check failed.") | ||
sys.exit(1) | ||
self._grab_version(initial=True) | ||
self._grab_history() | ||
# Grab and set new version. | ||
self._grab_version() | ||
|
||
def execute(self): | ||
"""Make the changes and offer a commit""" | ||
self._change_header() | ||
self._write_version() | ||
self._write_history() | ||
self._diff_and_commit() | ||
|
||
def _grab_version(self, initial=False): | ||
"""Grab the version. | ||
When initial is False, ask the user for a non-development | ||
version. When initial is True, grab the current suggestion. | ||
""" | ||
original_version = self.vcs.version | ||
logger.debug("Extracted version: %s", original_version) | ||
if original_version is None: | ||
logger.critical('No version found.') | ||
sys.exit(1) | ||
suggestion = new_version = self.data.get('new_version') | ||
if not new_version: | ||
# Get a suggestion. | ||
breaking = self.data['breaking'] | ||
feature = self.data['feature'] | ||
# Compare the suggestion for the last tag with the current version. | ||
# The wanted version bump may already have been done. | ||
last_tag_version = utils.get_last_tag(self.vcs, allow_missing=True) | ||
if last_tag_version is None: | ||
print("No tag found. No version bump needed.") | ||
sys.exit(0) | ||
else: | ||
print("Last tag: {}".format(last_tag_version)) | ||
print("Current version: {}".format(original_version)) | ||
minimum_version = utils.suggest_version( | ||
last_tag_version, feature=feature, breaking=breaking) | ||
if minimum_version <= original_version: | ||
print("No version bump needed.") | ||
sys.exit(0) | ||
# A bump is needed. Get suggestion for next version. | ||
suggestion = utils.suggest_version( | ||
original_version, feature=feature, breaking=breaking) | ||
if not initial: | ||
new_version = utils.ask_version( | ||
"Enter version", default=suggestion) | ||
if not new_version: | ||
new_version = suggestion | ||
self.data['original_version'] = original_version | ||
self.data['new_version'] = new_version | ||
|
||
|
||
def datacheck(data): | ||
"""Entrypoint: ensure that the data dict is fully documented""" | ||
utils.is_data_documented(data, documentation=DATA) | ||
|
||
|
||
def main(): | ||
parser = utils.base_option_parser() | ||
parser.add_argument( | ||
"--feature", | ||
action="store_true", | ||
dest="feature", | ||
default=False, | ||
help="Bump for feature release (increase minor version)") | ||
parser.add_argument( | ||
"--breaking", | ||
action="store_true", | ||
dest="breaking", | ||
default=False, | ||
help="Bump for breaking release (increase major version)") | ||
options = utils.parse_options(parser) | ||
if options.breaking and options.feature: | ||
print('Cannot have both breaking and feature options.') | ||
sys.exit(1) | ||
utils.configure_logging() | ||
bumpversion = BumpVersion( | ||
breaking=options.breaking, feature=options.feature) | ||
bumpversion.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
Detailed tests of bumpversion.py | ||
================================ | ||
|
||
.. :doctest: | ||
.. :setup: zest.releaser.tests.functional.setup | ||
.. :teardown: zest.releaser.tests.functional.teardown | ||
|
||
Several items are prepared for us. | ||
|
||
An svn repository: | ||
|
||
>>> repo_url | ||
'file://TESTREPO' | ||
|
||
An svn checkout of a project: | ||
|
||
>>> svnsourcedir | ||
'TESTTEMP/tha.example-svn' | ||
>>> import os | ||
>>> import sys | ||
>>> os.chdir(svnsourcedir) | ||
|
||
Asking input on the prompt is not unittestable unless we use the prepared | ||
testing hack in utils.py: | ||
|
||
>>> from zest.releaser import utils | ||
>>> utils.TESTMODE = True | ||
|
||
Initially there are no tags, and we require them. In the tests the | ||
error is ugly, but in practice it looks fine, saying no bump is needed. | ||
|
||
>>> from zest.releaser import bumpversion | ||
>>> bumpversion.main() | ||
Traceback (most recent call last): | ||
... | ||
RuntimeError: SYSTEM EXIT (code=0) | ||
|
||
So first run the fullrelease: | ||
|
||
>>> from zest.releaser import fullrelease | ||
>>> utils.test_answer_book.set_answers(['', '', '', '2.3.4', '', '', '', '', '', '', '']) | ||
>>> fullrelease.main() | ||
Question... | ||
Question: Enter version [0.1]: | ||
Our reply: 2.3.4 | ||
... | ||
>>> svnhead('CHANGES.txt') | ||
Changelog of tha.example | ||
======================== | ||
<BLANKLINE> | ||
2.3.5 (unreleased) | ||
------------------ | ||
>>> svnhead('setup.py') | ||
from setuptools import setup, find_packages | ||
import os.path | ||
<BLANKLINE> | ||
version = '2.3.5.dev0' | ||
|
||
Try bumpversion again. The first time we again get an error because | ||
no version bump is needed: our current version is already higher than | ||
the latest tag, and we have no feature or breaking change. In the | ||
tests it is again ugly, but the exit code is zero, which is good. | ||
|
||
>>> utils.test_answer_book.set_answers(['', '', '', '', '', '']) | ||
>>> bumpversion.main() | ||
Traceback (most recent call last): | ||
... | ||
RuntimeError: SYSTEM EXIT (code=0) | ||
|
||
Now a feature bump:: | ||
|
||
>>> sys.argv[1:] = ['--feature'] | ||
>>> bumpversion.main() | ||
Checking version bump for feature release. | ||
Last tag: 2.3.4 | ||
Current version: 2.3.5.dev0 | ||
Question: Enter version [2.4.0.dev0]: | ||
Our reply: <ENTER> | ||
Checking data dict | ||
Question: OK to commit this (Y/n)? | ||
Our reply: <ENTER> | ||
|
||
Now a breaking bump:: | ||
|
||
>>> sys.argv[1:] = ['--breaking'] | ||
>>> bumpversion.main() | ||
Checking version bump for breaking release. | ||
Last tag: 2.3.4 | ||
Current version: 2.4.0.dev0 | ||
Question: Enter version [3.0.0.dev0]: | ||
Our reply: <ENTER> | ||
Checking data dict | ||
Question: OK to commit this (Y/n)? | ||
Our reply: <ENTER> |
Oops, something went wrong.