From: Melissa LeBlanc-Williams Date: Mon, 23 Jun 2025 17:44:39 +0000 (-0700) Subject: Move tomllib imports to function so it works on MicroPython X-Git-Tag: 8.61.2^2 X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/1f36ae0002ba8a1d47bd5657f958ebddc4c2973d?ds=inline;hp=--cc Move tomllib imports to function so it works on MicroPython --- 1f36ae0002ba8a1d47bd5657f958ebddc4c2973d diff --git a/src/adafruit_blinka/__init__.py b/src/adafruit_blinka/__init__.py index 38ccec4..3624475 100755 --- a/src/adafruit_blinka/__init__.py +++ b/src/adafruit_blinka/__init__.py @@ -10,11 +10,6 @@ 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: