linux/Documentation/sphinx
Mauro Carvalho Chehab 11578a2ecb docs: kernel_include.py: use get_close_matches() to propose alternatives
Improve the suggestions algorithm by using get_close_matches() if
no suggestions with the same name are found. As we're now building
a dict, when the name is identical, but on a different domain,
the search is O(1), making it a lot faster.

The get_close_matches is also fast, as there is just one loop,
instead of 3.

This can be useful to detect typos on references, with could
be the base of a futuere extension that will handle ref unmatches
for the entire build, allowing someone to find typos and fix them.

As difflib and get_close_matches are there since the early
Python 3.x days, we don't need to handle any extra dependencies
to use it.

We're keeping the default values for the search, e.g. n=3, cutoff=0.6.
With that, we now have things like:

  $ make SPHINXDIRS="userspace-api/media" htmldocs
  ...
  include/uapi/linux/videodev2.h:199: WARNING: Invalid xref: c:type:`v4l2_memory`. Possible alternatives:
        c:type:`v4l2_meta_format` (from v4l/dev-meta)
        c:type:`v4l2_rect` (from v4l/dev-overlay)
        c:type:`v4l2_area` (from v4l/ext-ctrls-image-source) [ref.missing]
  ...
  include/uapi/linux/videodev2.h:1985: WARNING: Invalid xref: c:type:`V4L.v4l2_queryctrl`. Possible alternatives:
        std🏷️`v4l2-queryctrl` (from v4l/vidioc-queryctrl)
        std🏷️`v4l2-query-ext-ctrl` (from v4l/vidioc-queryctrl)

At the first example, it was not a typo, but a symbol that doesn't
seem to be properly documented. The second example points to
v4l2-queryctrl, which is a close match for the symbol.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Message-ID: <7365feb74cbdd6b982c87baf5863360ab98cf727.1759329363.git.mchehab+huawei@kernel.org>
History 2025-10-17 13:56:59 -06:00
..
templates docs: sphinx: remove SPDX/copyright comments from HTML output 2025-09-03 15:50:51 -06:00
automarkup.py Documentation/sphinx: Fix typo in automarkup.py 2025-08-18 09:45:47 -06:00
kernel_abi.py sphinx: kernel_abi: fix performance regression with O=<dir> 2025-07-24 08:36:17 -06:00
kernel_feat.py docs: kdoc: handle the obsolescensce of docutils.ErrorString() 2025-09-15 17:24:06 -06:00
kernel_include.py docs: kernel_include.py: use get_close_matches() to propose alternatives 2025-10-17 13:56:59 -06:00
kerneldoc-preamble.sty docs: kerneldoc-preamble.sty: Suppress extra spaces in CJK literal blocks 2024-09-05 14:16:41 -06:00
kerneldoc.py docs: kdoc: Remove a Python 2 comment 2025-07-08 08:06:25 -06:00
kfigure.py docs: sphinx: add missing SPDX tags 2025-06-25 12:39:17 -06:00
load_config.py docs: sphinx: add missing SPDX tags 2025-06-25 12:39:17 -06:00
maintainers_include.py docs: kdoc: handle the obsolescensce of docutils.ErrorString() 2025-09-15 17:24:06 -06:00
min_requirements.txt docs: sphinx: add missing SPDX tags 2025-06-25 12:39:17 -06:00
parallel-wrapper.sh docs: Fix empty parallelism argument 2020-02-25 03:11:04 -07:00
parser_yaml.py sphinx: parser_yaml.py: fix line numbers information 2025-08-12 07:47:31 +02:00
requirements.txt docs: sphinx: add missing SPDX tags 2025-06-25 12:39:17 -06:00
rstFlatTable.py docs: sphinx: add missing SPDX tags 2025-06-25 12:39:17 -06:00
translations.py docs: translations: use attribute to store current language 2024-02-21 13:41:37 -07:00