]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Move tomllib imports to function so it works on MicroPython
authorMelissa LeBlanc-Williams <melissa@adafruit.com>
Mon, 23 Jun 2025 17:44:39 +0000 (10:44 -0700)
committerMelissa LeBlanc-Williams <melissa@adafruit.com>
Mon, 23 Jun 2025 17:44:39 +0000 (10:44 -0700)
src/adafruit_blinka/__init__.py

index 38ccec42aaff5ced24d1bbbc3fc9477ebdd94402..3624475b9bea4362504d4822f285fde296536128 100755 (executable)
 
 import os
 
-try:
-    import tomllib
-except ImportError:
-    import toml as tomllib
-
 
 class Enum:
     """
@@ -82,9 +77,16 @@ class Lockable(ContextManaged):
 
 
 def load_settings_toml():
-    """Load values from settings.toml into os.environ, so that os.getenv returns them."""
+    """Load values from settings.toml into os.environ, so that os.getenv returns them.
+    Note: This does not work in MicroPython because of the tomllib module not being available.
+    """
+    try:
+        import tomllib
+    except ImportError:
+        import toml as tomllib
+
     if not os.path.isfile("settings.toml"):
-        raise FileNotFoundError("settings.toml not cound in current directory.")
+        raise FileNotFoundError("settings.toml not found in current directory.")
 
     print("settings.toml found. Updating environment variables:")
     with open("settings.toml", "rb") as toml_file: