tools/mpremote: Fix mpremote mip install with multiple lib folders in sys.path. #15332
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a fix for an algorithmic error in mpremote mip,
that throws an error due to a
\n
used in the concatenation and split.The issue is is discussed in https://github.com/orgs/micropython/discussions/14078
Repro & manual test:
connect a pybv11 with an SD card
on start the pybv11 will mount the SD card and add a 2nd
../lib
-path to sys.path, which will trigger the error.sys.path
:['', '.frozen', '/sd', '/sd/lib', '/flash', '/flash/lib']
mpremote mip install requests
Sample error without this fix
Install requests
Installing requests (latest) from https://micropython.org/pi/v2 to /sd/lib
/requests/init.mpy
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in run_code
File "C:\Users\josverl\pipx.cache\493badebc2c62e8\Scripts\mpremote.exe_main.py", line 7, in
File "C:\Users\josverl\pipx.cache\493badebc2c62e8\Lib\site-packages\mpremote\main.py", line 528, in main
handler_func(state, args)
File "C:\Users\josverl\pipx.cache\493badebc2c62e8\Lib\site-packages\mpremote\mip.py", line 197, in do_mip
_install_package(
File "C:\Users\josverl\pipx.cache\493badebc2c62e8\Lib\site-packages\mpremote\mip.py", line 160, in _install_package
_install_json(transport, package, index, target, version, mpy)
File "C:\Users\josverl\pipx.cache\493badebc2c62e8\Lib\site-packages\mpremote\mip.py", line 118, in _install_json
_download_file(transport, file_url, fs_target_path)
File "C:\Users\josverl\pipx.cache\493badebc2c62e8\Lib\site-packages\mpremote\mip.py", line 91, in _download_file
_ensure_path_exists(transport, dest)
File "C:\Users\josverl\pipx.cache\493badebc2c62e8\Lib\site-packages\mpremote\mip.py", line 33, in _ensure_path_exists
transport.fs_mkdir(prefix)
File "C:\Users\josverl\pipx.cache\493badebc2c62e8\Lib\site-packages\mpremote\transport_serial.py", line 427, in fs_mkdir
self.exec("import os\nos.mkdir('%s')" % dir)
File "C:\Users\josverl\pipx.cache\493badebc2c62e8\Lib\site-packages\mpremote\transport_serial.py", line 287, in exec
raise TransportError("exception", ret, ret_err)
mpremote.transport.TransportError: ('exception', b'', b'Traceback (most recent call last):\r\n File "", line 2\r\nSyntaxError: invalid syntax\r\n')