From nobody Thu Oct 9 02:56:41 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E63791C75E2; Sat, 21 Jun 2025 19:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750535761; cv=none; b=bDYUKTs3cxHVN9d4YCoShukxYPTaNUxhZEJp/UpYS6cH5wHQt2j1aAOmdTdww8fPUZbnkpnL9+hezOZzUsuL/socfCCVXNM4kIEu4rQ69gJVlsNKc3pMfLt0ftIR5C9niOTgERFj7kx9n92KE2rUvZYYp4Jdn/opXsxFEQJclcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750535761; c=relaxed/simple; bh=JvTI+DF/1Dszyn4T0n7ZKhi6vNtj6FoC1Ae/TMd5FHM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M5VKi29mLBGazWEsLYhCSZksZENLby9gDAE6VBhu8CmOundjXEOxiEjLjVDlDXbk9pqRJ8RczT1qxJuwMhfvqSweVkqZ7axDsuYkhJDtzuADP1d6r1WkofIKdyRp3YxF8MmUf8qTDd958UUBbyn/Mo0YOUOWT7+vva5ILAQsUsc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KPUaPay3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KPUaPay3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9ED81C4AF0B; Sat, 21 Jun 2025 19:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750535760; bh=JvTI+DF/1Dszyn4T0n7ZKhi6vNtj6FoC1Ae/TMd5FHM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KPUaPay3ElPI3a6f9isa+EFoHAHoP1yEwqgdktcW2n/wXDZzyG8YwRNSSGe8fBlvv XnHOBIK1u0Ydpevjia/IGZv3ZROcDjHtDgmpdGOh8dqBgIv/3+es1Otq5d+Ouc2Jfz NNrwBgLVCaiV/tNJi7+LWdqkiRJLECjQMbYKOT+621h94tA7rXYjgjGd5Y+BfIF+If UhjLP4hZTu4dEa9Hd8clfwg2J9UJ8bRFR6iJL697xRDE69qATaTruCcxIqvUyVMKJ1 GHT1j3fvku65kjCY+jW53+8LaapoRfe8pKNYUmNpP+eQW3E6HPEbrISs25bN8DiXlc bPhGu6DQl40Sg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uT4Ji-00000000e3c-2NwE; Sat, 21 Jun 2025 21:55:58 +0200 From: Mauro Carvalho Chehab To: Linux Doc Mailing List , Jonathan Corbet Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org, Donald Hunter Subject: [PATCH v2 01/15] docs: conf.py: properly handle include and exclude patterns Date: Sat, 21 Jun 2025 21:55:40 +0200 Message-ID: <737b08e891765dc10bd944d4d42f8b1e37b80275.1750535171.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab Content-Type: text/plain; charset="utf-8" When one does: make SPHINXDIRS=3D"foo" htmldocs All patterns would be relative to Documentation/foo, which causes the include/exclude patterns like: include_patterns =3D [ ... f'foo/*.{ext}', ] to break. This is not what it is expected. Address it by adding a logic to dynamically adjust the pattern when SPHINXDIRS is used. That allows adding parsers for other file types. It should be noticed that include_patterns was added on Sphinx 5.1: https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-incl= ude_patterns So, a backward-compatible code is needed when we start using it for real. Signed-off-by: Mauro Carvalho Chehab Reviewed-by: Donald Hunter --- Documentation/conf.py | 67 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/Documentation/conf.py b/Documentation/conf.py index 12de52a2b17e..4ba4ee45e599 100644 --- a/Documentation/conf.py +++ b/Documentation/conf.py @@ -17,6 +17,66 @@ import os import sphinx import shutil =20 +# Get Sphinx version +major, minor, patch =3D sphinx.version_info[:3] + +# Include_patterns were added on Sphinx 5.1 +if (major < 5) or (major =3D=3D 5 and minor < 1): + has_include_patterns =3D False +else: + has_include_patterns =3D True + # Include patterns that don't contain directory names, in glob format + include_patterns =3D ['**.rst'] + +# Location of Documentation/ directory +doctree =3D os.path.abspath('.') + +# Exclude of patterns that don't contain directory names, in glob format. +exclude_patterns =3D [] + +# List of patterns that contain directory names in glob format. +dyn_include_patterns =3D [] +dyn_exclude_patterns =3D ['output'] + +# Properly handle include/exclude patterns +# ---------------------------------------- + +def update_patterns(app): + + """ + On Sphinx, all directories are relative to what it is passed as + SOURCEDIR parameter for sphinx-build. Due to that, all patterns + that have directory names on it need to be dynamically set, after + converting them to a relative patch. + + As Sphinx doesn't include any patterns outside SOURCEDIR, we should + exclude relative patterns that start with "../". + """ + + sourcedir =3D app.srcdir # full path to the source directory + builddir =3D os.environ.get("BUILDDIR") + + # setup include_patterns dynamically + if has_include_patterns: + for p in dyn_include_patterns: + full =3D os.path.join(doctree, p) + + rel_path =3D os.path.relpath(full, start =3D app.srcdir) + if rel_path.startswith("../"): + continue + + app.config.include_patterns.append(rel_path) + + # setup exclude_patterns dynamically + for p in dyn_exclude_patterns: + full =3D os.path.join(doctree, p) + + rel_path =3D os.path.relpath(full, start =3D app.srcdir) + if rel_path.startswith("../"): + continue + + app.config.exclude_patterns.append(rel_path) + # helper # ------ =20 @@ -219,10 +279,6 @@ language =3D 'en' # Else, today_fmt is used as the format for a strftime call. #today_fmt =3D '%B %d, %Y' =20 -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns =3D ['output'] - # The reST default role (used for this markup: `text`) to use for all # documents. #default_role =3D None @@ -516,3 +572,6 @@ kerneldoc_srctree =3D '..' # the last statement in the conf.py file # ------------------------------------------------------------------------= ------ loadConfig(globals()) + +def setup(app): + app.connect('builder-inited', update_patterns) --=20 2.49.0