Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/mpremote: Fix mpremote mip install with multiple lib folders in sys.path. #15332

Merged
merged 1 commit into from
Jun 28, 2024

Conversation

Josverl
Copy link
Sponsor Contributor

@Josverl Josverl commented Jun 23, 2024

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

    • Expected result:
      Install requests
      Installing requests (latest) from https://micropython.org/pi/v2 to /sd/lib
      Installing: /sd/lib/requests/__init__.mpy
      Done
      
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')

@Josverl Josverl changed the title mpremote: Fix mpremote mip install to lib folder in sys.path. mpremote: Fix mpremote mip install with multiple lib folders in sys.path. Jun 23, 2024
@Josverl Josverl changed the title mpremote: Fix mpremote mip install with multiple lib folders in sys.path. toools/mpremote: Fix mpremote mip install with multiple lib folders in sys.path. Jun 23, 2024
@Josverl Josverl changed the title toools/mpremote: Fix mpremote mip install with multiple lib folders in sys.path. tools/mpremote: Fix mpremote mip install with multiple lib folders in sys.path. Jun 23, 2024
Copy link

codecov bot commented Jun 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.42%. Comparing base (b4213c9) to head (85f29ab).

Current head 85f29ab differs from pull request most recent head 3af1425

Please upload reports for the commit 3af1425 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15332      +/-   ##
==========================================
- Coverage   98.42%   98.42%   -0.01%     
==========================================
  Files         161      161              
  Lines       21249    21234      -15     
==========================================
- Hits        20915    20900      -15     
  Misses        334      334              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS

@dpgeorge dpgeorge added the tools label Jun 24, 2024
@dpgeorge
Copy link
Member

Thanks for the fix. This looks reasonable to me, using | as the separator. That character is unlikely to be in the name of any path.

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 when there is more
than one lib path in `sys.path`.

Signed-off-by: Jos Verlinde <Jos.Verlinde@microsoft.com>
@dpgeorge dpgeorge merged commit 3af1425 into micropython:master Jun 28, 2024
60 of 62 checks passed
@Josverl Josverl deleted the mpremote/mip_target branch June 28, 2024 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants