Gentoo Archives: gentoo-dev

From: Patrick McLean <chutzpah@g.o>
To: "Michał Górny" <mgorny@g.o>
Cc: gentoo-dev@l.g.o, python@g.o
Subject: Re: [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_sphinx helper function
Date: Wed, 20 Nov 2019 18:23:40
Message-Id: 20191120102327.0edcafcd@patrickm.gaikai.org
In Reply to: [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_sphinx helper function by "Michał Górny"
1 Hi Michał,
2
3 Thanks for doing this work, it's always better to have standardized
4 ways of doing things.
5
6 On Wed, 20 Nov 2019 15:21:55 +0100
7 Michał Górny <mgorny@g.o> wrote:
8
9 <snip>
10
11 > +distutils_enable_sphinx() {
12 > + debug-print-function ${FUNCNAME} "${@}"
13 > + [[ ${#} -ge 1 ]] || die "${FUNCNAME} takes at least one arg: <subdir>"
14 > +
15 > + _DISTUTILS_SPHINX_SUBDIR=${1}
16 > + shift
17 > + _DISTUTILS_SPHINX_PLUGINS=( "${@}" )
18 > +
19 > + local deps autodoc=1 d
20 > + for d; do
21 > + if [[ ${d} == --no-autodoc ]]; then
22 > + autodoc=
23 > + else
24 > + deps+="
25 > + ${d}[\${PYTHON_USEDEP}]"
26 > + fi
27 > + done
28 > +
29 > + if [[ ! ${autodoc} && -n ${deps} ]]; then
30 > + die "${FUNCNAME}: do not pass --no-autodoc if external plugins are used"
31 > + fi
32 > + if [[ ${autodoc} ]]; then
33 > + deps="$(python_gen_any_dep "
34 > + dev-python/sphinx[\${PYTHON_USEDEP}]
35 > + ${deps}")"
36 > +
37 > + python_check_deps() {
38 > + use doc || return 0
39 > + local p
40 > + for p in "${_DISTUTILS_SPHINX_PLUGINS[@]}"; do
41 > + has_version "${p}[${PYTHON_USEDEP}]" || return 1
42 > + done
43 > + }
44
45 I think it would be better to put this code in sphinx_check_deps
46 (or some such) and define a python_check_deps that just calls
47 sphinx_check_deps. That would allow ebuilds that need to do more than
48 the sphinx stuff to not have to reimplement this.
49
50 > + else
51 > + deps="dev-python/sphinx"
52 > + fi
53 > +
54 > + python_compile_all() {
55 > + use doc || return
56 > +
57 > + cd "${_DISTUTILS_SPHINX_SUBDIR}" || die
58 > + [[ -f conf.py ]] ||
59 > + die "conf.py not found, distutils_enable_sphinx call wrong"
60 > +
61 > + if [[ ${_DISTUTILS_SPHINX_PLUGINS[0]} == --no-autodoc ]]; then
62 > + if grep -q 'sphinx\.ext\.autodoc' "conf.py"; then
63
64 Since this is just searching for a fixed string maybe
65 "grep -F -q 'sphinx.ext.autodoc'" is a bit nicer.
66
67 > + die "distutils_enable_sphinx: --no-autodoc passed but sphinx.ext.autodoc found in conf.py"
68 > + fi
69 > + else
70 > + if ! grep -q 'sphinx\.ext\.autodoc' "conf.py"; then
71 > + die "distutils_enable_sphinx: sphinx.ext.autodoc not found in conf.py, pass --no-autodoc"
72 > + fi
73 > + fi
74 > +
75 > + # disable intersphinx (internet use)
76 > + sed -e 's:^intersphinx_mapping:disabled_&:' -i conf.py || die
77 > + # not all packages include the Makefile in pypi tarball
78 > + sphinx-build -b html -d _build/doctrees . _build/html || die
79 > +
80 > + HTML_DOCS+=( "${_DISTUTILS_SPHINX_SUBDIR}/_build/html/." )
81 > + }
82
83 Same as above, I think it would be better to define this as
84 sphinx_compile, and define a python_compile_all that just calls it.
85 That way if an ebuild defines it's own python_compile_all it can call
86 sphinx_compile to get this functionality.
87
88 > +
89 > + IUSE+=" doc"
90 > + if [[ ${EAPI} == [56] ]]; then
91 > + DEPEND+=" doc? ( ${deps} )"
92 > + else
93 > + BDEPEND+=" doc? ( ${deps} )"
94 > + fi
95 > +
96 > + # we need to ensure successful return in case we're called last,
97 > + # otherwise Portage may wrongly assume sourcing failed
98 > + return 0
99 > +}
100 > +
101 > # @FUNCTION: distutils_enable_tests
102 > # @USAGE: <test-runner>
103 > # @DESCRIPTION:

Replies