-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Should support for the functionality of importlib.reload (possibly under a different name) be added to CircuitPython?
There is no importlib module for CircuitPython, therefore "normal" python reloading is not available. I have a pure-python (no firmware/C level changes required) working proof-of-concept implementation here
Since dynamic module reloading isn't exactly a beginner-friendly technique, and it doesn't take a lot of code to provide a decent basic reload implementation for CircuitPython (my current implementation is less than 90 lines - nearly half of which is comments and white space), the main point of this feature request is to discuss whether it even makes sense to provide reload functionality in the basic CircuitPython distributions. It could be provided
- as part of the "core" CircuitPython firmware (frozen .mpy?)
- in one of the bundles (adafruit / community)
- as a "go copy this if you need it" guide
While the autoreload support in CircuitPython provides similar benefits for simple projects and is certainly more predictable / beginner-friendly, there are cases where "normal" reload functionality can be more efficient. One specific use case is modifying behavior of routed REST calls to an adafruit_httpserver.Server. This can dramatically speed up development for internals, diagnostics, and experimentation by removing the need to restart, reconnect wifi, fire up the web server, and wait till your project gets back to the state you were working with before...
Note that the del sys.modules[name]
followed by __import__( name )
approach only mostly reloads a module - it falls short of the "normal" reload functionality in some very significant ways