Hi!
I want to enhance MicroPython support in my Python IDE Thonny (currently it only supports Micro:bit).
One aspect of the support would be code completion in scripts. It would be rather easy to do with jedi if I had bunch of Python files corresponding to MicroPython modules containing stubs of the functions (preferably together with docstrings). For add-on libraries I could use the actual Python source, but the problem is with built-in modules.
How can I generate these scripts for each Micropython variant (device * version)? Can I somehow use the source of the docs? The main source?
Do you see other options for providing code completion in scripts (as opposed to dynamic completion in the REPL)?
How to get machine-readable MicroPython API for particular firmware variant?
- aivarannamaa
- Posts: 171
- Joined: Fri Sep 22, 2017 3:19 pm
- Location: Estonia
- Contact:
Re: How to get machine-readable MicroPython API for particular firmware variant?
Build unix coverage version ("make coverage"). Then:
As usual, not much different than with CPython, adjusted for "micro" in MicroPython.
Code: Select all
$ ./micropython_coverage
MicroPython v1.9.3-183-ge37ccfe59-dirty on 2017-12-16; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import sys
>>> help(sys)
object <module 'sys'> is of type module
__name__ -- sys
path -- ['', '/home/pfalcon/.micropython/lib', '/usr/lib/micropython']
argv -- []
version -- 3.4.0
version_info -- (3, 4, 0)
implementation -- (name='micropython', version=(1, 9, 3))
platform -- linux
byteorder -- little
maxsize -- 9223372036854775807
exit -- <function>
stdin -- <io.TextIOWrapper 0>
stdout -- <io.TextIOWrapper 1>
stderr -- <io.TextIOWrapper 2>
modules -- {}
exc_info -- <function>
getsizeof -- <function>
print_exception -- <function>
>>>
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
- aivarannamaa
- Posts: 171
- Joined: Fri Sep 22, 2017 3:19 pm
- Location: Estonia
- Contact:
Re: How to get machine-readable MicroPython API for particular firmware variant?
I'm afraid I don't understand your advice. I see how I can fetch the list of modules and list of functions, but what about signatures?
Aivar Annamaa
https://thonny.org
https://thonny.org
Re: How to get machine-readable MicroPython API for particular firmware variant?
If you run the below on the board and capture the output then you should be able to get the basics
import sys
sys.implementation.name
sys.implementation.version
sys.implementation
sys.platform
this will return something like:
'micropython'
(1, 9, 3)
'esp32'
(name='micropython', version=(1, 9, 3))
If you need to get the details of the build, then the only way I know of is to send a Ctrl-D to be board, that will trigger a REPL reset
and then on most firmwares you get some additional info on the welcome prompt
MicroPython v1.9.3-220-g7a9a73ee on 2017-12-27; ESP32 module with ESP32
HTH
import sys
sys.implementation.name
sys.implementation.version
sys.implementation
sys.platform
this will return something like:
'micropython'
(1, 9, 3)
'esp32'
(name='micropython', version=(1, 9, 3))
If you need to get the details of the build, then the only way I know of is to send a Ctrl-D to be board, that will trigger a REPL reset
and then on most firmwares you get some additional info on the welcome prompt
MicroPython v1.9.3-220-g7a9a73ee on 2017-12-27; ESP32 module with ESP32
HTH
Last edited by josverl on Fri Jan 05, 2018 11:34 pm, edited 1 time in total.
Re: How to get machine-readable MicroPython API for particular firmware variant?
Typo: Control-D does a soft reset and shows the banner (Control-B is used to end the raw repl and switch back to the "friendly" repl).