The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Chen Miao <chenmiao.ku@gmail.com>
To: corbet@lwn.net, alexs@kernel.org, si.yanteng@linux.dev,
	skhan@linuxfoundation.org, dzm91@hust.edu.cn, mchehab@kernel.org
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Chen Miao <chenmiao.ku@gmail.com>
Subject: [PATCH v1 1/2] docs: sphinx-pre-install: add macOS Homebrew support
Date: Sun,  9 Aug 2026 18:19:20 +0800	[thread overview]
Message-ID: <20260809101923.13176-2-chenmiao.ku@gmail.com> (raw)
In-Reply-To: <20260809101923.13176-1-chenmiao.ku@gmail.com>

The dependency checker currently reports an unknown distribution on macOS
and cannot provide installation hints.

Detect macOS and include its product version in the status output. Use
Homebrew for formula dependencies and install MacTeX as a cask without
sudo. Keep PyYAML in the virtual environment requirements because
Homebrew does not provide a PyYAML formula.

Document the macOS setup and the --no-pdf option.

Signed-off-by: Chen Miao <chenmiao.ku@gmail.com>
---
 Documentation/doc-guide/sphinx.rst            |  7 ++
 .../translations/zh_CN/doc-guide/sphinx.rst   |  5 ++
 Documentation/translations/zh_CN/how-to.rst   |  6 ++
 tools/docs/sphinx-pre-install                 | 89 ++++++++++++++++++-
 4 files changed, 106 insertions(+), 1 deletion(-)

diff --git a/Documentation/doc-guide/sphinx.rst b/Documentation/doc-guide/sphinx.rst
index 51c370260..62aca56b8 100644
--- a/Documentation/doc-guide/sphinx.rst
+++ b/Documentation/doc-guide/sphinx.rst
@@ -131,6 +131,13 @@ It supports two optional parameters:
 ``--no-virtualenv``
 	Use OS packaging for Sphinx instead of Python virtual environment.
 
+On macOS, the script uses Homebrew for system dependencies. Homebrew
+commands are printed without ``sudo``. The PDF dependencies are provided by
+the ``mactex`` cask; use ``--no-pdf`` when only building HTML documentation.
+The default virtualenv mode is recommended on macOS because PyYAML is
+installed from ``Documentation/sphinx/requirements.txt`` rather than from a
+Homebrew formula.
+
 Installing Sphinx Minimal Version
 ---------------------------------
 
diff --git a/Documentation/translations/zh_CN/doc-guide/sphinx.rst b/Documentation/translations/zh_CN/doc-guide/sphinx.rst
index 3375c6f3a..154142318 100644
--- a/Documentation/translations/zh_CN/doc-guide/sphinx.rst
+++ b/Documentation/translations/zh_CN/doc-guide/sphinx.rst
@@ -110,6 +110,11 @@ PDF和LaTeX构建
 
 	使用Sphinx的系统打包,而不是Python虚拟环境。
 
+在 macOS 上,该脚本使用 Homebrew 安装系统依赖,输出的 Homebrew 命令不需要
+``sudo``。PDF 依赖通过 ``mactex`` cask 提供;如果只构建 HTML 文档,请使用
+``--no-pdf``。macOS 用户建议使用默认的 Python 虚拟环境,因为 PyYAML 会从
+``Documentation/sphinx/requirements.txt`` 安装,而不是通过 Homebrew 安装。
+
 Sphinx构建
 ==========
 
diff --git a/Documentation/translations/zh_CN/how-to.rst b/Documentation/translations/zh_CN/how-to.rst
index 9ec2384e1..e8c91d81a 100644
--- a/Documentation/translations/zh_CN/how-to.rst
+++ b/Documentation/translations/zh_CN/how-to.rst
@@ -102,6 +102,12 @@ Linux 发行版和简单地使用 Linux 命令行,那么可以迅速开始了
 开头的命令。**请注意**,最新版本 Sphinx 的文档编译速度有极大提升,强烈建议
 您通过 pip/pypi 安装最新版本 Sphinx。
 
+如果您使用 macOS,脚本会使用 Homebrew 输出安装命令,Homebrew 命令不需要
+sudo。PDF 构建所需的 MacTeX 通过 Homebrew cask 安装;如果只构建 HTML 文档,
+可以执行 ``./tools/docs/sphinx-pre-install --no-pdf``。macOS 用户建议使用默认
+的 Python 虚拟环境,因为 PyYAML 会从 ``Documentation/sphinx/requirements.txt``
+安装,而不是通过 Homebrew 安装。
+
 如果您处于一个多用户环境中,为了避免对其他人造成影响,建议您配置单用户
 sphinx 虚拟环境,即只需要执行::
 
