Generating Python Stubs for MaixPy (For autocompletion in IDEs e.g, Pycharm).

Hi All,
Recently I found this project useful for developerts using Micropython.
micropython-stubber
It can generate .py files for autocompletion (function names, as presented in REPL). I put them in a folder and mark as Sources Root in Pycharm for autocompletion.

Steps to produce the stubs:

  1. Clone the micropython-stubber project or simply download logging.py and createstubs.py
  2. Modify the createstubs.py
    • Modify the path (Since /flash is not supported for folders):
      Line 355: stubber = Stubber(path='/sd')
    • Add additional modules for Maixpy:
      Append the modules after Line 62: self.modules.extend(['Maix','board','fpioa_manager','lcd','sensor','image','video','touchscreen','pye_mp','nes','lvgl'])
  3. Upload logging.py and createstubs.py to /sd
  4. REPL -> import createstubs (and wait for around 30 seconds).
  5. Download the files from your SD card

I also uploaded the stubs generated from my MaixGo (w/ lvgl). You can use it directly.
stubs_20191218.zip (37.4 KB)

Enjoy

1 Like

nice work!