Skip to content

Commit 58363e4

Browse files
Add os.path functionality like in CPython
1 parent b30f74e commit 58363e4

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Frameworks:
1616
- SharedPreferences: avoid writing default-only configs at boot and prune empty config dirs/files
1717

1818
OS:
19-
- Add path library
19+
- Add os.path functionality like in CPython
2020
- c_mpos/quirc: fix compilation warnings
2121
- Simplify focusgroup handling
2222
- Disable unused OS facilities (FreeRTOS internals, tracing, INFO logging, broken GIF, Pinyin IME, LVGL window, BMP) to reduce build size by 109KiB

internal_filesystem/apps/com.micropythonos.showfonts/assets/showfonts.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ def onCreate(self):
99
screen = lv.obj()
1010
screen.set_flex_flow(lv.FLEX_FLOW.COLUMN)
1111

12-
import path
13-
print(f"{__file__}") # apps/com.micropythonos.showfonts/assets/showfonts.py
14-
print(f"{path.abspath(__file__)}")
15-
print(f"{path.dirname(path.abspath(__file__))}")
16-
d = path.dirname(path.abspath(__file__))
17-
self._ttf_font = FontManager.getFont(size=42, ttf=f"M:{d}/Rancourt-SmallCaps.ttf")
12+
import os
13+
mydir = os.path.dirname(os.path.abspath(__file__))
14+
self._ttf_font = FontManager.getFont(size=42, ttf=f"M:{mydir}/Rancourt-SmallCaps.ttf")
1815

1916
self.addAllFontsTitles(screen)
2017
self.addAllGlyphs(screen)
@@ -40,7 +37,7 @@ def addAllFontsTitles(self, screen):
4037
bitcoin_symbol_in_circle = "\uf379"
4138
thumbs_up_symbol = "\uf164"
4239
diacritics = "æ ø å Æ Ø Å"
43-
supported_latin = "Æ æ Ð ð ß Þ þ 7"
40+
supported_latin = "Æ æ Ð ð ß Þ þ"
4441
title.set_text(
4542
"{}: ABC 123 xyz ❤️ ☺️ !@#$%^&*( {} {} ₿ {} {} {} 丯 丰 {} {}".format(
4643
name,

internal_filesystem/lib/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ This /lib folder contains:
1111
- https://github.com/micropython/micropython-lib/blob/master/python-stdlib/shutil/shutil.py version 0.0.5 # for rmtree()
1212
- https://github.com/micropython/micropython-lib/blob/master/python-stdlib/unittest/unittest/__init__.py version 0.10.4 # for testing (also on-device)
1313
- https://github.com/micropython/micropython-lib/blob/master/python-stdlib/pathlib/pathlib.py version 0.0.1 # for Path()
14+
- https://github.com/micropython/micropython-lib/blob/master/python-stdlib/os-path/os/path.py version 0.2.0 # for os.path (monkeypatched)

internal_filesystem/lib/mpos/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ def change_task_handler(period_ms=1):
322322
mpos.ui.change_task_handler = change_task_handler # make it accessible
323323
mpos.ui.change_task_handler()
324324

325+
# Patch (u)os module so os.path works like in CPython - do this before starting apps
326+
import sys
327+
import os as _os
328+
import path as _path
329+
_os.path = _path
330+
sys.modules["os"] = _os
331+
sys.modules["uos"] = _os
332+
325333
try:
326334
from mpos.net.wifi_service import WifiService
327335
_thread.stack_size(TaskManager.good_stack_size())

0 commit comments

Comments
 (0)