Closed vbolshakov closed 4 years ago
Hi, thanks for the idea.
I will look further into it, but as I do not own an EV3 brick myself, I am not sure if I will be able to generate the stubs for it. Have you tried executing micropy stubs create <EV3_PORT>
?
If the stubs generate successfully, you could either provide them to me or create a PR on micropy-stubs to add them for everyone.
Let me know if you're able to make any progress with this. Thanks.
There is no micropython repl on uart, but there is ssh access to ev3. Just need to understand what scripr i need to run on ev3 to generate stubs.
Can you add option to generate stubber as file?
Interesting.
So micropy-cli uses micropython-stubber for its stub generation. Essentially, you need to do the following:
micropython-stubber
and open createstubs.py
in your editor.createstubs.py
stubs
directory (if it succeeds on the EV3)If you run into any memory related errors, you can use my fork of the repo, make your module edits, then execute python process.py minify
. This will created a smaller minified.py
that uses less memory.
For finding the EV3 modules you can reference their documentation and try executing help('modules')
in repl (on most forks, this will print out a list of modules).
If you run into any trouble, I am happy to help.
There custom Lego build of micropython - pybricks-micropython (MicroPython v1.9.4 on 2019-03-26; linux version) with differences in 'os' module, so i change createstubs in several places with os and firmware version parsing. It is generating stubs for everything but custom modules. And i don't know why... If you interested, i can provide remote access to ev3.
Sure, I'd love to take a look at it!
What is the best way to give you access credential?
Hi,
I think that what is happening is that there is no way for a .py script to find out which modules there are on the firmware.
the only way is to issue the command : help('modules')
, however the output of that cannot be redirected , except on specific hardware ( pyboards) .
so the approach that I have uses in micro-stubber is :
so : you need to add the LEGO specific ones .
to do that in createstubs.py
add a (few) lines with the LEGO custom modules :
#.... at the very end
stubber.add_modules(['pybricks']) # stubs for LEGO Pybricks
stubber.create_all_stubs()
run createsubs.py , ie
brickrun createstubs.py
retrieve (upload..) the stubs from the brick to your PC
( and please share or send a PR to https://github.com/josverl/micropython-stubber including any license ( MIT?) that is relevant for LEGO )
also if you have a list of LEGO specific MicroPython modules , i can just add them to the list of modules to try for micros-stubber.
help('modules') show modules without any problems: robot@ev3dev:~$ pybricks-micropython MicroPython v1.9.4 on 2019-03-26; linux version Use Ctrl-D to exit, Ctrl-E for paste mode
help('modules') main parameters_c pybricks/uev3dev/messaging umachine _thread pybricks/init pybricks/uev3dev/sound uos array pybricks/display pybricks/uev3dev/util urandom boot pybricks/ev3brick sys ure btree pybricks/ev3devices termios uselect builtins pybricks/ev3devio tools usocket cmath pybricks/parameters ubinascii ussl ev3brick_c pybricks/robotics ucollections ustruct ev3devices_c pybricks/speaker ucryptolib utime ffi pybricks/tools uctypes utimeq framebuf pybricks/uev3dev/init uerrno uzlib gc pybricks/uev3dev/_alsa uhashlib websocket math pybricks/uev3dev/_wand uheapq micropython pybricks/uev3dev/display uio mmap pybricks/uev3dev/i2c ujson Plus any modules on the filesystem
But when i add stubber.add_modules(['pybricks/ev3brick'])
I got only this as result """ Module: 'pybricks.ev3brick' on 1 """
display = None ev3brick = None parameters = None speaker = None tools = None uev3dev = None
Okay, that is helpful
I suspect that has something to do with nested modules ( module/submodule and even module/sub/leaf ) ( that is somthing I have noticed ( with M5Stack) before , but have not untangled earlier
have you tried stubber.add_modules(['pybricks'])
behaviour will depend on the implementation. It looks like LEGO has used frozen py-modules so we only can guess
also likely relevant : a manual stubbing exercise : https://github.com/drewwhis/pybricks-stubs
Already use it. But automation with micropy-cli will be better.
Checked both: stubber.add_modules(['pybricks']) # stubs for LEGO Pybricks stubber.add_modules(['pybricks/ev3brick']) # stubs for LEGO Pybricks
@Josverl, thanks for your help. I don't really know much about the EV3 products.
@vbolshakov, agreed. ~The automated stub creation is relatively primitive and could definitely be expanded on.~ (Edit: Misunderstood what you meant. For some reason I thought you were referring to micropy-cli
's ability to automate the uploading/retrieval process of createstubs.py
)
When I get to a desktop later today I will look at this in more detail.
@vbolshakov, I suppose I could add pybricks-stubs to micropy-stubs until Josverl/micropython-stubber#7 is solved. Sound good for now?
Yes.
Okay, went ahead and added what I could. Since it's only the extra modules from pybricks
I would suggest adding another package along side it.
This seemed to work pretty well for me while I was testing it:
micropy stubs add ev3-pybricks-0.0.1
micropy stubs add esp32-micropython-1.9.4 # Someone mentioned PyBricks was based on 1.9.4?
{
"name": "NewProject",
"stubs": {
"esp32-micropython-1.9.4": "1.2.0",
"ev3-pybricks-0.0.1": "1.2.0"
},
"config": {
"vscode": true,
"pylint": true
},
"packages": {},
"dev-packages": {}
}
I will leave this issue open until we can manage a full package from the EV3.
@vbolshakov Please take a look at : https://github.com/Josverl/micropython-stubber/issues/7#issuecomment-526954206
Add support for Lego EV3 MicroPython. https://education.lego.com/en-us/support/mindstorms-ev3/python-for-ev3