Last active
July 29, 2016 14:51
-
-
Save mattvonrocketstein/ac7c3fc1da4e696e58976324c414c72e to your computer and use it in GitHub Desktop.
version_bump fabfile
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
import os | |
from fabric import api | |
from fabric import colors | |
from fabric.contrib.console import confirm | |
_ope = os.path.exists | |
_mkdir = os.mkdir | |
_expanduser = os.path.expanduser | |
_dirname = os.path.dirname | |
PKG_NAME = 'my_pkg' | |
VERSION_DELTA = .01 | |
@api.task | |
def version_bump(): | |
""" bump the version number for """ + PKG_NAME | |
sandbox = {} | |
version_file = os.path.join(PKG_NAME, 'version.py') | |
err = 'version file not found in expected location: ' + version_file | |
assert os.path.exists(version_file), err | |
# running "import pkg.version" should have no side-effects, | |
# so there's little point in parsing the file. just exec | |
execfile(version_file, sandbox) | |
current_version = sandbox['__version__'] | |
new_version = current_version + VERSION_DELTA | |
with open(version_file, 'r') as fhandle: | |
version_file_contents = [x for x in fhandle.readlines() | |
if x.strip()] | |
new_file = version_file_contents[:-1] + \ | |
["__version__={0}".format(new_version)] | |
new_file = '\n'.join(new_file) | |
print colors.red("warning:") + \ | |
" version will be changed to {0}".format(new_version) | |
print colors.red("new version file will look like this:\n") | |
print new_file | |
ans = confirm('proceed with version change?') | |
if not ans: | |
print 'aborting.' | |
return | |
with open(version_file, 'w') as fhandle: | |
fhandle.write(new_file) | |
print 'version has been rewritten.' | |
bump_version = version_bump |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment