]> Nutra Git (v1) - nutratech/usda-sqlite.git/commitdiff
lint sql/latest_version.py
authorShane Jaroch <chown_tee@proton.me>
Thu, 18 Apr 2024 15:44:19 +0000 (11:44 -0400)
committerShane Jaroch <chown_tee@proton.me>
Thu, 18 Apr 2024 15:44:19 +0000 (11:44 -0400)
sql/latest_version.py [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 4fe02e6..0e9aa91
@@ -8,20 +8,30 @@ Created on Sat Mar  2 12:32:45 2024
 
 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())