diff --git a/tools/docs/sphinx-pre-install b/tools/docs/sphinx-pre-install
index 965c9b093..51a296cc7 100755
--- a/tools/docs/sphinx-pre-install
+++ b/tools/docs/sphinx-pre-install
@@ -518,6 +518,24 @@ class MissingCheckers(AncillaryMethods):
         a decent coverage.
         """
 
+        if sys.platform == "darwin":
+            sw_vers = self.which("sw_vers")
+            if sw_vers:
+                try:
+                    result = self.run(
+                        [sw_vers, "-productVersion"],
+                        capture_output=True,
+                        text=True,
+                        check=True,
+                    )
+                    version = result.stdout.strip()
+                    if version:
+                        return f"macOS {version}"
+                except (subprocess.CalledProcessError, FileNotFoundError):
+                    pass
+
+            return "macOS"
+
         system_release = ""
 
         if self.which("lsb_release"):
@@ -716,6 +734,69 @@ class SphinxDependencyChecker(MissingCheckers):
 
         return self.get_install_progs(progs, "apt-get install")
 
+    def give_macos_hints(self):
+        """
+        Provide package installation hints for macOS using Homebrew.
+
+        Homebrew formulae and casks must not be installed with sudo. MacTeX
+        is a cask, while the other dependencies are formulae.
+        """
+        if not self.which("brew"):
+            if not self.distro_msg:
+                self.deps.add_package("Homebrew", DepManager.SYSTEM_MANDATORY)
+                self.deps.check_missing({})
+                self.deps.warn_install()
+                self.distro_msg = \
+                    "Homebrew is required for macOS support. Install it from " \
+                    "https://brew.sh/ and re-run this script."
+            return None
+
+        progs = {
+            "Pod::Usage":    "perl",
+            "convert":       "imagemagick",
+            "dot":           "graphviz",
+            "ensurepip":     "python",
+            "python-sphinx": "sphinx-doc",
+            "rsvg-convert":   "librsvg",
+            "xelatex":        "mactex",
+            "latexmk":        "mactex",
+        }
+
+        install = self.deps.check_missing(progs)
+
+        if self.verbose_warn_install:
+            self.deps.warn_install()
+
+        if not install:
+            return None
+
+        formulae = set()
+        casks = set()
+        for prog in self.deps.missing:
+            if prog == "yaml":
+                self.distro_msg = \
+                    "PyYAML is not provided as a Homebrew formula. Use the " \
+                    "default virtualenv mode so it is installed from " \
+                    "Documentation/sphinx/requirements.txt."
+                continue
+
+            package = progs.get(prog, prog)
+            if package == "mactex":
+                casks.add(package)
+            else:
+                formulae.add(package)
+
+        commands = []
+        if formulae:
+            commands.append("\tbrew install " + " ".join(sorted(formulae)))
+        if casks:
+            commands.append("\tbrew install --cask " + " ".join(sorted(casks)))
+
+        if not commands:
+            return None
+
+        return "\nYou should run:\n" + "\n".join(commands)
+
     def give_redhat_hints(self):
         """
         Provide package installation hints for RedHat-based distros
@@ -1138,6 +1219,8 @@ class SphinxDependencyChecker(MissingCheckers):
             re.compile("Kali"):                       self.give_debian_hints,
             re.compile("Mint"):                       self.give_debian_hints,
 
+            re.compile("macOS"):                      self.give_macos_hints,
+
             re.compile("openSUSE"):                   self.give_opensuse_hints,
 
             re.compile("Mageia"):                     self.give_mageia_hints,
@@ -1458,7 +1541,11 @@ class SphinxDependencyChecker(MissingCheckers):
         self.check_program("dot", DepManager.SYSTEM_OPTIONAL)
         self.check_program("convert", DepManager.SYSTEM_OPTIONAL)
 
-        self.check_python_module("yaml")
+        # PyYAML is installed from Documentation/sphinx/requirements.txt in
+        # the virtualenv recommended on macOS. Homebrew does not provide a
+        # PyYAML formula, so do not ask for a nonexistent brew package here.
+        if not (sys.platform == "darwin" and self.virtualenv and self.need_pip):
+            self.check_python_module("yaml")
 
         if self.pdf:
             self.check_program("xelatex", DepManager.PDF_MANDATORY)
-- 
2.50.1 (Apple Git-155)


  reply	other threads:[~2026-08-09 10:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-09 10:19 [PATCH v1 0/2] docs: sphinx-pre-install: improve dependency checks Chen Miao
2026-08-09 10:19 ` Chen Miao [this message]
2026-08-09 13:02   ` [PATCH v1 1/2] docs: sphinx-pre-install: add macOS Homebrew support Weijie Yuan
2026-08-09 13:21     ` Dongliang Mu
2026-08-09 14:11       ` Weijie Yuan
2026-08-09 19:07         ` Chen Miao
2026-08-09 22:34           ` Jonathan Corbet
2026-08-10  3:47             ` Weijie Yuan
2026-08-10  5:12               ` Chen Miao
2026-08-09 18:59     ` Chen Miao
2026-08-09 10:19 ` [PATCH v1 2/2] docs: sphinx-pre-install: check GNU Make version Chen Miao
2026-08-09 17:18   ` Mauro Carvalho Chehab
2026-08-09 19:11     ` Chen Miao

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=20260809101923.13176-2-chenmiao.ku@gmail.com \
    --to=chenmiao.ku@gmail.com \
    --cc=alexs@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dzm91@hust.edu.cn \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=si.yanteng@linux.dev \
    --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