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

Type Hints for ESP32 #218

Closed
wants to merge 4 commits into from
Closed

Conversation

MrNavaStar
Copy link
Contributor

I have created type hints for the ESP32! This includes the esp module (it differs from the esp8266 esp module) and the esp32 module. I would like to also create hints for the espnow module, however I don't think it is yet in the main branch of micropython. Please let me know If I am wrong about this and I will make a pr with hints for it.

Please have a look over my hints and make sure there are no glaring issues, I have gone over a few times and I think they are pretty solid. The only remaining issues as far as I can tell are a few functions that have no comments. I was unable to find any description of what they do in the official micropython docs.

@Elizaveta239 Elizaveta239 self-assigned this Dec 22, 2022
@Elizaveta239
Copy link
Contributor

Thank you very much! I'll try to review it in the nearest future (or at least not later than January)

@MrNavaStar
Copy link
Contributor Author

Sounds awesome! Ill keep adding any missing type hints as I run into them.

@PBrunot
Copy link

PBrunot commented Dec 26, 2022

Wouldn't be just easier to install the package micropython-{esp32,...}-stubs ? Somebody else is already doing the hard-work to keep boards and micropython libraries in sync. Just add an additional dependency and we're good to go.
I have tested with ESP32-WROOM32 (Lolin D32 board) + PyCharm 22.3 Community Edition + micropython-esp32-stubs 1.19-post7 package: all the specific ESP32 classes (DAC, TouchPad, ...) are supported.

@MrNavaStar
Copy link
Contributor Author

Wouldn't be just easier to install the package micropython-{esp32,...}-stubs ? Somebody else is already doing the hard-work to keep boards and micropython libraries in sync. Just add an additional dependency and we're good to go.

@PBrunot I had no idea this existed! Could you post a link? I agree that would be much better than manually keeping these up to date.

Do you know of any similar packages for other boards or even the micropython core modules (as they too are out of date)

@MrNavaStar
Copy link
Contributor Author

I think this one is different, but it seems to have cover all the boards this plug-in supports + the core modules. We could completely remove the type hints folder in this repo and just install from here

@MrNavaStar
Copy link
Contributor Author

MrNavaStar commented Dec 27, 2022

@PBrunot I have been playing around with this library a bit and it seems to be lacking in a few major ways. The first is that there are no built in comments, and second many of the actual type hints are missing. As in functions do not say what data types they take in or return.

This is not very helpful beyond making the ide happy:
image

@PBrunot
Copy link

PBrunot commented Dec 27, 2022 via email

@MrNavaStar
Copy link
Contributor Author

Yeah Im not sure what they were thinking when they made this tool, but how are these hints helpful lol? They all just take args and kwargs return any:
image

I think the best way forward would be writing a custom tool that creates stubs based on the micropython docs

@PBrunot
Copy link

PBrunot commented Dec 28, 2022 via email

@MrNavaStar
Copy link
Contributor Author

That is correct, we cannot extract the comments from the c code. However, there is a repo called micropython-libs that contains the raw python for all of the micropython libraries. There are some comments in there. The rest of the comments would need to be extracted from the official docs

@MrNavaStar
Copy link
Contributor Author

@Elizaveta239 Any update on this/how we need to move forward?

Elizaveta239 pushed a commit that referenced this pull request Mar 17, 2023
Signed-off-by: Elizaveta Shashkova <elizabeth.shashkova@gmail.com>
@Elizaveta239
Copy link
Contributor

Hi! I'm very sorry for the late response! Thank you very much for the contribution!
Yes, it would be great to automate stub files generation, but currently I don't see how it can be done easily.

I'm closing the PR, It's merged into master. I'll fix some compatibility issues and will publish the new version of the plugin soon.
Thank you very much!

@Josverl
Copy link

Josverl commented Mar 20, 2023

Dear @navastar,
I assume you picked the least rich stub ( a half-product) , and I assume you did not read the documentation that tries to explain this.( not perfectly clear - but still) , and please let me know if it needs further clarification.

So parsing the docs maybe the best option indeed.

Fully agree - that is what I have done. I parse the (sometimes incomplete) micropython documentation (.rst files) and combine that with the other ( also incomplete stubs ) generated on these firmware, and come to a decently complete set of stubs.
With each update to the micropython docs documentation, this gets merged into latest.

The best stubs are in 'publish' and on PyPi

fyi:
The C source does not have usable information that i was able to extract reliably due to differences in coding style by the different authors of the ports and over time.

The reason that the stubs mentioned above contain is little / no information for the DS18x20 device is due to the fact that:

And my code is not smart enough to conjure information out of thin air. ( perhaps I should try to to add OpenAI for that, at the risk of mixing Circuitpython methods with Micropython ... )

@PBrunot
It is possible that there is some information lots in generating the stubs ( I currently rely on mypy/stubgen and that seems to generate better stubs , but also loose some comments / docstrings in the process)
If you can find an example where this happens , please let me know.
I you know of a different stub generation tool to turn .py files into .pyi files without loosing information that would be helpful as well.

@Elizaveta239, please let me know for fixes that you find that you need to make. That way I can either improve the documentation , or try to improve the logic, for esp32 , as well as for other ports.

Please share the feedback here on on https://github.com/Josverl/micropython-stubs/discussions

Happy to help you help other coders.
Jos

@berkut0
Copy link

berkut0 commented Jul 3, 2023

Hi all
According to the changelog ESP32 should be supported.
but I'm not sure if I'm doing it right.
Should I choose ESP8266 for ESP32?

image

@megazhuk
Copy link

Hi! I'm very sorry for the late response! Thank you very much for the contribution! Yes, it would be great to automate stub files generation, but currently I don't see how it can be done easily.

I'm closing the PR, It's merged into master. I'll fix some compatibility issues and will publish the new version of the plugin soon. Thank you very much!

Can't find 'esp32' in 'Device type' field in Micropython plugin options in Settings.
And 'esp32.pyi' not used by PyCharm.
I left "ESP8266" in the "Device type" field, and copied the esp32.pyi file from \intellij-micropython\typehints\esp32 into the
\intellij-micropython\typehints\esp8266 folder.
Now it works, but the soul is not calm.
May be you can fix this ?

@Josverl
Copy link

Josverl commented Jul 17, 2023

Type-stubs are in the planning, and being worked on, for the Micropython project, based off the automated micropython -stubs that I created.

Hope that set your mind at ease.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants