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
[RFC] doc: Add Sphinx extension for code samples #62029
[RFC] doc: Add Sphinx extension for code samples #62029
Conversation
76177ff
to
59b921d
Compare
4bf1290
to
381c4e5
Compare
Latest updates address the following issues/comments raised by folks:
|
9fd99be
to
4edf3bf
Compare
FWIW I am very tempted to also add a |
4edf3bf
to
4d2bfb4
Compare
@carlescufi @cfriedt @cfriedt I think this is ready for another review. Please see #62029 (comment) for main changes. I didn't want to do it initially to keep the initial RFC changes small as a proof of concept, but if people think it's a good idea I could update the third commit of the series so that it effectively migrates all the This would allow to remove the following code that's currently here only to keep backwards compatible with "old" link targets. zephyr/doc/_extensions/zephyr/domain.py Lines 94 to 97 in bf5560b
Thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall lgtm, thanks for this addition. It would also be nice to render the information in a reversed way, ie, in samples, list the relevant APIs used in the sample. So when I open eg blinky, I'll get a link to the GPIO API.
This adds a new Sphinx extension for both a code-sample directive and role. Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Update the sample.tmpl file so that it encourages people to use the new :zephyr:code-sample: directive. Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Use the new code-sample directive and roles in a few places to demonstrate how it works. Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Use sphinx-toggle to make "Related code samples" collapsible. Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
4d2bfb4
to
52c282c
Compare
Ya I will keep this for a later update, I think. I thought about adding it but what kept me from doing it TBH was that for some reason Breathe does not seem to capture the human-readable name of doxygen groups (but I could probably put together some kind of hack I'm sure). So it would be looking rather ugly IMO to have the references render as "Related API: gpio_interfaces" where we could instead have "Related API: GPIO Driver APIs" |
We should also be cautious about building stuff on top of breathe, it's not well maintained. |
CI-built doc website: https://builds.zephyrproject.io/zephyr/pr/62029/docs/
Introduction
Finding relevant code samples for a given API can be challenging, and this RFC aims at introducing some Sphinx tooling to help make documentation of code samples more consistent / useful.
Problem description
Unless one is already well-versed into Zephyr (and has a way to actually browse the source tree), finding code samples that are relevant for a particular API can be very challenging.
Proposed change
Add a Sphinx extension that helps formally describe the most critical information for each code samples:
Detailed RFC
This PR introduces a new Sphinx extension meant at providing a way to document code samples in a more structured way, and to have a way for users to discover relevant samples when browsing a given API documentation page.
As a proof of concept, a couple basic samples have been ported over. Should more or less fix #60647.
Example usage for the
zephyr:code-sample::
directive allowing to describe a sample:Example usage for the
zephyr:code-sample
role:Some of the things that this enables (not everything implemented in the PR, but might be in the future based on feedback / interest:
code-sample
role now allows to link to a sample'ssemaphore_apis
listed as one of the doxygen-groups, Semaphore API now looks like this (admonition is collapsed by default -- don't mind the buggy style if you test it live here, I'll get this fixed):.. zephyr:board
directive at some point?Note: I went for Doxygen groups as the type of "unit" that is relevant to attach to a code sample, but we could think of different/additional ones too - ex. header files, C functions (i.e. "checkout this one sample cause it has everything you need to understand how to use this particular function"), ...
Concerns and Unresolved Questions
Alternatives