From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Linux Doc Mailing List <linux-doc@vger.kernel.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Mauro Carvalho Chehab" <mchehab+huawei@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 33/39] scripts: sphinx-pre-install: rework install command logic
Date: Tue, 12 Aug 2025 17:52:50 +0200 [thread overview]
Message-ID: <a6120449d9cc14346e867d1ef8944ae28ddbf3f6.1754992972.git.mchehab+huawei@kernel.org> (raw)
In-Reply-To: <cover.1754992972.git.mchehab+huawei@kernel.org>
Cleanup the code to remove some redundancy and to let it be
clearer about the command install instructions.
Ensure that special instructions will be shown only once,
before the actual install command.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
scripts/sphinx-pre-install.py | 179 ++++++++++++++++------------------
1 file changed, 82 insertions(+), 97 deletions(-)
diff --git a/scripts/sphinx-pre-install.py b/scripts/sphinx-pre-install.py
index 1b11162da9fb..7dfe5c2a6cc2 100755
--- a/scripts/sphinx-pre-install.py
+++ b/scripts/sphinx-pre-install.py
@@ -213,7 +213,7 @@ class DepManager:
raise KeyError(f"ERROR!!!: invalid dtype for {progs}: {dtype}")
if output_msg:
- print(f"\n{output_msg}\n")
+ print(f"\n{output_msg}")
class AncillaryMethods:
"""
@@ -583,23 +583,6 @@ class MissingCheckers(AncillaryMethods):
return f.read().strip()
return ""
- def check_missing(self, progs):
- """
- Check for missing dependencies using the provided program mapping.
-
- The actual distro-specific programs are mapped via progs argument.
-
- Returns True if there are missing dependencies, False otherwise.
- """
- self.install += self.deps.check_missing(progs)
- if self.verbose_warn_install:
- self.deps.warn_install()
-
- if not self.deps.need and not self.deps.optional:
- return False
-
- return True
-
def get_system_release(self):
"""
Determine the system type. There's no unique way that would work
@@ -722,7 +705,7 @@ class SphinxDependencyChecker(MissingCheckers):
self.recommend_python = None
# Certain hints are meant to be shown only once
- self.first_hint = True
+ self.distro_msg = None
self.latest_avail_ver = (0, 0, 0)
self.venv_ver = (0, 0, 0)
@@ -732,6 +715,33 @@ class SphinxDependencyChecker(MissingCheckers):
self.conf = prefix + "Documentation/conf.py"
self.requirement_file = prefix + "Documentation/sphinx/requirements.txt"
+ def get_install_progs(self, progs, cmd, extra=None):
+ """
+ Check for missing dependencies using the provided program mapping.
+
+ The actual distro-specific programs are mapped via progs argument.
+ """
+ install = self.deps.check_missing(progs)
+
+ if self.verbose_warn_install:
+ self.deps.warn_install()
+
+ if not install:
+ return
+
+ if cmd:
+ if self.verbose_warn_install:
+ msg = "You should run:"
+ else:
+ msg = ""
+
+ if extra:
+ msg += "\n\t" + extra.replace("\n", "\n\t")
+
+ return(msg + "\n\tsudo " + cmd + " " + install)
+
+ return None
+
#
# Distro-specific hints methods
#
@@ -772,12 +782,7 @@ class SphinxDependencyChecker(MissingCheckers):
self.check_program("dvipng", DepManager.PDF_MANDATORY)
- if self.check_missing(progs):
- return
-
- if self.verbose_warn_install:
- print("You should run:")
- print(f"\n\tsudo apt-get install {self.install}")
+ return self.get_install_progs(progs, "apt-get install")
def give_redhat_hints(self):
"""
@@ -838,18 +843,16 @@ class SphinxDependencyChecker(MissingCheckers):
self.deps.add_package("python39", DepManager.SYSTEM_MANDATORY)
self.recommend_python = True
- if self.first_hint:
- print("Note: RHEL-based distros typically require extra repositories.\n" \
- "For most, enabling epel and crb are enough:\n" \
- "\tsudo dnf install -y epel-release", \
- "\tsudo dnf config-manager --set-enabled crb\n" \
- "Yet, some may have other required repositories. Those commands could be useful:\n" \
- "\tsudo dnf repolist all\n" \
- "\tsudo dnf repoquery --available --info <pkgs>\n",
- "\tsudo dnf config-manager --set-enabled '*' # enable all - probably not what you want")
-
- self.first_hint = False
-
+ if not self.distro_msg:
+ self.distro_msg = \
+ "Note: RHEL-based distros typically require extra repositories.\n" \
+ "For most, enabling epel and crb are enough:\n" \
+ "\tsudo dnf install -y epel-release\n" \
+ "\tsudo dnf config-manager --set-enabled crb\n" \
+ "Yet, some may have other required repositories. Those commands could be useful:\n" \
+ "\tsudo dnf repolist all\n" \
+ "\tsudo dnf repoquery --available --info <pkgs>\n" \
+ "\tsudo dnf config-manager --set-enabled '*' # enable all - probably not what you want"
if self.pdf:
pdf_pkgs = [
@@ -868,13 +871,7 @@ class SphinxDependencyChecker(MissingCheckers):
if not fedora and rel == 8:
self.deps.del_package("texlive-ctex")
- if self.check_missing(progs):
- return
-
- if self.verbose_warn_install:
- print("You should run:")
-
- print(f"\n\tsudo dnf install -y {self.install}")
+ return self.get_install_progs(progs, "dnf install")
def give_opensuse_hints(self):
"""
@@ -945,12 +942,7 @@ class SphinxDependencyChecker(MissingCheckers):
if self.pdf:
self.check_missing_tex()
- if self.check_missing(progs):
- return
-
- if self.verbose_warn_install:
- print("You should run:")
- print(f"\n\tsudo zypper install --no-recommends {self.install}")
+ return self.get_install_progs(progs, "zypper install --no-recommends")
def give_mageia_hints(self):
"""
@@ -995,12 +987,7 @@ class SphinxDependencyChecker(MissingCheckers):
self.check_missing_file(pdf_pkgs, noto_sans, DepManager.PDF_MANDATORY)
self.check_rpm_missing(tex_pkgs, DepManager.PDF_MANDATORY)
- if self.check_missing(progs):
- return
-
- if self.verbose_warn_install:
- print("You should run:")
- print(f"\n\tsudo {packager_cmd} {self.install}")
+ return self.get_install_progs(progs, packager_cmd)
def give_arch_linux_hints(self):
"""
@@ -1023,20 +1010,15 @@ class SphinxDependencyChecker(MissingCheckers):
]
if self.pdf:
- self.check_pacman_missing(archlinux_tex_pkgs, DepManager.PDF_MANDATORY)
+ self.check_pacman_missing(archlinux_tex_pkgs,
+ DepManager.PDF_MANDATORY)
- self.check_missing_file(
- ["/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc"],
- "noto-fonts-cjk",
- 2,
- )
+ self.check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc"],
+ "noto-fonts-cjk",
+ DepManager.PDF_MANDATORY)
- if self.check_missing(progs):
- return
- if self.verbose_warn_install:
- print("You should run:")
- print(f"\n\tsudo pacman -S {self.install}")
+ return self.get_install_progs(progs, "pacman -S")
def give_gentoo_hints(self):
"""
@@ -1065,13 +1047,6 @@ class SphinxDependencyChecker(MissingCheckers):
for package, files in pdf_pkgs.items():
self.check_missing_file(files, package, DepManager.PDF_MANDATORY)
- if self.check_missing(progs):
- return
-
- if self.verbose_warn_install:
- print("You should run:")
- print("\n")
-
# Handling dependencies is a nightmare, as Gentoo refuses to emerge
# some packages if there's no package.use file describing them.
# To make it worse, compilation flags shall also be present there
@@ -1104,7 +1079,10 @@ class SphinxDependencyChecker(MissingCheckers):
"zziblib": "dev-libs/zziplib sdl",
}
- if self.first_hint:
+ extra_cmds = ""
+ if not self.distro_msg:
+ self.distro_msg = "Note: Gentoo requires package.use to be adjusted before emerging packages"
+
use_base = "/etc/portage/package.use"
files = glob(f"{use_base}/*")
@@ -1148,23 +1126,23 @@ class SphinxDependencyChecker(MissingCheckers):
# emit a code to setup missing USE
if install:
- print(f"\tsudo su -c 'echo \"{portage}\" > {use_base}/{fname}'")
-
- self.first_hint = False
+ extra_cmds += (f"sudo su -c 'echo \"{portage}\" > {use_base}/{fname}'\n")
# Now, we can use emerge and let it respect USE
- print(f"\tsudo emerge --ask --changed-use --binpkg-respect-use=y {self.install}")
+ return self.get_install_progs(progs,
+ "emerge --ask --changed-use --binpkg-respect-use=y",
+ extra_cmds)
- #
- # Dispatch the check to an os_specific hinter
- #
-
- def check_distros(self):
+ def get_install(self):
"""
- OS-specific hints logic. Seeks for a hinter. If found, provide
- package-manager-specific install commands.
+ OS-specific hints logic. Seeks for a hinter. If found, use it to
+ provide package-manager specific install commands.
- Otherwise, just lists the missing dependencies.
+ Otherwise, outputs install instructions for the meta-packages.
+
+ Returns a string with the command to be executed to install the
+ the needed packages, if distro found. Otherwise, return just a
+ list of packages that require installation.
"""
os_hints = {
re.compile("Red Hat Enterprise Linux"): self.give_redhat_hints,
@@ -1195,9 +1173,7 @@ class SphinxDependencyChecker(MissingCheckers):
# If the OS is detected, use per-OS hint logic
for regex, os_hint in os_hints.items():
if regex.search(self.system_release):
- os_hint()
-
- return
+ return os_hint()
#
# Fall-back to generic hint code for other distros
@@ -1207,11 +1183,12 @@ class SphinxDependencyChecker(MissingCheckers):
if self.pdf:
self.check_missing_tex()
- self.check_missing(progs)
+ self.distro_msg = \
+ f"I don't know distro {self.system_release}.\n" \
+ "So, I can't provide you a hint with the install procedure.\n" \
+ "There are likely missing dependencies.\n"
- print(f"I don't know distro {self.system_release}.")
- print("So, I can't provide you a hint with the install procedure.")
- print("There are likely missing dependencies.")
+ return self.get_install_progs(progs, None)
#
# Common dependencies
@@ -1336,7 +1313,6 @@ class SphinxDependencyChecker(MissingCheckers):
self.pdf = False
self.deps.optional = 0
- self.install = ""
old_verbose = self.verbose_warn_install
self.verbose_warn_install = 0
@@ -1344,7 +1320,9 @@ class SphinxDependencyChecker(MissingCheckers):
self.deps.add_package("python-sphinx", DepManager.PYTHON_MANDATORY)
- self.check_distros()
+ cmd = self.get_install()
+ if cmd:
+ print(cmd)
self.deps.need = old_need
self.deps.optional = old_optional
@@ -1511,7 +1489,14 @@ class SphinxDependencyChecker(MissingCheckers):
self.check_program("latexmk", DepManager.PDF_MANDATORY)
# Do distro-specific checks and output distro-install commands
- self.check_distros()
+ cmd = self.get_install()
+ if cmd:
+ print(cmd)
+
+ # If distro requires some special instructions, print here.
+ # Please notice that get_install() needs to be called first.
+ if self.distro_msg:
+ print("\n" + self.distro_msg)
if not self.python_cmd:
if self.need == 1:
--
2.50.1
next prev parent reply other threads:[~2025-08-12 15:53 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-12 15:52 [PATCH v2 00/39] Translate sphinx-pre-install to Python Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 01/39] scripts: sphinx-pre-install: fix version check for Fedora Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 02/39] scripts: sphinx-pre-install: rename it to scripts/sphinx-pre-install.pl Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 03/39] scripts: sphinx-pre-install: Convert script to Python Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 04/39] scripts: sphinx-pre-install: Make it compatible with Python 3.6 Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 05/39] scripts: sphinx-pre-install: run on a supported version Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 06/39] scripts: sphinx-pre-install: drop obsolete routines Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 07/39] scripts: sphinx-pre-install: drop support for old virtualenv Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 08/39] scripts: sphinx-pre-install: Address issues with OpenSUSE Leap 15.x Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 09/39] scripts: sphinx-pre-install: fix opensuse Leap hint for PyYAML Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 10/39] scripts: sphinx-pre-install: fix support for gentoo Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 11/39] scripts: sphinx-pre-install: Address issues with OpenSUSE Tumbleweed Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 12/39] scripts: sphinx-pre-install: only show portage hints once Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 13/39] scripts: sphinx-pre-install: cleanup rhel support Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 14/39] scripts: sphinx-pre-install: output Python and docutils version Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 15/39] scripts: sphinx-pre-install: add a missing f-string marker Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 16/39] scripts: sphinx-pre-install: fix Leap support for rsvg-convert Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 17/39] scripts: sphinx-pre-install: fix rhel recomendations Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 18/39] scripts: sphinx-pre-install: remove Scientific Linux Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 19/39] scripts: sphinx-pre-install: improve Gentoo package deps logic Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 20/39] scripts: sphinx-pre-install: fix OpenMandriva support Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 21/39] scripts: sphinx-pre-install: move package instructions to a new func Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 22/39] scripts: sphinx-pre-install: adjust a warning message Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 23/39] scripts: sphinx-pre-install: better handle Python min version Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 24/39] scripts: sphinx-pre-install: convert is_optional to a class Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 25/39] scripts: sphinx-pre-install: better handle RHEL-based distros Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 26/39] scripts: sphinx-pre-install: move missing logic to a separate class Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 27/39] scripts: sphinx-pre-install: move ancillary checkers " Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 28/39] scripts: sphinx-pre-install: add more generic checkers on a class Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 29/39] scripts: sphinx-pre-install: move get_system_release() Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 30/39] scripts: sphinx-pre-install: add documentation for the ancillary classes Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 31/39] scripts: sphinx-pre-install: add docstring documentation Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 32/39] scripts: sphinx-pre-install: fix several codingstyle issues Mauro Carvalho Chehab
2025-08-12 15:52 ` Mauro Carvalho Chehab [this message]
2025-08-12 15:52 ` [PATCH v2 34/39] docs: Makefile: switch to the new scripts/sphinx-pre-install.py Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 35/39] scripts: sphinx-pre-install.pl: get rid of the old script Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 36/39] scripts: sphinx-pre-install: update mandatory system deps Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 37/39] scripts: sphinx-pre-install: add support for RHEL8-based distros Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 38/39] scripts: sphinx-pre-install: add a warning for Debian-based distros Mauro Carvalho Chehab
2025-08-12 15:52 ` [PATCH v2 39/39] scripts: sphinx-pre-install: some adjustments related to venv Mauro Carvalho Chehab
2025-08-13 16:23 ` [PATCH v2 00/39] Translate sphinx-pre-install to Python Jonathan Corbet
-- strict thread matches above, loose matches on Subject: below --
2025-07-09 13:51 Mauro Carvalho Chehab
2025-07-09 13:52 ` [PATCH v2 33/39] scripts: sphinx-pre-install: rework install command logic 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=a6120449d9cc14346e867d1ef8944ae28ddbf3f6.1754992972.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 \
/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;
as well as URLs for NNTP newsgroup(s).