import csv
import os
+import sys
SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
-try:
- version_csv_path = os.path.join(SCRIPT_DIR, "version.csv")
- rows = []
- with open(version_csv_path, "r", encoding="utf-8") as _r_file:
- reader = csv.reader(_r_file)
- rows = list(reader)
+def print_version() -> int:
+ """Prints latest version. Print nothing on error or missing value/file."""
+ try:
+ version_csv_path = os.path.join(SCRIPT_DIR, "version.csv")
- # Print latest version
- print(rows[-1][1], end="")
+ # Gather version.CSV into list
+ rows = []
+ with open(version_csv_path, "r", encoding="utf-8") as _r_file:
+ reader = csv.reader(_r_file)
+ rows = list(reader)
-except Exception as exc:
- # Failed, so we print empty version
- pass
+ # Print latest version
+ print(rows[-1][1])
+ return 0
+
+ except Exception: # pylint: disable=broad-exception-caught
+ # Failed, so we print empty version
+ return 1
+
+
+if __name__ == "__main__":
+ sys.exit(print_version())