Skip to content

Commit e33c590

Browse files
authored
Merge pull request #983 from makermelissa/main
Move tomllib imports to function so it works on MicroPython
2 parents 959f130 + 1f36ae0 commit e33c590

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/adafruit_blinka/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010

1111
import os
1212

13-
try:
14-
import tomllib
15-
except ImportError:
16-
import toml as tomllib
17-
1813

1914
class Enum:
2015
"""
@@ -82,9 +77,16 @@ def unlock(self):
8277

8378

8479
def load_settings_toml():
85-
"""Load values from settings.toml into os.environ, so that os.getenv returns them."""
80+
"""Load values from settings.toml into os.environ, so that os.getenv returns them.
81+
Note: This does not work in MicroPython because of the tomllib module not being available.
82+
"""
83+
try:
84+
import tomllib
85+
except ImportError:
86+
import toml as tomllib
87+
8688
if not os.path.isfile("settings.toml"):
87-
raise FileNotFoundError("settings.toml not cound in current directory.")
89+
raise FileNotFoundError("settings.toml not found in current directory.")
8890

8991
print("settings.toml found. Updating environment variables:")
9092
with open("settings.toml", "rb") as toml_file:

0 commit comments

Comments
 (0)