Skip to content

Add a static stubs directory #10485

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dunkmann00
Copy link

@dunkmann00 dunkmann00 commented Jul 16, 2025

Stubs are mostly generated from modules in shared-bindings. But in order to generate the stub the c code has to be commented with the appropriate type hints. If a module is located somewhere else (like micropython.const) and/or there are not the appropriate doc comments, no stub is generated for it. For these occassions we can create static stubs in the stubs directory that can be used in circuitpython-stubs.

This also creates a stub for micropython.const and adds the static stubs directory into the makefile stubs command.

Fixes #10484

Stubs are mostly generated from modules in shared-bindings. But in order
to generate the stub the c code has to be commented with the appropriate
type hints. If a module is located somewhere else (like
micropython.const) and/or there are not the appropriate doc comments, no
stub is generated for it. For these occassions we can create static
stubs in the stubs directory that can be used in circuitpython-stubs.

This also creates a stub for micropython.const and adds the static
stubs directory into the makefile stubs command.
@FoamyGuy
Copy link
Collaborator

I looked into the docs build error. It's root cause is that now it's trying to pull from multiple different places for the micropython module.

I've tested the following solution locally and it appears to be working:

  1. Delete: https://github.com/adafruit/circuitpython/blob/main/docs/library/micropython.rst. Sphinx will pull from the stubs for anything that it can, so it no longer needs this static rst file it will pull from the new static .pyi file. Which in hindsight is actually kind of nice to have 1 true source of the info rather than multiple. There are a handful of other micropython features in this file currently that are all marked as CIRCUITPYTHON REMOVE which seems to disable them from appearing on the final docs page. If there is a desire to keep those in the repo in some fashion then they would need to be moved to the .pyi if we use this solution, hopefully the same REMOVE thing can be done from there. If they aren't used by our docs, I'm not sure we have a need for them in the repo though personally.

  2. Change these lines:

    .. toctree::
    :maxdepth: 1
    micropython.rst
    to this:

:doc:`../../shared-bindings/micropython/index`

With those changes the final docs pages remain almost the exact same and seem to build successfully.

The one visual difference is on this page: https://docs.circuitpython.org/en/latest/docs/library/index.html "micropython" appears as part of the link instead of in a code block.

Currently live docs:
image

Local test build doc with these changes:
image

There might be a way to get the code formatting back, but I am not sure. It took me a decent amount of fiddling to figure out how to link to the right place so I decided to skip trying to match the code format syntax. I could try to look for that though if it is preferred to keep that styling.

@dunkmann00
Copy link
Author

Okay I tried out what you described and locally got it building and it seems good...but the only problem is it is now putting micropython as a module in Core Modules, which we don't want.

@FoamyGuy
Copy link
Collaborator

I think having it pulled in via stubs makes the docs assume that it is inside of shared-bindings. I just noticed also the URL that the micropython docs ends up at is different:

Currently live:

/docs/library/micropython.html

With this PR change:

/shared-bindings/micropython/index.html

I'm not sure how to fix it. I think that it's getting picked up by this autodoc https://github.com/adafruit/circuitpython/blob/main/shared-bindings/index.rst?plain=1#L24-L28 but I don't know if it's possible / how to make an exclusion for micropython but if we did exclude it from here then we would need to somehow explicitly add it somewhere else for it to be available in the docs. I'm not sure if it's possible, or if it would work to dump the .pyi files back at doc/libraries/micropython/ during the build, but maybe?

Personally I think it's okay to have micropython appear in 'core modules' instead of 'standard libraries', or at least I can think of no downside other than the URL changing, so any cached copies of that might become dead links. I don't know the real history of it, but looking at the structure of the different files and how docs/stubs build now it feels to me like those might have been originally separate due to the fact that those modules didn't exist somewhere with our docstrings that ultimately are what the docs (and .pyi files) get built from. With this change we now do have a place with our docstrings (the new static stubs file), so it makes sense to me that it would move to the same place as all the other docs that originate from docstrings rather than .rst files.

@dunkmann00
Copy link
Author

Okay cool. I kind of was at the same place as you with not really sure how to get it to replicate the current site layout. But if you are okay with it being in Core modules then that works for me!

@dunkmann00
Copy link
Author

The last commit adds a redirect from the old location to the new, so dead links shouldn't be a problem.

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.

Adding micropython.const to stubs
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy