Make the extractVersion function in setup a bit more robust

This commit is contained in:
Veronica Berglyd Olsen
2021-06-10 22:08:26 +02:00
parent 616fe35ed5
commit 530d92cc3f
+13 -6
View File
@@ -50,12 +50,19 @@ def extractVersion():
numVers = "Unknown"
hexVers = "Unknown"
initFile = os.path.join("nw", "__init__.py")
with open(initFile, mode="r") as inFile:
for aLine in inFile:
if aLine.startswith("__version__"):
numVers = getValue((aLine))
if aLine.startswith("__hexversion__"):
hexVers = getValue((aLine))
try:
with open(initFile, mode="r", encoding="utf-8") as inFile:
for aLine in inFile:
if aLine.startswith("__version__"):
numVers = getValue((aLine))
if aLine.startswith("__hexversion__"):
hexVers = getValue((aLine))
except Exception as e:
print("Could not read file: %s" % initFile)
print(str(e))
print("novelWriter version is: %s (%s)" % (numVers, hexVers))
print("")
return numVers, hexVers