3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-11-23 06:01:27 +00:00

documenting.rst: Using autodoc

Switch `autocmd` to use the `seealso` admonition for referencing source file location instead of `note`.
This commit is contained in:
Krystine Sherwin 2025-11-22 12:56:30 +13:00
parent 5318df784a
commit dc8198561a
No known key found for this signature in database
3 changed files with 66 additions and 29 deletions

View file

@ -30,6 +30,7 @@ the name of the pass, as demonstrated here with `chformal`.
:start-at: public Pass { :start-at: public Pass {
:end-at: ChformalPass() :end-at: ChformalPass()
:caption: ``ChformalPass()`` from :file:`passes/cmds/chformal.cc` :caption: ``ChformalPass()`` from :file:`passes/cmds/chformal.cc`
:name: chformal_pass
:append: :append:
// ... // ...
} ChformalPass; } ChformalPass;
@ -484,7 +485,9 @@ the `Warning flags`_, source location, source function, and corresponding group
.. literalinclude:: /generated/cmds.json .. literalinclude:: /generated/cmds.json
:language: json :language: json
:start-at: "chformal": { :start-at: "chformal": {
:end-before: "chparam": { :end-at: "internal_flag": false
:append: }
:dedent:
:caption: `chformal` in generated :file:`cmds.json` :caption: `chformal` in generated :file:`cmds.json`
:name: chformal_json :name: chformal_json
@ -635,51 +638,83 @@ will fallback to formatting as inline yoscrypt.
.. literalinclude:: formatting_sample.txt .. literalinclude:: formatting_sample.txt
:language: reStructuredText :language: reStructuredText
:start-after: .. 3 :start-after: .. 3
:end-before: .. 4
.. tab:: formatted output .. tab:: formatted output
.. include:: formatting_sample.txt .. include:: formatting_sample.txt
:start-after: .. 3 :start-after: .. 3
:end-before: .. 4
Using autodoc Using autodoc
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
- below is the raw RST output from ``autocmd`` (``YosysCmdDocumenter`` class in The vast majority of command and cell help content in these docs is done with
:file:`docs/util/cmd_documenter.py`) for `chformal` command the the `autodoc extension`_. By generating Sphinx documentation from our JSON
- heading will be rendered as a subheading of the most recent heading (see dumps of commands and cells, not only are we able to write the help content once
`chformal autocmd`_ above rendered under `Command help`_) and have it available both in Yosys itself and online, we also ensure that any
- ``.. cmd:def:: <cmd>`` line is indexed for cross references with ``:cmd:ref:`` code changes or additions are automatically propagated to the web docs.
directive (`chformal autocmd`_ above uses ``:noindex:`` option so that
`chformal` still links to the correct location)
+ ``:title:`` option controls text that appears when hovering over the .. note::
`chformal` link
- commands with warning flags (experimental or internal) add a ``.. warning`` We are focusing on the ``autocmd`` directive here because it is easier to
block before any of the help content demonstrate. In practice we don't really use it directly outside of this
- if a command has no ``source_location`` the ``.. note`` at the bottom will page, and instead make use of the ``autocmdgroup`` directive. By providing
instead link to :doc:`/cmd/index_other` the ``:members:`` option, this is the same as calling ``autocmd`` for each
command in the group and means that any new commands are added automatically.
.. _showing autocmd generated rst: Now let's take a look at the :ref:`chformal_rst` behind :ref:`chformal autocmd`.
This conversion is done by the ``YosysCmdDocumenter`` class in
:file:`docs/util/cmd_documenter.py`. We can see all of our ``paragraph`` and
``option`` nodes from :ref:`ChformalPass::formatted_help() <chformal_source>`
have made it through, as has the ``short_help`` from our :ref:`ChformalPass()
constructor <chformal_pass>`. The heading will be rendered as a subheading of
the most recent heading (notice how the `chformal` help content above is listed
under `Command help`_ in the table of contents).
.. _chformal_rst:
.. autocmd_rst:: chformal .. autocmd_rst:: chformal
- command groups documented with ``autocmdgroup <group>`` To support cross references with the ``cmd:ref`` role, we see everything is
under the ``cmd:def`` directive. The ``:title:`` option is what controls the
text that appears when hovering over the `chformal` link, and when using the
``cmd:title`` role. For commands with `warning flags`_, a ``.. warning`` block
is added to the generated RST before any of the help content. This is the same
`warning admonition`_ that we've seen elsewhere on this page. For commands with
no ``source_location``, the ``.. seealso`` block at the bottom will instead link
to :doc:`/cmd/index_other`.
+ with ``:members:`` option this is the same as calling ``autocmd`` for each .. _warning admonition: https://pradyunsg.me/furo/reference/admonitions/#warning
member of the group
- ``autocell`` and ``autocellgroup`` .. hint::
+ very similar to ``autocmd`` and ``autocmdgroup`` but for cells instead of The :ref:`chformal autocmd` on this page uses the ``:noindex:`` option so
commands (``YosysCellDocumenter`` in :file:`docs/util/cell_documenter.py`) that references to `chformal` link to the :doc:`/cmd_ref` instead of this
+ optionally includes verilog source for cell(s) with ``:source:`` option page.
(plus ``:linenos:``)
+ cell definitions do not include titles
+ cells can have properties (:ref:`propindex`)
- bonus ``autocmd_rst``, used exclusively on this page for `showing autocmd For documenting cells we have ``autocell`` and ``autocellgroup``, which function
generated rst`_ pretty similarly to their command-based counter parts, ``autocmd`` and
``autocmdgroup``. These directives are provided by the ``YosysCellDocumenter``
in :file:`docs/util/cell_documenter.py`. Like with `help <celltype>+`, we are
able to include verilog simulation models in our ``autodoc`` with the
``:source:`` option. We can then also include line numbers by adding
``:linenos:``, which is very useful when trying to find the source code being
referenced.
.. todo:: would be nice to get a ``.. autocell:: $nex``
like we did with `chformal autocmd`_, but it doesn't seem to like the
`:noindex:` option, or using `:source:` without it being ``binary::$nex``.
.. todo:: cells can have properties (:ref:`propindex`)
.. note::
For :ref:`showing autocmd generated rst <chformal_rst>` on this page, we also
have the ``autocmd_rst`` directive. This is not used anywhere else in the
documentation, but it's mentioned here since we're already deep in the weeds
of how these docs are made.
Our custom Sphinx domains Our custom Sphinx domains
~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -14,3 +14,5 @@
- `-remove` - `-remove`
- `chformal -remove` - `chformal -remove`
.. 4

View file

@ -394,7 +394,7 @@ class YosysCmdDocumenter(YosysCmdGroupDocumenter):
if self.get_sourcename() != 'unknown': if self.get_sourcename() != 'unknown':
self.add_line('\n', source_name) self.add_line('\n', source_name)
self.add_line(f'.. note:: Help text automatically generated from :file:`{source_name}:{source_line}`', source_name) self.add_line(f'.. seealso:: Help text automatically generated from :file:`{source_name}:{source_line}`', source_name)
# add additional content (e.g. from document), if present # add additional content (e.g. from document), if present
if more_content: if more_content: