-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da2f4e6
commit daeda05
Showing
3 changed files
with
119 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import logging | ||
|
||
import semantic_version | ||
|
||
from changes import util, attributes | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def strip_long_arguments(arguments, long_keys): | ||
long_arguments = util.extract(arguments, long_keys) | ||
return dict([ | ||
(key[2:], value) for key, value in long_arguments.items() | ||
]) | ||
|
||
|
||
def extract_version_arguments(): | ||
return strip_long_arguments(['--major', '--minor', '--patch']) | ||
|
||
def increment(version, major=False, minor=False, patch=True): | ||
""" | ||
Increment a semantic version | ||
:param version: str of the version to increment | ||
:param major: bool specifying major level version increment | ||
:param minor: bool specifying minor level version increment | ||
:param patch: bool specifying patch level version increment | ||
:return: str of the incremented version | ||
""" | ||
version = semantic_version.Version(version) | ||
if major: | ||
version.major += 1 | ||
version.minor = 0 | ||
version.patch = 0 | ||
elif minor: | ||
version.minor += 1 | ||
version.patch = 0 | ||
elif patch: | ||
version.patch += 1 | ||
|
||
return str(version) | ||
|
||
|
||
def get_new_version(app_name, current_version, | ||
major=False, minor=False, patch=True): | ||
|
||
guess_new_version = increment( | ||
current_version, | ||
major=major, | ||
minor=minor, | ||
patch=patch | ||
) | ||
|
||
new_version = raw_input( | ||
'What is the release version for "%s" ' | ||
'[Default: %s]: ' % ( | ||
app_name, guess_new_version | ||
) | ||
) | ||
if not new_version: | ||
new_version = guess_new_version | ||
return new_version.strip() | ||
|
||
|
||
def current_version(app_name): | ||
return attributes.extract_attribute(app_name, '__version__') |
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,47 @@ | ||
from unittest2 import TestCase | ||
|
||
from changes import version | ||
from . import BaseTestCase | ||
|
||
class VersionTestCase(TestCase): | ||
|
||
def test_increment(self): | ||
self.assertEquals( | ||
'1.0.0', | ||
version.increment('0.0.1', major=True) | ||
) | ||
|
||
self.assertEquals( | ||
'0.1.0', | ||
version.increment('0.0.1', minor=True) | ||
) | ||
|
||
self.assertEquals( | ||
'1.0.1', | ||
version.increment('1.0.0', patch=True) | ||
) | ||
|
||
def test_strip_long_arguments(self): | ||
arguments = { | ||
'--major': True, | ||
'--minor': False, | ||
'--patch': False, | ||
} | ||
long_keys = ['--major', '--minor', '--patch'] | ||
expected = { | ||
'major': True, | ||
'minor': False, | ||
'patch': False, | ||
} | ||
self.assertEquals( | ||
expected, | ||
version.strip_long_arguments(arguments, long_keys) | ||
) | ||
|
||
class CurrentVersionTestCase(BaseTestCase): | ||
|
||
def test_current_version(self): | ||
self.assertEquals( | ||
'0.0.1', | ||
version.current_version(self.module_name) | ||
) |