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

doc: samples: Introduce code sample categories #77400

Merged
merged 4 commits into from
Sep 23, 2024

Conversation

kartben
Copy link
Collaborator

@kartben kartben commented Aug 22, 2024

https://builds.zephyrproject.io/zephyr/pr/77400/docs/samples/index.html

This PR enhances the documentation framework by introducing support for categorizing and listing code samples. This also makes better use of the already available metadata that .. zephyr:code-sample directive allows to associate to each sample, namely, the short description.

New directives:

.. zephyr:code-sample-category:: Defines a category for grouping related code samples, which is similar to what used to be manually done, and usually in an inconsistent way. Also for the sake of consistency and minimizing the risk of people misusing Sphinx's toctree, the directive also acts as an implicit toctree, "mounting" all the samples (or sub-categories) underneath it.

.. zephyr:code-sample-listing:: Generates a listing of all the samples for a category (or more than one, actually), optionally with an input field allowing to do filtering of the samples and get them "MQTT", "PWM", "ESP32", etc. samples to quickly show up.

New roles:

  • :zephyr:code-sample-category:: References a code sample category from anywhere in the documentation, similar to :zephyr:code-sample: role.

This change should also help encourage code sample authors to take better care of the metadata (ex. have a really good short description) for their samples as this makes them much more discoverable.

Limitations:

  • Sub-categories and code samples are always listed alphabetically. If deemed useful, I can add some kind of "featured-subcategories" and "featured-samples" options to allow "promoting" some items to the top of their respective lists, but I am not certain this is critical to have (in this first implementation, or ever). It's true that we may want the "Basic" category to be listed first, though, so definitely open to discussion especially as I have some working code for this already (just don't feel like making the directive crazy-customizable from day 1 if not strictly needed).

    Sorting everything alphabetically is arguably infinitely better and more consistent than what we had anyway, as samples in a given category would typically be listed according to their folder name, which might be very different from their actual name as per the title of the README. Therefore, listing such as https://docs.zephyrproject.org/latest/samples/bluetooth/bluetooth.html or https://docs.zephyrproject.org/latest/samples/net/net.html are effectively very randomly sorted today and not very easy to navigate at a glance.

  • Incremental build might need some polishing, but it's likely also true for code-samples, as some dependencies might not alway be captured.

  • Not necessarily a limitation as this forces us to also organize documentation sources cleanly in the first place but atm it's not possible to define categories in just any document and then randomly "attach" a sample to a given category. A category needs to be defined in a folder that contains a sample, and a sample is automatically added to the first category found in its parent folders' hierarchy.

    What that means in practice is should e.g. Bluetooth want to create sub-categories for e.g. Mesh, Audio, etc., the first step would be to create samples/bluetooth/audio/, samples/bluetooth/mesh, etc., move the relevant samples there, and then add an .rst file declaring the category in said folders. Again, not necessarily a limitation IMO, just something to be aware of.

Includes a commit from #77478 as I wanted to already align the docs for the new directives/roles with the changes implemented there.

The actual Sphinx extension work is in the commit doc: extensions: samples: Introduce code sample categories and the changes in the commit that follows, while intimidating, are really about converting existing "legacy" categories and references to them to the new system.

@kartben kartben changed the title doc: samples: wip extension doc: samples: wip sample listing Aug 22, 2024
@kartben kartben force-pushed the samples_toc branch 8 times, most recently from a2f876f to 0f086c0 Compare August 29, 2024 09:02
@kartben kartben force-pushed the samples_toc branch 21 times, most recently from 1e01b03 to d5be859 Compare September 2, 2024 09:36
@kartben kartben force-pushed the samples_toc branch 2 times, most recently from 5815ba1 to ad39ade Compare September 17, 2024 07:29
@kartben kartben requested review from erwango and removed request for theob-pro September 17, 2024 07:58
jori-nordic
jori-nordic previously approved these changes Sep 17, 2024
Copy link
Collaborator

@Thalley Thalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will review once #77478 has merged. Suggest to put DNM or something like that on the PR to prevent this from merging before #77478.

@kartben kartben added the DNM This PR should not be merged (Do Not Merge) label Sep 17, 2024
@kartben
Copy link
Collaborator Author

kartben commented Sep 17, 2024

Adding a "DNM" as per @Thalley's suggestion and to reflect dependency on doc updates in #77478

Adopt zephyr:code-sample directive to describe the Dining
Philosophers sample and update reference accordingly.

Signed-off-by: Benjamin Cabé <[email protected]>
move domain.py to domain/ to make it easier to keep things organized
and e.g. add dedicated css/js resources, etc.

Signed-off-by: Benjamin Cabé <[email protected]>
This commit adds support for categorizing code samples in the
documentation.

It introduces two new directives:

- `zephyr:code-sample-category::` to create a category and associated
  brief description, that implicitly acts as a toctree too.

- `zephyr:code-sample-listing::` to allow dumping a list of samples
  corresponding to a category anywhere in the documentation.

Fixes zephyrproject-rtos#62453.

Signed-off-by: Benjamin Cabé <[email protected]>
This commit uses the new .. zephyr:code-sample-category directive to
categorize code samples across the tree.
Updates existing legacy references to manually defined targets to now
use :zephyr:code-sample-category: role instead.

Signed-off-by: Benjamin Cabé <[email protected]>
@@ -27,4 +27,4 @@ Building and Running
This sample can be found under :zephyr_file:`samples/bluetooth/observer` in the
Zephyr tree.

See :ref:`Bluetooth samples section <bluetooth-samples>` for details.
See :zephyr:code-sample-category:`Bluetooth samples section <bluetooth>` for details.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
See :zephyr:code-sample-category:`Bluetooth samples section <bluetooth>` for details.
See :zephyr:code-sample-category:`bluetooth` samples for details.

Suggest to make this consistent with the others

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! As you can probably imagine, I went for the easy "search and replace" without necessarily putting more thought into it :)

@kartben kartben removed the DNM This PR should not be merged (Do Not Merge) label Sep 18, 2024
@kartben
Copy link
Collaborator Author

kartben commented Sep 22, 2024

@gmarull did you have time to take a look at this PR? I might not be able to come back to it soon but as it will likely be a source of merge conflicts, it would be good to get this in sooner than later in case it is good enough to go. Thanks!

Copy link
Member

@carlescufi carlescufi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great stuff! Thanks @kartben

@carlescufi carlescufi merged commit 1db9b00 into zephyrproject-rtos:main Sep 23, 2024
18 of 19 checks passed
@kartben kartben deleted the samples_toc branch September 23, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants