From 59369755edc4498228e3644151bf31ce2e5ff50a Mon Sep 17 00:00:00 2001 From: Dominik George <nik@naturalnet.de> Date: Mon, 31 Jan 2022 00:59:28 +0100 Subject: [PATCH] Move impotrs into methods for even more namespace tidyness --- boot.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/boot.py b/boot.py index 3689963..744e544 100644 --- a/boot.py +++ b/boot.py @@ -14,12 +14,6 @@ """µnit - Configurable initialisation system for MicroPython/ESP""" -import gc -import json -import network -import os -import webrepl - # Set of configuration schemas provided by µnit itself # First level: category -> (human-readable name, dict of settings) # Second level: setting key -> (human-readable name, type, choices, default) @@ -60,6 +54,8 @@ class _MynitConfig: self._load() def _make_dir(self): + import os + try: os.stat(self._dir) except OSError: @@ -68,6 +64,8 @@ class _MynitConfig: def _load(self): """Load cached data from data directory.""" + import json + # Create data directory if it doesn't exist yet self._make_dir() @@ -90,6 +88,8 @@ class _MynitConfig: self._config = {} def _save(self): + import json + """Save cached data to data directory.""" # Create data directory if it doesn't exist yet self._make_dir() @@ -161,6 +161,8 @@ class _MynitBoot: print("Boot finished") def setup_wifi(self): + import network + # Setup wifi if self._config["wifi"]["essid"]: if self._config["wifi"]["mode"] == "sta": @@ -198,6 +200,8 @@ class _MynitBoot: print("Wifi configured as %s" % (nic.ifconfig(),)) def setup_webrepl(self): + import webrepl + # Start webrepl if enabled if self._config["webrepl"]["enabled"]: print("Starting web REPL on port %d" % self._config["webrepl"]["port"]) @@ -219,4 +223,6 @@ if __name__ == "__main__": del _MYNIT_SCHEMAS, _MynitBoot, _MynitConfig # Forcibly clean up before handing overto main.py - gc.collect() + # fmt: off + import gc; gc.collect(); del gc + # fmt: on -- GitLab