]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/board.py
Change to using try/except blocks
[Adafruit_Blinka-hackapet.git] / src / board.py
index ebdc21f427f732a0b264ef7cdf79373c28b1bbee..1b42b53211399f7606e65571a2489d735d4f5cd7 100755 (executable)
@@ -28,13 +28,12 @@ See `CircuitPython:board` in CircuitPython for more details.
 * Author(s): cefn
 """
 import sys
-import busio
 
 import adafruit_platformdetect.constants.boards as ap_board
 from adafruit_blinka.agnostic import board_id, detector
+import busio
 
 # pylint: disable=wildcard-import,unused-wildcard-import,ungrouped-imports
-# pylint: disable=import-outside-toplevel
 
 if board_id == ap_board.FEATHER_HUZZAH:
     from adafruit_blinka.board.feather_huzzah import *
@@ -225,15 +224,19 @@ elif "sphinx" in sys.modules:
 else:
     raise NotImplementedError("Board not supported {}".format(board_id))
 
-if SDA and SCL:
+try:
+    if SDA and SCL:
 
-    def I2C():
-        """The singleton I2C interface"""
-        return busio.I2C(SCL, SDA)
+        def I2C():
+            """The singleton I2C interface"""
+            return busio.I2C(SCL, SDA)
 
+    if SCLK:
 
-if SCLK:
+        def SPI():
+            """The singleton SPI interface"""
+            return busio.SPI(SCLK, MOSI, MISO)
 
-    def SPI():
-        """The singleton SPI interface"""
-        return busio.SPI(SCLK, MOSI, MISO)
+
+except NameError:
+    pass