|
2 | 2 |
|
3 | 3 | MicroPythonOS provides a unified framework architecture for accessing system services. All frameworks follow a consistent, simple pattern that makes them easy to discover, use, and extend. |
4 | 4 |
|
| 5 | +## Importing from mpos |
| 6 | + |
| 7 | +**Apps should only import from the `mpos` module directly.** Importing from submodules (such as `mpos.ui`, `mpos.content`, etc.) is not necessary and should be avoided. |
| 8 | + |
| 9 | +All frameworks and utilities you need are available through the main `mpos` module. If you find yourself needing to import from a submodule, or if you would like a new framework to be created, please [create a GitHub issue](https://github.com/MicroPythonOS/MicroPythonOS/issues) describing your use case. |
| 10 | + |
| 11 | +### Correct Import Style |
| 12 | + |
| 13 | +Import directly from `mpos`: |
| 14 | + |
| 15 | +```python |
| 16 | +from mpos import DisplayMetrics |
| 17 | + |
| 18 | +DisplayMetrics.width() |
| 19 | +``` |
| 20 | + |
| 21 | +Or import the module and use it: |
| 22 | + |
| 23 | +```python |
| 24 | +import mpos |
| 25 | + |
| 26 | +mpos.DisplayMetrics.width() |
| 27 | +``` |
| 28 | + |
| 29 | +### Avoid Submodule Imports |
| 30 | + |
| 31 | +Do not import from submodules: |
| 32 | + |
| 33 | +```python |
| 34 | +# ❌ Don't do this |
| 35 | +from mpos.ui import DisplayMetrics |
| 36 | +from mpos.content import AppManager |
| 37 | +``` |
| 38 | + |
| 39 | +Instead, use the main `mpos` module which re-exports everything you need: |
| 40 | + |
| 41 | +```python |
| 42 | +# ✅ Do this instead |
| 43 | +from mpos import DisplayMetrics, AppManager |
| 44 | +``` |
| 45 | + |
5 | 46 | ## Overview |
6 | 47 |
|
7 | 48 | Frameworks are centralized services that provide access to system capabilities like audio, networking, camera, sensors, and task management. They follow a **singleton class pattern with class methods**, ensuring a predictable and discoverable API across the entire system. |
@@ -60,7 +101,7 @@ class MyFramework: |
60 | 101 | Manages app discovery, installation, launching, and version management. |
61 | 102 |
|
62 | 103 | ```python |
63 | | -from mpos.content.app_manager import AppManager |
| 104 | +from mpos import AppManager |
64 | 105 |
|
65 | 106 | # Get all installed apps |
66 | 107 | apps = AppManager.get_app_list() |
@@ -191,16 +232,7 @@ Frameworks should be initialized once at system startup in the board initializat |
191 | 232 |
|
192 | 233 | ```python |
193 | 234 | # In board/your_board.py |
194 | | -from mpos import ( |
195 | | - AppearanceManager, |
196 | | - AudioFlinger, |
197 | | - DownloadManager, |
198 | | - ConnectivityManager, |
199 | | - CameraManager, |
200 | | - SensorManager, |
201 | | - TaskManager |
202 | | -) |
203 | | -from mpos.content.app_manager import AppManager |
| 235 | +from mpos import AppearanceManager, AudioFlinger, DownloadManager, ConnectivityManager, CameraManager, SensorManager, TaskManager, AppManager |
204 | 236 |
|
205 | 237 | def init_frameworks(): |
206 | 238 | """Initialize all frameworks.""" |
@@ -292,22 +324,9 @@ class MyFramework: |
292 | 324 | All frameworks are imported consistently as classes: |
293 | 325 |
|
294 | 326 | ```python |
295 | | -from mpos import ( |
296 | | - AppearanceManager, |
297 | | - AudioFlinger, |
298 | | - CameraManager, |
299 | | - ConnectivityManager, |
300 | | - DownloadManager, |
301 | | - SensorManager, |
302 | | - SharedPreferences, |
303 | | - TaskManager, |
304 | | - WifiService, |
305 | | -) |
306 | | -from mpos.content.app_manager import AppManager |
| 327 | +from mpos import AppearanceManager, AudioFlinger, CameraManager, ConnectivityManager, DownloadManager, SensorManager, SharedPreferences, TaskManager, WifiService, AppManager |
307 | 328 | ``` |
308 | 329 |
|
309 | | -**Note:** AppManager is imported from `mpos.content.app_manager` rather than the main `mpos` module. |
310 | | - |
311 | 330 | ## Benefits of Harmonization |
312 | 331 |
|
313 | 332 | | Aspect | Before | After | |
|
0 commit comments