From 530d92cc3ffa9b6b03ee6373f10e7adff64d69cc Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 10 Jun 2021 22:08:26 +0200 Subject: [PATCH] Make the extractVersion function in setup a bit more robust --- setup.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 7f222796..4bb3801f 100755 --- a/setup.py +++ b/setup.py @@ -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