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