From 7be05396bae0f7498bd19d612edd3bfad6179ba6 Mon Sep 17 00:00:00 2001
From: Julian Oes <julian@oes.ch>
Date: Tue, 26 Mar 2019 16:45:48 +0100
Subject: [PATCH] px_uploader.py: check for pyserial

If we dont explicitly check for pyserial, we can have the case where the
import works but the Serial object creation fails. However, we don't see
this because we have this huge try/catch block which swallows
everything.
---
 Tools/px_uploader.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/Tools/px_uploader.py b/Tools/px_uploader.py
index 2782c91430..6ea4432890 100755
--- a/Tools/px_uploader.py
+++ b/Tools/px_uploader.py
@@ -732,6 +732,16 @@ def main():
         print("WARNING: You should uninstall ModemManager as it conflicts with any non-modem serial device (like Pixhawk)")
         print("==========================================================================================================")
 
+    # We need to check for pyserial because the import itself doesn't
+    # seem to fail, at least not on macOS.
+    try:
+        if serial.__version__:
+            pass
+    except:
+        print("Error: pyserial not installed!")
+        print("    (Install using: sudo pip install pyserial)")
+        sys.exit(1)
+
     # Load the firmware file
     fw = firmware(args.firmware)
 
-- 
GitLab