-
-
Save unpluggedcoder/7b4d39b16858f18b038ec18b9c5a1e27 to your computer and use it in GitHub Desktop.
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
__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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment