QUERY · ISSUE
Mpy modules cannot be imported (sys.path missing '') when running file outside of cwd
py-core
Found on unix port - protostuffer is a single .py file in the modules folder, built in at compile time
./micropython
MicroPython v1.9.3-7-g46e9ef6-dirty on 2017-12-21; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import protostuffer
>>>
./micropython ../../tests/protostuffer-tests/header.py
Traceback (most recent call last):
File "../../tests/protostuffer-tests/header.py", line 1, in <module>
ImportError: no module named 'protostuffer'
To fix
./micropython -i ../../tests/protostuffer-tests/header.py
Traceback (most recent call last):
File "../../tests/protostuffer-tests/header.py", line 1, in <module>
ImportError: no module named 'protostuffer'
MicroPython v1.9.3-7-g46e9ef6-dirty on 2017-12-21; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import protostuffer
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'protostuffer'
>>> import sys
>>> sys.path.append('')
>>> import protostuffer
>>>
CANDIDATE · PULL REQUEST
Implement sys.path support
This implement sys.path support - handling on __import__()'s side, and initialization of sys.path value for unix port. Adding needed changes for stm should be more or less trivial based on the unix code. There may be opportunities for refactoring and reusing some code. But I just wanted to put up this for review.
And some comments about patches: yeah, nobody likes to do string processing in C, especially if without dynamic memory alloc. But someone needs to overcome that and try ;-).