1 |
version 2: now prepending the DOCS_BUILDER before calling |
2 |
python_gen_*_dep functions as suggested by @mgorny. (And this time the |
3 |
email should be plaintext as requested by David) |
4 |
|
5 |
Best regards, |
6 |
Andrew |
7 |
|
8 |
On 16/01/2021 14:49, Andrew Ammerlaan wrote: |
9 |
> python-single-r1 does not have the python_gen_any_dep function (unlike |
10 |
> python-r1). This makes dependency resolution fail if an ebuild tries to |
11 |
> enable doc building (using docs.eclass or distutils_enable_sphinx) while |
12 |
> DISTUTILS_SINGLE_IMPL is set and/or python-single-r1 is inherited. See |
13 |
> also bug: https://bugs.gentoo.org/704520 . The python_gen_cond_dep |
14 |
> function should be used instead in these cases. |
15 |
> |
16 |
> Therefore, I propose the following small changes to docs.eclass and |
17 |
> distutils-r1.eclass (in the next email), PR is open here: |
18 |
> https://github.com/gentoo/gentoo/pull/19078 |
19 |
> |
20 |
> Best regards, |
21 |
> Andrew |
22 |
> |
23 |
|
24 |
From 2f74a1175e706eda243d9e22532e10f8da9519ed Mon Sep 17 00:00:00 2001 |
25 |
From: Andrew Ammerlaan <andrewammerlaan@××××××.net> |
26 |
Date: Sat, 16 Jan 2021 14:28:53 +0100 |
27 |
Subject: [PATCH] eclass/docs.eclass: make compatible with python-single-r1 |
28 |
|
29 |
python-single-r1 does not have the pyhton_gen_any-dep |
30 |
function, use the pyhton_gen_cond_dep instead |
31 |
|
32 |
also a much needed update to the documentation |
33 |
of this eclass. Fixed typos, and added proper |
34 |
examples. |
35 |
|
36 |
Signed-off-by: Andrew Ammerlaan <andrewammerlaan@××××××.net> |
37 |
--- |
38 |
eclass/docs.eclass | 160 +++++++++++++++++++++++++++++++-------------- |
39 |
1 file changed, 110 insertions(+), 50 deletions(-) |
40 |
|
41 |
diff --git a/eclass/docs.eclass b/eclass/docs.eclass |
42 |
index adacae4abda64..97499c54b6ccf 100644 |
43 |
--- a/eclass/docs.eclass |
44 |
+++ b/eclass/docs.eclass |
45 |
@@ -10,20 +10,52 @@ |
46 |
# @SUPPORTED_EAPIS: 6 7 |
47 |
# @BLURB: A simple eclass to build documentation. |
48 |
# @DESCRIPTION: |
49 |
-# A simple eclass providing functions to build documentation. |
50 |
+# A simple eclass providing basic functions and variables to build |
51 |
+# documentation. |
52 |
# |
53 |
-# Please note that docs sets RDEPEND and DEPEND unconditionally |
54 |
-# for you. |
55 |
+# Please note that this eclass appends to RDEPEND and DEPEND |
56 |
+# unconditionally for you. |
57 |
# |
58 |
# This eclass also appends "doc" to IUSE, and sets HTML_DOCS |
59 |
-# to the location of the compiled documentation |
60 |
+# to the location of the compiled documentation automatically, |
61 |
+# 'einstalldocs' will then automatically install the documentation |
62 |
+# to the correct directory. |
63 |
# |
64 |
# The aim of this eclass is to make it easy to add additional |
65 |
-# doc builders. To do this, add a <DOCS_BUILDER>-deps and |
66 |
-# <DOCS_BUILDER>-build function for your doc builder. |
67 |
+# doc builders. To do this, add a <DOCS_BUILDER>_deps and |
68 |
+# <DOCS_BUILDER>_compile function for your doc builder. |
69 |
# For python based doc builders you can use the |
70 |
# python_append_deps function to append [${PYTHON_USEDEP}] |
71 |
# automatically to additional dependencies. |
72 |
+# |
73 |
+# Example use doxygen: |
74 |
+# @CODE |
75 |
+# DOCS_BUILDER="doxygen" |
76 |
+# DOCS_DEPEND="media-gfx/imagemagick" |
77 |
+# DOCS_DIR="docs" |
78 |
+# |
79 |
+# inherit docs |
80 |
+# |
81 |
+# ... |
82 |
+# |
83 |
+# src_compile() { |
84 |
+# default |
85 |
+# docs_compile |
86 |
+# } |
87 |
+# @CODE |
88 |
+# |
89 |
+# Example use mkdocs with distutils-r1: |
90 |
+# @CODE |
91 |
+# DOCS_BUILDER="mkdocs" |
92 |
+# DOCS_DEPEND="dev-python/mkdocs-material" |
93 |
+# DOCS_DIR="doc" |
94 |
+# |
95 |
+# PYTHON_COMPAT=( python3_{7,8,9} ) |
96 |
+# |
97 |
+# inherit distutils-r1 docs |
98 |
+# |
99 |
+# ... |
100 |
+# @CODE |
101 |
|
102 |
case "${EAPI:-0}" in |
103 |
0|1|2|3|4|5) |
104 |
@@ -50,41 +82,54 @@ esac |
105 |
# Path containing the doc builder config file(s). |
106 |
# |
107 |
# For sphinx this is the location of "conf.py" |
108 |
-# For mkdocs this is the location of "mkdocs.yml" |
109 |
# |
110 |
+# For mkdocs this is the location of "mkdocs.yml" |
111 |
# Note that mkdocs.yml often does not reside |
112 |
# in the same directory as the actual doc files |
113 |
# |
114 |
+# For doxygen the default name is Doxyfile, but |
115 |
+# package may use a non-standard name. If this |
116 |
+# is the case one should set DOCS_CONFIG_NAME to |
117 |
+# the correct name |
118 |
+# |
119 |
# Defaults to ${S} |
120 |
|
121 |
# @ECLASS-VARIABLE: DOCS_DEPEND |
122 |
# @DEFAULT_UNSET |
123 |
# @PRE_INHERIT |
124 |
# @DESCRIPTION: |
125 |
-# Sets additional dependencies to build docs. |
126 |
+# Sets additional dependencies required to build the |
127 |
+# documentation. |
128 |
# For sphinx and mkdocs these dependencies should |
129 |
-# be specified without [${PYTHON_USEDEP}], this |
130 |
+# be specified *without* [${PYTHON_USEDEP}], this |
131 |
# is added by the eclass. E.g. to depend on mkdocs-material: |
132 |
# |
133 |
+# @CODE |
134 |
# DOCS_DEPEND="dev-python/mkdocs-material" |
135 |
+# @CODE |
136 |
# |
137 |
-# This eclass appends to this variable, so you can |
138 |
-# call it later in your ebuild again if necessary. |
139 |
+# This eclass appends to this variable, this makes it |
140 |
+# possible to call it later in your ebuild again if |
141 |
+# necessary. |
142 |
|
143 |
# @ECLASS-VARIABLE: DOCS_AUTODOC |
144 |
# @PRE_INHERIT |
145 |
# @DESCRIPTION: |
146 |
# Sets whether to use sphinx.ext.autodoc/mkautodoc |
147 |
-# Defaults to 1 (True) for sphinx, and 0 (False) for mkdocs |
148 |
+# Defaults to 1 (True) for sphinx, and 0 (False) for mkdocs. |
149 |
+# Not relevant for doxygen. |
150 |
|
151 |
# @ECLASS-VARIABLE: DOCS_OUTDIR |
152 |
# @DESCRIPTION: |
153 |
-# Sets where the compiled files will be put. |
154 |
-# There's no real reason to change this, but this |
155 |
-# variable is useful if you want to overwrite the HTML_DOCS |
156 |
-# added by this eclass. E.g.: |
157 |
+# Sets the directory where the documentation should |
158 |
+# be built into. There is no real reason to change this. |
159 |
+# However, this variable is useful if the package should |
160 |
+# also install other HTML files. |
161 |
# |
162 |
+# Example use: |
163 |
+# @CODE |
164 |
# HTML_DOCS=( "${yourdocs}" "${DOCS_OUTDIR}/." ) |
165 |
+# @CODE |
166 |
# |
167 |
# Defaults to ${S}/_build/html |
168 |
|
169 |
@@ -93,18 +138,19 @@ esac |
170 |
# Name of the doc builder config file. |
171 |
# |
172 |
# Only relevant for doxygen, as it allows |
173 |
-# config files with non-standard names |
174 |
+# config files with non-standard names. |
175 |
+# Does not do anything for mkdocs or sphinx. |
176 |
# |
177 |
# Defaults to Doxyfile for doxygen |
178 |
|
179 |
if [[ ! ${_DOCS} ]]; then |
180 |
|
181 |
-# For the python based DOCS_BUILDERS we need to inherit python-any-r1 |
182 |
+# For the python based DOCS_BUILDERS we need to inherit any python eclass |
183 |
case ${DOCS_BUILDER} in |
184 |
"sphinx"|"mkdocs") |
185 |
# We need the python_gen_any_dep function |
186 |
- if [[ ! ${_PYTHON_R1} && ! ${_PYTHON_ANY_R1} ]]; then |
187 |
- die "python-r1 or python-any-r1 needs to be inherited as well to use |
188 |
python based documentation builders" |
189 |
+ if [[ ! ${_PYTHON_R1} && ! ${_PYTHON_ANY_R1} && ! |
190 |
${_PYTHON_SINGLE_R1} ]]; then |
191 |
+ die "distutils-r1, python-r1, python-single-r1 or python-any-r1 |
192 |
needs to be inherited to use python based documentation builders" |
193 |
fi |
194 |
;; |
195 |
"doxygen") |
196 |
@@ -119,6 +165,7 @@ case ${DOCS_BUILDER} in |
197 |
esac |
198 |
|
199 |
# @FUNCTION: python_append_dep |
200 |
+# @INTERNAL |
201 |
# @DESCRIPTION: |
202 |
# Appends [\${PYTHON_USEDEP}] to all dependencies |
203 |
# for python based DOCS_BUILDERs such as mkdocs or |
204 |
@@ -135,6 +182,7 @@ python_append_deps() { |
205 |
} |
206 |
|
207 |
# @FUNCTION: sphinx_deps |
208 |
+# @INTERNAL |
209 |
# @DESCRIPTION: |
210 |
# Sets dependencies for sphinx |
211 |
sphinx_deps() { |
212 |
@@ -142,28 +190,29 @@ sphinx_deps() { |
213 |
|
214 |
: ${DOCS_AUTODOC:=1} |
215 |
|
216 |
+ deps="dev-python/sphinx[\${PYTHON_USEDEP}] |
217 |
+ ${DOCS_DEPEND}" |
218 |
if [[ ${DOCS_AUTODOC} == 0 ]]; then |
219 |
if [[ -n "${DOCS_DEPEND}" ]]; then |
220 |
die "${FUNCNAME}: do not set DOCS_AUTODOC to 0 if external plugins |
221 |
are used" |
222 |
- else |
223 |
- DOCS_DEPEND="$(python_gen_any_dep " |
224 |
- dev-python/sphinx[\${PYTHON_USEDEP}]")" |
225 |
fi |
226 |
- elif [[ ${DOCS_AUTODOC} == 1 ]]; then |
227 |
- DOCS_DEPEND="$(python_gen_any_dep " |
228 |
- dev-python/sphinx[\${PYTHON_USEDEP}] |
229 |
- ${DOCS_DEPEND}")" |
230 |
- else |
231 |
+ elif [[ ${DOCS_AUTODOC} != 0 && ${DOCS_AUTODOC} != 1 ]]; then |
232 |
die "${FUNCNAME}: DOCS_AUTODOC should be set to 0 or 1" |
233 |
fi |
234 |
+ if [[ ${_PYTHON_SINGLE_R1} ]]; then |
235 |
+ DOCS_DEPEND="$(python_gen_cond_dep "${deps}")" |
236 |
+ else |
237 |
+ DOCS_DEPEND="$(python_gen_any_dep "${deps}")" |
238 |
+ fi |
239 |
} |
240 |
|
241 |
# @FUNCTION: sphinx_compile |
242 |
+# @INTERNAL |
243 |
# @DESCRIPTION: |
244 |
# Calls sphinx to build docs. |
245 |
# |
246 |
-# If you overwrite src_compile or python_compile_all |
247 |
-# do not call this function, call docs_compile instead |
248 |
+# If you overwrite python_compile_all do not call |
249 |
+# this function, call docs_compile instead |
250 |
sphinx_compile() { |
251 |
debug-print-function ${FUNCNAME} |
252 |
use doc || return |
253 |
@@ -190,6 +239,7 @@ sphinx_compile() { |
254 |
} |
255 |
|
256 |
# @FUNCTION: mkdocs_deps |
257 |
+# @INTERNAL |
258 |
# @DESCRIPTION: |
259 |
# Sets dependencies for mkdocs |
260 |
mkdocs_deps() { |
261 |
@@ -197,26 +247,28 @@ mkdocs_deps() { |
262 |
|
263 |
: ${DOCS_AUTODOC:=0} |
264 |
|
265 |
+ deps="dev-python/mkdocs[\${PYTHON_USEDEP}] |
266 |
+ ${DOCS_DEPEND}" |
267 |
if [[ ${DOCS_AUTODOC} == 1 ]]; then |
268 |
- DOCS_DEPEND="$(python_gen_any_dep " |
269 |
- dev-python/mkdocs[\${PYTHON_USEDEP}] |
270 |
- dev-python/mkautodoc[\${PYTHON_USEDEP}] |
271 |
- ${DOCS_DEPEND}")" |
272 |
- elif [[ ${DOCS_AUTODOC} == 0 ]]; then |
273 |
- DOCS_DEPEND="$(python_gen_any_dep " |
274 |
- dev-python/mkdocs[\${PYTHON_USEDEP}] |
275 |
- ${DOCS_DEPEND}")" |
276 |
- else |
277 |
+ deps="dev-python/mkautodoc[\${PYTHON_USEDEP}] |
278 |
+ ${deps}" |
279 |
+ elif [[ ${DOCS_AUTODOC} != 0 && ${DOCS_AUTODOC} != 1 ]]; then |
280 |
die "${FUNCNAME}: DOCS_AUTODOC should be set to 0 or 1" |
281 |
fi |
282 |
+ if [[ ${_PYTHON_SINGLE_R1} ]]; then |
283 |
+ DOCS_DEPEND="$(python_gen_cond_dep "${deps}")" |
284 |
+ else |
285 |
+ DOCS_DEPEND="$(python_gen_any_dep "${deps}")" |
286 |
+ fi |
287 |
} |
288 |
|
289 |
# @FUNCTION: mkdocs_compile |
290 |
+# @INTERNAL |
291 |
# @DESCRIPTION: |
292 |
# Calls mkdocs to build docs. |
293 |
# |
294 |
-# If you overwrite src_compile or python_compile_all |
295 |
-# do not call this function, call docs_compile instead |
296 |
+# If you overwrite python_compile_all do not call |
297 |
+# this function, call docs_compile instead |
298 |
mkdocs_compile() { |
299 |
debug-print-function ${FUNCNAME} |
300 |
use doc || return |
301 |
@@ -236,6 +288,7 @@ mkdocs_compile() { |
302 |
} |
303 |
|
304 |
# @FUNCTION: doxygen_deps |
305 |
+# @INTERNAL |
306 |
# @DESCRIPTION: |
307 |
# Sets dependencies for doxygen |
308 |
doxygen_deps() { |
309 |
@@ -246,11 +299,9 @@ doxygen_deps() { |
310 |
} |
311 |
|
312 |
# @FUNCTION: doxygen_compile |
313 |
+# @INTERNAL |
314 |
# @DESCRIPTION: |
315 |
# Calls doxygen to build docs. |
316 |
-# |
317 |
-# If you overwrite src_compile or python_compile_all |
318 |
-# do not call this function, call docs_compile instead |
319 |
doxygen_compile() { |
320 |
debug-print-function ${FUNCNAME} |
321 |
use doc || return |
322 |
@@ -273,12 +324,21 @@ doxygen_compile() { |
323 |
# @DESCRIPTION: |
324 |
# Calls DOCS_BUILDER and sets HTML_DOCS |
325 |
# |
326 |
-# This function must be called in global scope. Take care not to |
327 |
-# overwrite the variables set by it. Has support for distutils-r1 |
328 |
-# eclass, but only if this eclass is inherited *after* |
329 |
-# distutils-r1. If you need to extend src_compile() or |
330 |
-# python_compile_all(), you can call the original implementation |
331 |
-# as docs_compile. |
332 |
+# This function must be called in src_compile. Take care not to |
333 |
+# overwrite the variables set by it. If distutils-r1 is inherited |
334 |
+# *before* this eclass, than docs_compile will be automatically |
335 |
+# added to python_compile_all() and there is no need to call |
336 |
+# it manually. Note that this function checks if USE="doc" is |
337 |
+# enabled, and if not automatically exits. Therefore, there is |
338 |
+# no need to wrap this function in a if statement. |
339 |
+# |
340 |
+# Example use: |
341 |
+# @CODE |
342 |
+# src_compile() { |
343 |
+# default |
344 |
+# docs_compile |
345 |
+# } |
346 |
+# @CODE |
347 |
docs_compile() { |
348 |
debug-print-function ${FUNCNAME} |
349 |
use doc || return |