Page MenuHomec4science

bump_version.py
No OneTemporary

File Metadata

Created
Sun, Apr 28, 05:56

bump_version.py

# Copyright (C) 2018 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
import os
import sys
from warnings import warn
filename = "./setup.py"
filenameOut = filename[:-3] + "_out" + filename[-3:]
if not os.path.exists(filename):
raise Exception(("Could not find setup.py file. Check if current folder"
"is correct."))
if len(sys.argv) > 2:
warn("Ignoring all arguments except first.")
findSingleVersion = False
try:
with open(filename, 'r') as filein, open(filenameOut, 'w') as fileout:
for line in filein:
versionpos = line.find("version=\"")
if versionpos > -1:
if findSingleVersion:
raise
commapos = line.find("\",")
if len(sys.argv) > 1:
version = sys.argv[1]
else:
version = line[versionpos + 9 : commapos]
try:
if version[-1] in [str(x) for x in range(9)]:
lastdigit = int(version[-1]) + 1
elif version[-1] == "9":
lastdigit = "X"
else:
lastdigit = "XX"
version = "{}{}".format(version[:-1], lastdigit)
except:
warn(("Could not read old version. Keeping old "
"version. Try specifying new version manually."))
line = (line[: versionpos] + "version=\"" + version
+ line[commapos :])
findSingleVersion = True
fileout.write(line)
if not findSingleVersion:
os.remove(filenameOut)
raise Exception(("Found no occurrences of version in setup.py. "
"Aborting."))
except:
os.remove(filenameOut)
raise Exception(("Found multiple occurrences of version in setup.py. "
"Aborting."))
os.remove(filename)
os.rename(filenameOut, filename)
filenameVer = "./VERSION"
with open(filenameVer, 'w') as filever:
filever.write(version)

Event Timeline