How to obtain a list of importable modules?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
HermannSW
Posts: 144
Joined: Wed Nov 01, 2017 7:46 am
Contact:

Re: How to obtain a list of importable modules?

Post by HermannSW » Sun Oct 21, 2018 6:36 am

Because of importing of modules is needed for getting help on them, I did do different determination (I had to exclude "webrepl_setup" from "common.mod" because of its interactive nature):

Code: Select all

$ for m in `cat common.mod`; do webrepl_client.py -p abcd -r 192.168.4.1 < <(sleep 1 && echo -e "import $m\nhelp($m)\nexit"); done > esp8266.detail
$ for m in `cat common.mod`; do webrepl_client.py -p abcd -r 192.168.4.1 < <(sleep 1 && echo -e "import $m\nhelp($m)\nexit"); done > esp32.detail
$
Pointers and MicroPython version have to be normalized away:

Code: Select all

$ cat norm.sed
s/^\(.*v1.9.4\).*$/\1/g
s/\(0x[0-9a-f]\{8,8\}\)/0x00000000/g
s/\(at [0-9a-f]\{8,8\}\)/at 0x00000000/g
s/^.*### closed ###.*$//g
$ 

diffs.txt file is in attachment as well as here:

Code: Select all

$ diff --side-by-side <(sed -f norm.sed esp8266.detail) <(sed -f norm.sed esp32.detail) > diffs.txt
$

Some analysis, there are 51 line differences, 121 entries for esp32 only, 51-13=38 entries for esp8266 only:

Code: Select all

$ grep "  |" diffs.txt | wc --lines
51
$ grep "  >" diffs.txt | wc --lines
121
$ grep "  <" diffs.txt | wc --lines
51
$ grep "  [<>]" diffs.txt | grep "^[     ]*[<>][         ]*$" | wc --lines
13
$ grep "  [<>]" diffs.txt | grep "^[     ]*[<][  ]*$" | wc --lines
13
$

binascii module only has "crc32" function in addition to esp8266 for esp32:

Code: Select all

>>>                                                             >>>
MicroPython v1.9.4                                              MicroPython v1.9.4
Type "help()" for more information.                             Type "help()" for more information.
>>> import binascii                                             >>> import binascii
>>> help(binascii)                                              >>> help(binascii)
object <module 'ubinascii'> is of type module                   object <module 'ubinascii'> is of type module
  __name__ -- ubinascii                                           __name__ -- ubinascii
  hexlify -- <function>                                           hexlify -- <function>
  unhexlify -- <function>                                         unhexlify -- <function>
  a2b_base64 -- <function>                                        a2b_base64 -- <function>
  b2a_base64 -- <function>                                        b2a_base64 -- <function>
                                                              >   crc32 -- <function>
>>> exit                                                        >>> exit

In math module constants have different resolution (at lest in help display), expm1 is only available for esp32:

Code: Select all

>>>                                                             >>>
MicroPython v1.9.4                                              MicroPython v1.9.4
Type "help()" for more information.                             Type "help()" for more information.
>>> import math                                                 >>> import math
>>> help(math)                                                  >>> help(math)
object <module 'math'> is of type module                        object <module 'math'> is of type module
  __name__ -- math                                                __name__ -- math
  e -- 2.71828                                                |   e -- 2.718282
  pi -- 3.14159                                               |   pi -- 3.141593
  sqrt -- <function>                                              sqrt -- <function>
  pow -- <function>                                               pow -- <function>
  exp -- <function>                                               exp -- <function>
                                                              >   expm1 -- <function>
  log -- <function>                                               log -- <function>
...

There are false positives, mostly because "diff" cannot resolve different module feature orderings, sometimes because constants have different values (eg. SOL_SOCKET in socket module). But overall diffs.txt gives a good overview of the differences between esp8266 and esp32 MicroPython common module features.
Attachments
detail.zip
detail.zip
(20.28 KiB) Downloaded 5 times

Jongy
Posts: 2
Joined: Fri Jun 08, 2018 11:50 am

Re: How to obtain a list of importable modules?

Post by Jongy » Tue Feb 05, 2019 9:45 pm

See my patch in https://github.com/micropython/micropython/pull/4468 for the CPython-compatible solution of this.

Note, however, that it includes only modules built into the MicroPython interpreter, and not all "importable" modules, that might be otherwise frozen/located as python/.mpy files in a filesystem.

Post Reply