mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Jonathan Corbet <corbet@lwn.net>,
	Linux Doc Mailing List <linux-doc@vger.kernel.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	linux-kernel@vger.kernel.org,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Randy Dunlap <rdunlap@infradead.org>
Subject: [PATCH 04/15] docs: kdoc_files: use a class to group config parameters
Date: Tue,  3 Feb 2026 15:55:32 +0100	[thread overview]
Message-ID: <c71213ef14ddc7f79581a874cf8a222ffe4f2d1a.1770128540.git.mchehab+huawei@kernel.org> (raw)
In-Reply-To: <cover.1770128540.git.mchehab+huawei@kernel.org>

Instead of abusing argparse.Namespace, define a class to store
configuration parameters and logger.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 tools/lib/python/kdoc/kdoc_files.py | 45 ++++++++++++++++++++---------
 1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/tools/lib/python/kdoc/kdoc_files.py b/tools/lib/python/kdoc/kdoc_files.py
index 8c2059623949..1c5cb9e5f0e8 100644
--- a/tools/lib/python/kdoc/kdoc_files.py
+++ b/tools/lib/python/kdoc/kdoc_files.py
@@ -9,7 +9,6 @@ Classes for navigating through the files that kernel-doc needs to handle
 to generate documentation.
 """
 
-import argparse
 import logging
 import os
 import re
@@ -87,6 +86,28 @@ class GlobSourceFiles:
                 file_not_found_cb(fname)
 
 
+class KdocConfig():
+    """
+    Stores all configuration attributes that kdoc_parser and kdoc_output
+    needs.
+    """
+    def __init__(self, verbose=False, werror=False, wreturn=False,
+                 wshort_desc=False, wcontents_before_sections=False,
+                 logger=None):
+
+        self.verbose = verbose
+        self.werror = werror
+        self.wreturn = wreturn
+        self.wshort_desc =  wshort_desc
+        self.wcontents_before_sections = wcontents_before_sections
+
+        if logger:
+            self.log = logger
+        else:
+            self.log = logging.getLogger(__file__)
+
+        self.warning = self.log.warning
+
 class KernelFiles():
     """
     Parse kernel-doc tags on multiple kernel source files.
@@ -224,29 +245,25 @@ class KernelFiles():
             if kdoc_werror:
                 werror = kdoc_werror
 
+        if not logger:
+           logger = logging.getLogger("kernel-doc")
+        else:
+            logger = logger
+
         # Some variables are global to the parser logic as a whole as they are
         # used to send control configuration to KernelDoc class. As such,
         # those variables are read-only inside the KernelDoc.
-        self.config = argparse.Namespace
+        self.config = KdocConfig(verbose, werror, wreturn, wshort_desc,
+                                 wcontents_before_sections, logger)
 
-        self.config.verbose = verbose
-        self.config.werror = werror
-        self.config.wreturn = wreturn
-        self.config.wshort_desc = wshort_desc
-        self.config.wcontents_before_sections = wcontents_before_sections
+        # Override log warning, as we want to count errors
+        self.config.warning = self.warning
 
         if xforms:
             self.xforms = xforms
         else:
             self.xforms = CTransforms()
 
-        if not logger:
-            self.config.log = logging.getLogger("kernel-doc")
-        else:
-            self.config.log = logger
-
-        self.config.warning = self.warning
-
         self.config.src_tree = os.environ.get("SRCTREE", None)
 
         # Initialize variables that are internal to KernelFiles
-- 
2.52.0


  parent reply	other threads:[~2026-02-03 14:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-03 14:55 [PATCH 00/15] Add unit tests for kernel-doc parser and output Mauro Carvalho Chehab
2026-02-03 14:55 ` [PATCH 01/15] unittests: unittest_helper: store verbosity at the environment Mauro Carvalho Chehab
2026-02-03 14:55 ` [PATCH 02/15] unittests: rename kdoc_xforms.py Mauro Carvalho Chehab
2026-02-03 14:55 ` [PATCH 03/15] unittests: add a runner to execute all unittests Mauro Carvalho Chehab
2026-02-03 14:55 ` Mauro Carvalho Chehab [this message]
2026-02-03 14:55 ` [PATCH 05/15] docs: kdoc_files: move output symbols logic to kdoc_output Mauro Carvalho Chehab
2026-02-03 14:55 ` [PATCH 06/15] docs: kdoc_item: fix initial value for parameterdesc_start_lines Mauro Carvalho Chehab
2026-02-03 14:55 ` [PATCH 07/15] docs: kdoc_item: add support to generate a KdocItem from a dict Mauro Carvalho Chehab
2026-02-03 14:55 ` [PATCH 08/15] docs: kdoc_item: fix a typo on sections_start_lines Mauro Carvalho Chehab
2026-02-03 14:55 ` [PATCH 09/15] docs: unittests: add a parser to test kernel-doc parser logic Mauro Carvalho Chehab
2026-02-03 14:55 ` [PATCH 10/15] docs: add a schema to help creating unittests for kernel-doc Mauro Carvalho Chehab
2026-02-03 14:55 ` [PATCH 11/15] docs: add a simple kdoc-test.yaml together with a validation tool Mauro Carvalho Chehab
2026-02-03 14:55 ` [PATCH 12/15] docs: test_kdoc_parser: add support for dynamic test creation Mauro Carvalho Chehab
2026-02-03 14:55 ` [PATCH 13/15] docs: add a new file to write kernel-doc output to a YAML file Mauro Carvalho Chehab
2026-02-03 14:55 ` [PATCH 14/15] docs: kernel-doc: add support to store output on " Mauro Carvalho Chehab
2026-02-03 14:55 ` [PATCH 15/15] unittests: test_kdoc_parser: add command line arg to read " Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c71213ef14ddc7f79581a874cf8a222ffe4f2d1a.1770128540.git.mchehab+huawei@kernel.org \
    --to=mchehab+huawei@kernel.org \
    --cc=corbet@lwn.net \
    --cc=jani.nikula@linux.intel.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=rdunlap@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®