diff --git a/dev/scripts/versionIncrease.py b/dev/scripts/versionIncrease.py index 6cebb17..b84a826 100644 --- a/dev/scripts/versionIncrease.py +++ b/dev/scripts/versionIncrease.py @@ -2,20 +2,36 @@ import os + +def nextVersionString(oldVersionString): + oldVersion = oldVersionString.split(".") + assert len(oldVersion) == 3 + oldVersion = [int(x) for x in oldVersion] + return "%d.%d.%d" % (oldVersion[0], oldVersion[1], oldVersion[2] + 1) + + def increaseVersion(fname): assert os.path.exists(fname) + with open(fname) as f: - oldVersionString = f.read().strip() - oldVersion = oldVersionString.split(".") - oldVersion = [int(x) for x in oldVersion] - newVersionString = "%d.%d.%d" % (oldVersion[0], oldVersion[1], oldVersion[2] + 1) + lines = f.read().split("\n") + + for i, line in enumerate(lines): + strippedLine = line.replace(" ", "") + if strippedLine.startswith("version=") or strippedLine.startswith("__version__="): + oldVersion = line.split("'")[1] + newVersion = nextVersionString(oldVersion) + print(f"{os.path.basename(fname)}\t{oldVersion} -> {newVersion}") + lines[i] = line.replace(oldVersion, newVersion) + with open(fname, 'w') as f: - f.write(newVersionString) - print(f"Upgraded: {oldVersionString} -> {newVersionString}") - return + f.write("\n".join(lines)) + + return newVersion if __name__ == "__main__": PATH_HERE = os.path.abspath(os.path.dirname(__file__)) - versionFile = os.path.abspath(PATH_HERE+"/../../src/pyabf/version.txt") - increaseVersion(versionFile) + setupVersion = increaseVersion(PATH_HERE+"/../../src/setup.py") + pyAbfVersion = increaseVersion(PATH_HERE+"/../../src/pyabf/__init__.py") + assert setupVersion == pyAbfVersion