docs: kernel_include.py: remove Include class inheritance

While the original code came from the Sphinx Include class,
such class is monolithic: it has only one function that does
everything, and 3 variables that are used:

	- required_arguments
	- optional_arguments
	- option_spec

So, basically those are the only members that remain from
the original class, but hey! Those are the same vars that every
other Sphinx directive extension has to define!

In summary, keeping inheritance here doesn't make much sense.

Worse than that, kernel-include doesn't support the current set
of options that the original Include class has, but it also
has its own set of options.

So, let's fill in the argument vars with what it does
support, dropping the rest.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/a9f2eebf11c6b0c3a2e3bf42e71392cdfd2835d1.1755872208.git.mchehab+huawei@kernel.org
This commit is contained in:
Mauro Carvalho Chehab
2025-08-22 16:19:33 +02:00
committed by Jonathan Corbet
parent 4aa578f9c0
commit 428c1d3511

View File

@@ -62,9 +62,8 @@ import sys
from docutils import io, nodes, statemachine
from docutils.statemachine import ViewList
from docutils.utils.error_reporting import SafeString, ErrorString
from docutils.parsers.rst import directives
from docutils.parsers.rst import Directive, directives
from docutils.parsers.rst.directives.body import CodeBlock, NumberLines
from docutils.parsers.rst.directives.misc import Include
from sphinx.util import logging
@@ -81,18 +80,43 @@ RE_SIMPLE_REF = re.compile(r'`([^`]+)`')
# ==============================================================================
class KernelInclude(Include):
"""KernelInclude (``kernel-include``) directive"""
class KernelInclude(Directive):
"""
KernelInclude (``kernel-include``) directive
# Add extra options
option_spec = Include.option_spec.copy()
Most of the stuff here came from Include directive defined at:
docutils/parsers/rst/directives/misc.py
option_spec.update({
Yet, overriding the class don't has any benefits: the original class
only have run() and argument list. Not all of them are implemented,
when checked against latest Sphinx version, as with time more arguments
were added.
So, keep its own list of supported arguments
"""
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = True
option_spec = {
'literal': directives.flag,
'code': directives.unchanged,
'encoding': directives.encoding,
'tab-width': int,
'start-line': int,
'end-line': int,
'start-after': directives.unchanged_required,
'end-before': directives.unchanged_required,
# ignored except for 'literal' or 'code':
'number-lines': directives.unchanged, # integer or None
'class': directives.class_option,
# Arguments that aren't from Sphinx Include directive
'generate-cross-refs': directives.flag,
'warn-broken': directives.flag,
'toc': directives.flag,
'exception-file': directives.unchanged,
})
}
def read_rawtext(self, path, encoding):
"""Read and process file content with error handling"""