Linux Documentation
 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>,
	Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
	Shuah Khan <skhan@linuxfoundation.org>
Subject: [PATCH v3 10/13] docs: maintainers_include: better handle directories
Date: Sat,  9 May 2026 08:56:43 +0200	[thread overview]
Message-ID: <2b07e12eaa07bf81824ad427335783b170e01dba.1778309595.git.mchehab+huawei@kernel.org> (raw)
In-Reply-To: <cover.1778309595.git.mchehab+huawei@kernel.org>

The TOC tree needs to use paths relative to the document containing
the maintainers-profile-toc directive. Fix it.

While here, address a warning from sashiko-bot, which points
that using partition can be problematic if the root Linux path
ends being something like:

    foo/Documentation/linux/

causing the documentation dir to be at:

    foo/Documentation/linux/Documentation

Very unlikely, but fixing it is trivial: just use regex to
pick the last one.

Notice that I dropped the comment about using os.fspath() as
the logic already uses os.path.abspath() which should work
equally well.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 Documentation/sphinx/maintainers_include.py | 28 ++++++++++++---------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/Documentation/sphinx/maintainers_include.py b/Documentation/sphinx/maintainers_include.py
index 073a10575872..8c7b79721edd 100755
--- a/Documentation/sphinx/maintainers_include.py
+++ b/Documentation/sphinx/maintainers_include.py
@@ -82,7 +82,7 @@ def ErrorString(exc):  # pylint: disable=C0103, C0116
 class MaintainersParser:
     """Parse MAINTAINERS file(s) content"""
 
-    def __init__(self, app_dir, path):
+    def __init__(self, base_dir, app_dir, path):
         self.path = path
 
         # Poor man's state machine.
@@ -92,8 +92,8 @@ class MaintainersParser:
 
         self.subsystem_name = None
 
-        self.app_dir = os.path.abspath(app_dir)
-        self.base_dir, _, self.sphinx_dir = self.app_dir.partition("Documentation")
+        self.base_dir = base_dir
+        self.app_dir = app_dir
 
         self.re_doc = re.compile(r'(Documentation/([^\s\?\*]*)\.rst)')
 
@@ -323,6 +323,8 @@ class MaintainersProfile(Include):
 
     def emit(self):
         """Parse all the MAINTAINERS lines looking for profile entries"""
+        env = self.state.document.settings.env
+        docdir = os.path.dirname(os.path.join(env.srcdir, env.docname))
         path = maint_parser.path
 
         #
@@ -347,7 +349,9 @@ class MaintainersProfile(Include):
         output += "\n.. toctree::\n"
         output += "   :hidden:\n\n"
 
-        for fname in sorted(maint_parser.profile_toc):
+        for f in sorted(maint_parser.profile_toc):
+            fname = os.path.join(maint_parser.base_dir, "Documentation", f)
+            fname = os.path.relpath(fname, docdir)
             output += f"   {fname}\n"
 
         output += "\n"
@@ -381,15 +385,15 @@ def setup(app):
     """Setup Sphinx extension"""
     global maint_parser  # pylint: disable=W0603
 
-    #
-    # NOTE: we're using os.fspath() here because of a Sphinx warning:
-    #   RemovedInSphinx90Warning: Sphinx 9 will drop support for representing paths as strings. Use "pathlib.Path" or "os.fspath" instead.
-    #
-    app_dir = os.fspath(app.srcdir)
-    srctree = os.path.abspath(os.environ["srctree"])
-    path = os.path.join(srctree, "MAINTAINERS")
+    app_dir = os.path.abspath(app.srcdir)
+    match = re.match(r"(.*/)Documentation", app_dir)
+    if not match:
+        raise ValueError('Documentation directory not found.')
 
-    maint_parser = MaintainersParser(app_dir, path)
+    base_dir = match.group(1)
+    path = os.path.join(base_dir, "MAINTAINERS")
+
+    maint_parser = MaintainersParser(base_dir, app_dir, path)
 
     app.add_directive("maintainers-include", MaintainersInclude)
     app.add_directive("maintainers-profile-toc", MaintainersProfile)
-- 
2.54.0


  parent reply	other threads:[~2026-05-09  6:56 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-09  6:56 [PATCH v3 00/13] Improve process/maintainers output Mauro Carvalho Chehab
2026-05-09  6:56 ` [PATCH v3 01/13] docs: maintainers_include: keep hidden TOC sorted Mauro Carvalho Chehab
2026-05-09  6:56 ` [PATCH v3 02/13] docs: maintainers_include: split state machine on multiple funcs Mauro Carvalho Chehab
2026-05-09  6:56 ` [PATCH v3 03/13] docs: maintainers_include: cleanup the code Mauro Carvalho Chehab
2026-05-09  6:56 ` [PATCH v3 04/13] docs: maintainers_include: clean most SPHINXDIRS=process warnings Mauro Carvalho Chehab
2026-05-09  6:56 ` [PATCH v3 05/13] docs: maintainers_include: do some coding style cleanups Mauro Carvalho Chehab
2026-05-09  6:56 ` [PATCH v3 06/13] docs: maintainers_include: store maintainers entries on a dict Mauro Carvalho Chehab
2026-05-09  6:56 ` [PATCH v3 07/13] docs: maintainers_include: properly handle file patterns Mauro Carvalho Chehab
2026-05-09  6:56 ` [PATCH v3 08/13] docs: maintainers_include: add a filtering javascript Mauro Carvalho Chehab
2026-05-09  6:56 ` [PATCH v3 09/13] docs: maintainers_include: don't ignore invalid profile entries Mauro Carvalho Chehab
2026-05-09  6:56 ` Mauro Carvalho Chehab [this message]
2026-05-09  6:56 ` [PATCH v3 11/13] docs: maintainers_include: better handle doc wildcards Mauro Carvalho Chehab
2026-05-09  6:56 ` [PATCH v3 12/13] MAINTAINERS: make clearer about what's expected for "P" field Mauro Carvalho Chehab
2026-05-09  6:56 ` [PATCH v3 13/13] MAINTAINERS: use a URL for pin-init maintainer's profile entry Mauro Carvalho Chehab
2026-05-09 12:11   ` Gary Guo
2026-05-09 17:53 ` [PATCH v3 00/13] Improve process/maintainers output Joe Perches

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=2b07e12eaa07bf81824ad427335783b170e01dba.1778309595.git.mchehab+huawei@kernel.org \
    --to=mchehab+huawei@kernel.org \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=skhan@linuxfoundation.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