Skip to content

Instantly share code, notes, and snippets.

@lukleh
Last active March 14, 2018 11:34
Show Gist options
  • Save lukleh/03ec5de6730afc3e0240 to your computer and use it in GitHub Desktop.
Save lukleh/03ec5de6730afc3e0240 to your computer and use it in GitHub Desktop.
__version__ = "0.1.6.8"
if __name__ == "__main__":
import sys
import argparse
def increment_line(args):
vi = [int(i) for i in __version__.split('.')]
print('current version: %s' % __version__)
if len(vi) == 3:
vi.append(0)
if args.M:
vi[0] += 1
vi[1] = 0
vi[2] = 0
vi[3] = 0
elif args.m:
vi[1] += 1
vi[2] = 0
vi[3] = 0
elif args.p:
vi[2] += 1
vi[3] = 0
elif args.b:
vi[3] += 1
vs = [str(i) for i in vi]
nv = '.'.join(vs)
print('new version: %s' % nv)
return '__version__ = "%s"\n' % nv
thisfile = sys.modules[__name__].__file__
with open(thisfile, 'r') as f:
lines = f.readlines()
parser = argparse.ArgumentParser()
parser.add_argument("-M", action='store_true', help="increment major X.0.0.0")
parser.add_argument("-m", action='store_true', help="increment minor 0.X.0.0")
parser.add_argument("-p", action='store_true', help="increment patch 0.0.X.0")
parser.add_argument("-b", action='store_true', help="increment build 0.0.0.X")
args = parser.parse_args()
if not any(vars(args).values()):
parser.print_help()
exit()
lines[0] = increment_line(args)
with open(thisfile, 'w') as f:
f.write(''.join(lines))
@lukleh
Copy link
Author

lukleh commented Mar 20, 2016

very quick and dirty hack, but works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment