Replies: 6 comments 4 replies
-
See https://josverl.github.io/autodoc201/ for a quick preview |
Beta Was this translation helpful? Give feedback.
-
Can you add a direct link to a source code sample which shows this new way of dcumenting? |
Beta Was this translation helpful? Give feedback.
-
Thanks for your reaction Stinos, It is in that same repo that the pages are : https://github.com/Josverl/autodoc201 Code - there is not too much of it actually, that is the point. the Sphinxs
autoapi needs:
Example module documentation: The results are docpages
It is also possible to mix information autogenerated from the stubs, with additional text/documentation written in .rst ( or .md) |
Beta Was this translation helpful? Give feedback.
-
Documentation for overloads
As according to the standards, overloads may not have docstrings, and Shpinxs AutoAPI does not generate documentation for any but the last, Note: VSCode's Pylance does show both docstrings, and even shows the one that matches the overload best. |
Beta Was this translation helpful? Give feedback.
-
Checked the high level and some details and overall I'd say this is better than the current situation, mainly because from my point of view having the type hints in the docs is rather valueable plus it bridges docs and stubs and imo the stubs should be made an official part of micropython. Still with respect to
I don't think this changes much. Not that that is a problem, it's inherent to the Python language probably, but all of these issues still mostly remain, right? Now the stubs have to be kept up-to-date, still use .rst, there can still be different styles. And there's one thing (which can maybe solved though) which actually seems a bit worse: opening a .rst file in most editors gives syntax highlighting. Opening a .pyi file in VSCode just shows the dosctrings as docstrings so none of the .rst in those strings is recognized. However when Python linting with pretty much default settings kicks in it'll complain about line length, lack of newline between functions etc. So as far as writing the documentation goes this might be a bit harder, or maybe there's tooling which can solve that. |
Beta Was this translation helpful? Give feedback.
-
We've been doing this quite a while in CircuitPython and it has worked well. We store Python stubs in the C files that implement the Python API (shared-bindings in CP land) by having them in |
Beta Was this translation helpful? Give feedback.
-
Introduction and Motivation:
This proposal is to change the way that the documentation for the MicroPython library is maintained.
Currently all documentation is manually created in .rST format, which is error prone and makes it difficult to keep the documentation up-to-date with changes in the implementation of libraries. Also different notation preferences and the .rST oddities have let to numerous unclarities or onprecise documentation.
My proposal is to permanently add type stubs for the library modules, and generate (parts of the) library documentation from these stubs.
I propose to use type-stubs from the[ micropython-stubs](Josverl/micropython-stubs: Stubs of most MicroPython ports, boards and versions to make writing code that much simpler. (github.com)) project as the inital basis for this, and would continue to use these in the process to build the micropython-*-stubs I publish to PyPI.
To allow Sphinx generate documentation from type-stubs, a Sphinx add-in is needed. The best option I have found thus far is Sphinx AutoAPI 3.1.2 ). This is a full featured OSS project with active maintenance and an MIT licence.
It also supports documenting both
.pyi
type-stubs and.py
modules and without the need to import them into CPython, which for many hardware based modules is essential.Benefits:
Scope:
The inital scope would be limited to the documentation under :
/docs/library
Possible futures:
After initial integration of AutoAPI, it would be simple to add additional documentation pages that were impractical to add before, such as :
Background Information:
This has been worked on previously by Jim, an I have spoken to him on occasion but that work appears to have stalled.
I spend a few days to try to understand his approach, and see if I could make that work by changing the way I generate what I refer to as "Doc-Stubs", but
sphinx.ext.autodoc
is incapable of working with .pyi stubs.MicroPython Season of Docs 2023 - Proposal - Google Docs
In other words , the concept was sound , but autodoc just can't handle stub files or modules that are intended for MCUs
Currently I maintain micropython-stubber which reads the dics/library/.rst files and converts then to .pyi files. This takes approx 1800 lines of single purpose code and 150+ code tests that I can mostly retire after this has completed.
I may be overly optimistic, however I think micropython-stubs and stubber are taking care of of the heavy lifing needed to create the relevant .pyi files in the original docs proposal, and the set of 400+ stub quality tests that should give assurance of their initial quality.
The current micropython type stubs are not perfect, nor complete.I strive them to be not wrong, and that already takes a lot of time.
I have been looking for ways to apply things like adding @Overloads on methods, and to mkae it simpler to contribute, without needing to understand all the complexities of building a stub package that I have added over the years.
Blog: Generating beautiful Python API documentation with Sphinx AutoAPI | bylr.info
Detailed Description:
To Implement this the following steps are needed
( docs/stubs/library)
Customize AutoAPI's jinja templates used to generate documentation
Update the existing .rST documents.
Per document in docs/library:
.. module::
-->.. autoapimodule::
.. function::
-->.. autoapifunction::
.. class::
-->.. autoapiclass::
make -C ./docs
Provide a guide-level explanation of the proposed change. What will it achieve?
Include a reference-level explanation with technical details1.
Topics for discussion:
Toolset
Is Sphinx-autoapi the correct tool, or are there better ones ?
I have looked at :
Standard Sphinx autodoc
sphinx.ext.autodoc
autodoc
provides several directives that are versions of the usualpy:module
,py:class
and so forth. On parsing time, they import the corresponding module and extract the docstring of the given objects, inserting them into the page source under a suitablepy:module
,py:class
etc. directive.sphinx-autodoc2
Sphinx AutoAPI
port
orboard
specific modules , functions and classes.Writing guidelines
Currently all is documenteded in the .rST files.
In the future the maintenance of that documentation will be split across two sources:
What is a common effective structure and we will need to document that as well.
Reviewing changes - Type-Stubs
How to verifying correctness of changes to type-stubs.
typestubs can be automatically verified in CI/CD, but there are limited standard tools for this.
micropython-stubs/tests/quality_tests at main · Josverl/micropython-stubs (github.com)
Reviewing changes - Sphinx
A review is needed as always, but the review will be a bit more challenging as in the source the change is spread across different files, but for the result should be similar or the same. I know that RTD support building and publishing [PR previews](Pull request previews — Read the Docs user documentation) so perhaps that is a good option to allow efficient and effective reviewer
Documentation Format
Should we use .rST(restructured text) or .MD (Markdown) for the documentation.
Current docs are written in .rST , but .MD is more accessible.
Currently Sphinx AutoAPI does not directy support .MD, but it is possible and on [their roadmap](Markdown support · Issue #287 · readthedocs/sphinx-autoapi · GitHub).
If we indeed use Sphinx AutoAP, It seems sensible to wait
Publishing type-stubs
I do not think it makes sense to publish the setof library type-stubs independently, as they do not match the set of stubs needed for any port or board.
I do not want to inflate the scope of this with the added complexity of building , testing and publishing distibution packages for type stubs, but It is clearly related.
That being said, I'm currently the sole owner of PyPI of these micropython-stubs, and that is not perfect either.
Documenting Constants/Attributes/Data
There is no formal standard to add docstrings to module or class level properties, but there is a common practice that is also used in the micropython stubs.
This method does not appear to be recognised by either of the API-documentation tools.
Sorry that this a bit of a longer post, but I have been mulling this for quite some time,
and would like to move forward on this, but do not want to do that entirely on my own.
Beta Was this translation helpful? Give feedback.
All reactions