As part of committing recently made changes to GitHub you also have to commit the changed version.py file. Perhaps this is overly lazy, but I wrote a small Python script called bumpversion.py to save myself just a few keystrokes per commit. When I prepared the setup.py to submit this script to PyPI I discovered someone else already made a far more complicated bumpversion package, so I decided to name mine bumpversionsimple.
This script will search for a version.py file in the subdirectories of the current directory. It will read the version.py file and create a commit message when committing the changes. Note that when it finds multiple version.py files (unexpected in a project directory!) it will just print out an error, do nothing and exit.
Installation is simple:
pip install bumpversionsimple
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
#! /usr/bin/env python | |
import os | |
import sys | |
def main(): | |
versionfile = [os.path.join(root, x) for root, dirs, files in os.walk(os.getcwd()) for x in files if x == "version.py"] | |
if len(versionfile) == 1: | |
with open(versionfile[0]) as versionf: | |
version = versionf.read().split("\"")[1] | |
os.system("git commit -m 'bumping version to {}' {}".format(version, versionfile[0])) | |
else: | |
sys.exit("Found multiple occurences of version.py – doing nothing.") | |
if __name__ == '__main__': | |
main() |