Fix the regression in calling sphinx-build for the non-autodoc case
that causes the build to fail if dev-python/sphinx isn't built
for the newest Python interpreter available.  To account for this,
we need to call sphinx-build as an executable (i.e. via python-exec).

Ideally, build_sphinx would be aware of which case it is used for,
and use appropriate invocation.  Unfortunately, we cannot do that
without breaking backwards compatibility.  However, we can simply check
if Sphinx is available via ${EPYTHON}, and fall back to calling
python-exec directly.  This is effectively equivalent to choosing
the specific invocation directly, as python-exec would have respected
the implementation specified by EPYTHON anyway if sphinx-build
executable was available for it.

Fixes: f6a17acb8b7c (...: Run sphinx-build via EPYTHON)
Signed-off-by: Michał Górny <mgo...@gentoo.org>
---
 eclass/python-utils-r1.eclass | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index c3726437cb68..362e55aed06f 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -1231,10 +1231,24 @@ build_sphinx() {
 
        sed -i -e 's:^intersphinx_mapping:disabled_&:' \
                "${dir}"/conf.py || die
-       # not all packages include the Makefile in pypi tarball
-       "${EPYTHON}" -m sphinx.cmd.build \
-               -b html -d "${dir}"/_build/doctrees "${dir}" \
-               "${dir}"/_build/html || die
+       # 1. not all packages include the Makefile in pypi tarball,
+       # so we call sphinx-build directly
+       # 2. if autodoc is used, we need to call sphinx via EPYTHON,
+       # to ensure that PEP 517 venv is respected
+       # 3. if autodoc is not used, then sphinx might not be installed
+       # for the current impl, so we need a fallback to sphinx-build
+       local command=( "${EPYTHON}" -m sphinx.cmd.build )
+       if ! "${EPYTHON}" -c "import sphinx.cmd.build" 2>/dev/null; then
+               command=( sphinx-build )
+       fi
+       command+=(
+               -b html
+               -d "${dir}"/_build/doctrees
+               "${dir}"
+               "${dir}"/_build/html
+       )
+       echo "${command[@]}" >&2
+       "${command[@]}" || die
 
        HTML_DOCS+=( "${dir}/_build/html/." )
 }
-- 
2.35.1


Reply via email to