/[gentoo-x86]/eclass/distutils-r1.eclass
Gentoo

Contents of /eclass/distutils-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.71 - (show annotations) (download)
Tue May 21 01:31:02 2013 UTC (10 months, 4 weeks ago) by floppym
Branch: MAIN
Changes since 1.70: +2 -1 lines
Set PYTHON_REQUIRED_USE, and add it to REQUIRED_USE in distutils-r1.

1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/distutils-r1.eclass,v 1.70 2013/04/30 05:36:19 mgorny Exp $
4
5 # @ECLASS: distutils-r1
6 # @MAINTAINER:
7 # Python team <python@gentoo.org>
8 # @AUTHOR:
9 # Author: Michał Górny <mgorny@gentoo.org>
10 # Based on the work of: Krzysztof Pawlik <nelchael@gentoo.org>
11 # @BLURB: A simple eclass to build Python packages using distutils.
12 # @DESCRIPTION:
13 # A simple eclass providing functions to build Python packages using
14 # the distutils build system. It exports phase functions for all
15 # the src_* phases. Each of the phases runs two pseudo-phases:
16 # python_..._all() (e.g. python_prepare_all()) once in ${S}, then
17 # python_...() (e.g. python_prepare()) for each implementation
18 # (see: python_foreach_impl() in python-r1).
19 #
20 # In distutils-r1_src_prepare(), the 'all' function is run before
21 # per-implementation ones (because it creates the implementations),
22 # per-implementation functions are run in a random order.
23 #
24 # In remaining phase functions, the per-implementation functions are run
25 # before the 'all' one, and they are ordered from the least to the most
26 # preferred implementation (so that 'better' files overwrite 'worse'
27 # ones).
28 #
29 # If the ebuild doesn't specify a particular pseudo-phase function,
30 # the default one will be used (distutils-r1_...). Defaults are provided
31 # for all per-implementation pseudo-phases, python_prepare_all()
32 # and python_install_all(); whenever writing your own pseudo-phase
33 # functions, you should consider calling the defaults (and especially
34 # distutils-r1_python_prepare_all).
35 #
36 # Please note that distutils-r1 sets RDEPEND and DEPEND unconditionally
37 # for you.
38 #
39 # Also, please note that distutils-r1 will always inherit python-r1
40 # as well. Thus, all the variables defined and documented there are
41 # relevant to the packages using distutils-r1.
42 #
43 # For more information, please see the python-r1 Developer's Guide:
44 # http://www.gentoo.org/proj/en/Python/python-r1/dev-guide.xml
45
46 case "${EAPI:-0}" in
47 0|1|2|3)
48 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
49 ;;
50 4|5)
51 ;;
52 *)
53 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
54 ;;
55 esac
56
57 # @ECLASS-VARIABLE: DISTUTILS_OPTIONAL
58 # @DEFAULT_UNSET
59 # @DESCRIPTION:
60 # If set to a non-null value, distutils part in the ebuild will
61 # be considered optional. No dependencies will be added and no phase
62 # functions will be exported.
63 #
64 # If you enable DISTUTILS_OPTIONAL, you have to set proper dependencies
65 # for your package (using ${PYTHON_DEPS}) and to either call
66 # distutils-r1 default phase functions or call the build system
67 # manually.
68
69 # @ECLASS-VARIABLE: DISTUTILS_SINGLE_IMPL
70 # @DEFAULT_UNSET
71 # @DESCRIPTION:
72 # If set to a non-null value, the ebuild will support setting a single
73 # Python implementation only. It will effectively replace the python-r1
74 # eclass inherit with python-single-r1.
75 #
76 # Note that inheriting python-single-r1 will cause pkg_setup()
77 # to be exported. It must be run in order for the eclass functions
78 # to function properly.
79
80 if [[ ! ${_DISTUTILS_R1} ]]; then
81
82 inherit eutils
83
84 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
85 inherit multiprocessing python-r1
86 else
87 inherit python-single-r1
88 fi
89
90 fi
91
92 if [[ ! ${DISTUTILS_OPTIONAL} ]]; then
93 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
94 fi
95
96 if [[ ! ${_DISTUTILS_R1} ]]; then
97
98 if [[ ! ${DISTUTILS_OPTIONAL} ]]; then
99 RDEPEND=${PYTHON_DEPS}
100 DEPEND=${PYTHON_DEPS}
101 REQUIRED_USE=${PYTHON_REQUIRED_USE}
102 fi
103
104 # @ECLASS-VARIABLE: PATCHES
105 # @DEFAULT_UNSET
106 # @DESCRIPTION:
107 # An array containing patches to be applied to the sources before
108 # copying them.
109 #
110 # If unset, no custom patches will be applied.
111 #
112 # Please note, however, that at some point the eclass may apply
113 # additional distutils patches/quirks independently of this variable.
114 #
115 # Example:
116 # @CODE
117 # PATCHES=( "${FILESDIR}"/${P}-make-gentoo-happy.patch )
118 # @CODE
119
120 # @ECLASS-VARIABLE: DOCS
121 # @DEFAULT_UNSET
122 # @DESCRIPTION:
123 # An array containing documents installed using dodoc. The files listed
124 # there must exist in the directory from which
125 # distutils-r1_python_install_all() is run (${S} by default).
126 #
127 # If unset, the function will instead look up files matching default
128 # filename pattern list (from the Package Manager Specification),
129 # and install those found.
130 #
131 # Example:
132 # @CODE
133 # DOCS=( NEWS README )
134 # @CODE
135
136 # @ECLASS-VARIABLE: HTML_DOCS
137 # @DEFAULT_UNSET
138 # @DESCRIPTION:
139 # An array containing documents installed using dohtml. The files
140 # and directories listed there must exist in the directory from which
141 # distutils-r1_python_install_all() is run (${S} by default).
142 #
143 # If unset, no HTML docs will be installed.
144 #
145 # Example:
146 # @CODE
147 # HTML_DOCS=( doc/html/. )
148 # @CODE
149
150 # @ECLASS-VARIABLE: EXAMPLES
151 # @DEFAULT_UNSET
152 # @DESCRIPTION:
153 # An array containing examples installed into 'examples' doc
154 # subdirectory. The files and directories listed there must exist
155 # in the directory from which distutils-r1_python_install_all() is run
156 # (${S} by default).
157 #
158 # The 'examples' subdirectory will be marked not to be compressed
159 # automatically.
160 #
161 # If unset, no examples will be installed.
162 #
163 # Example:
164 # @CODE
165 # EXAMPLES=( examples/. demos/. )
166 # @CODE
167
168 # @ECLASS-VARIABLE: DISTUTILS_IN_SOURCE_BUILD
169 # @DEFAULT_UNSET
170 # @DESCRIPTION:
171 # If set to a non-null value, in-source builds will be enabled.
172 # If unset, the default is to use in-source builds when python_prepare()
173 # is declared, and out-of-source builds otherwise.
174 #
175 # If in-source builds are used, the eclass will create a copy of package
176 # sources for each Python implementation in python_prepare_all(),
177 # and work on that copy afterwards.
178 #
179 # If out-of-source builds are used, the eclass will instead work
180 # on the sources directly, prepending setup.py arguments with
181 # 'build --build-base ${BUILD_DIR}' to enforce keeping & using built
182 # files in the specific root.
183
184 # @ECLASS-VARIABLE: DISTUTILS_NO_PARALLEL_BUILD
185 # @DEFAULT_UNSET
186 # @DESCRIPTION:
187 # If set to a non-null value, the parallel build feature will
188 # be disabled.
189 #
190 # When parallel builds are used, the implementation-specific sub-phases
191 # for selected Python implementation will be run in parallel. This will
192 # increase build efficiency with distutils which does not do parallel
193 # builds.
194 #
195 # This variable can be used to disable the afore-mentioned feature
196 # in case it causes issues with the package.
197
198 # @ECLASS-VARIABLE: mydistutilsargs
199 # @DEFAULT_UNSET
200 # @DESCRIPTION:
201 # An array containing options to be passed to setup.py.
202 #
203 # Example:
204 # @CODE
205 # python_configure_all() {
206 # mydistutilsargs=( --enable-my-hidden-option )
207 # }
208 # @CODE
209
210 # @FUNCTION: esetup.py
211 # @USAGE: [<args>...]
212 # @DESCRIPTION:
213 # Run setup.py using currently selected Python interpreter
214 # (if ${PYTHON} is set; fallback 'python' otherwise).
215 #
216 # setup.py will be passed the following, in order:
217 # 1. ${mydistutilsargs[@]}
218 # 2. The 'build' command and standard build options including ${BUILD_DIR}
219 # 3. Any additional arguments passed to the esetup.py function.
220 #
221 # This command dies on failure.
222 esetup.py() {
223 debug-print-function ${FUNCNAME} "${@}"
224
225 local add_args=()
226 if [[ ${BUILD_DIR} ]]; then
227 add_args+=(
228 build
229 --build-base "${BUILD_DIR}"
230
231 # using a single directory for them helps us export
232 # ${PYTHONPATH} and ebuilds find the sources independently
233 # of whether the package installs extensions or not
234 #
235 # note: due to some packages (wxpython) relying on separate
236 # platlib & purelib dirs, we do not set --build-lib (which
237 # can not be overriden with --build-*lib)
238 --build-platlib "${BUILD_DIR}/lib"
239 --build-purelib "${BUILD_DIR}/lib"
240
241 # make the ebuild writer lives easier
242 --build-scripts "${BUILD_DIR}/scripts"
243 )
244
245 # if setuptools is used, adjust egg_info path as well
246 if "${PYTHON:-python}" setup.py --help egg_info &>/dev/null; then
247 add_args+=(
248 egg_info --egg-base "${BUILD_DIR}"
249 )
250 fi
251 elif [[ ! ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
252 die 'Out-of-source build requested, yet BUILD_DIR unset.'
253 fi
254
255 set -- "${PYTHON:-python}" setup.py \
256 "${mydistutilsargs[@]}" "${add_args[@]}" "${@}"
257
258 echo "${@}" >&2
259 "${@}" || die
260 }
261
262 # @FUNCTION: distutils_install_for_testing
263 # @USAGE: [<args>...]
264 # @DESCRIPTION:
265 # Install the package into a temporary location for running tests.
266 # Update PYTHONPATH appropriately and set TEST_DIR to the test
267 # installation root. The Python packages will be installed in 'lib'
268 # subdir, and scripts in 'scripts' subdir (like in BUILD_DIR).
269 #
270 # Please note that this function should be only used if package uses
271 # namespaces (and therefore proper install needs to be done to enforce
272 # PYTHONPATH) or tests rely on the results of install command.
273 # For most of the packages, tests built in BUILD_DIR are good enough.
274 distutils_install_for_testing() {
275 debug-print-function ${FUNCNAME} "${@}"
276
277 # A few notes:
278 # 1) because of namespaces, we can't use 'install --root',
279 # 2) 'install --home' is terribly broken on pypy, so we need
280 # to override --install-lib and --install-scripts,
281 # 3) non-root 'install' complains about PYTHONPATH and missing dirs,
282 # so we need to set it properly and mkdir them,
283 # 4) it runs a bunch of commands which write random files to cwd,
284 # in order to avoid that, we need to run them ourselves to pass
285 # alternate build paths,
286 # 5) 'install' needs to go before 'bdist_egg' or the latter would
287 # re-set install paths.
288
289 TEST_DIR=${BUILD_DIR}/test
290 local bindir=${TEST_DIR}/scripts
291 local libdir=${TEST_DIR}/lib
292 PYTHONPATH=${libdir}:${PYTHONPATH}
293
294 local add_args=(
295 install
296 --home="${TEST_DIR}"
297 --install-lib="${libdir}"
298 --install-scripts="${bindir}"
299 )
300
301 if "${PYTHON:-python}" setup.py --help bdist_egg &>/dev/null; then
302 add_args+=(
303 bdist_egg --dist-dir="${TEST_DIR}"
304 )
305 fi
306
307 mkdir -p "${libdir}" || die
308 esetup.py "${add_args[@]}"
309 }
310
311 # @FUNCTION: distutils-r1_python_prepare_all
312 # @DESCRIPTION:
313 # The default python_prepare_all(). It applies the patches from PATCHES
314 # array, then user patches and finally calls python_copy_sources to
315 # create copies of resulting sources for each Python implementation.
316 #
317 # At some point in the future, it may also apply eclass-specific
318 # distutils patches and/or quirks.
319 distutils-r1_python_prepare_all() {
320 debug-print-function ${FUNCNAME} "${@}"
321
322 [[ ${PATCHES} ]] && epatch "${PATCHES[@]}"
323
324 epatch_user
325
326 # by default, use in-source build if python_prepare() is used
327 if [[ ! ${DISTUTILS_IN_SOURCE_BUILD+1} ]]; then
328 if declare -f python_prepare >/dev/null; then
329 DISTUTILS_IN_SOURCE_BUILD=1
330 fi
331 fi
332
333 if [[ ${DISTUTILS_IN_SOURCE_BUILD} && ! ${DISTUTILS_SINGLE_IMPL} ]]
334 then
335 # create source copies for each implementation
336 python_copy_sources
337 fi
338 }
339
340 # @FUNCTION: distutils-r1_python_prepare
341 # @DESCRIPTION:
342 # The default python_prepare(). A no-op.
343 distutils-r1_python_prepare() {
344 debug-print-function ${FUNCNAME} "${@}"
345
346 :
347 }
348
349 # @FUNCTION: distutils-r1_python_configure
350 # @DESCRIPTION:
351 # The default python_configure(). A no-op.
352 distutils-r1_python_configure() {
353 debug-print-function ${FUNCNAME} "${@}"
354
355 :
356 }
357
358 # @FUNCTION: distutils-r1_python_compile
359 # @USAGE: [additional-args...]
360 # @DESCRIPTION:
361 # The default python_compile(). Runs 'esetup.py build'. Any parameters
362 # passed to this function will be appended to setup.py invocation,
363 # i.e. passed as options to the 'build' command.
364 distutils-r1_python_compile() {
365 debug-print-function ${FUNCNAME} "${@}"
366
367 esetup.py "${@}"
368 }
369
370 # @FUNCTION: distutils-r1_python_test
371 # @DESCRIPTION:
372 # The default python_test(). A no-op.
373 distutils-r1_python_test() {
374 debug-print-function ${FUNCNAME} "${@}"
375
376 :
377 }
378
379 # @FUNCTION: _distutils-r1_rename_scripts
380 # @USAGE: <path>
381 # @INTERNAL
382 # @DESCRIPTION:
383 # Renames installed Python scripts to be implementation-suffixed.
384 # ${EPYTHON} needs to be set to the implementation name.
385 #
386 # All executable scripts having shebang referencing ${EPYTHON}
387 # in given path will be renamed.
388 _distutils-r1_rename_scripts() {
389 debug-print-function ${FUNCNAME} "${@}"
390
391 local path=${1}
392 [[ ${path} ]] || die "${FUNCNAME}: no path given"
393
394 local f
395 while IFS= read -r -d '' f; do
396 debug-print "${FUNCNAME}: found executable at ${f#${D}/}"
397
398 local shebang
399 read -r shebang < "${f}"
400 if [[ ${shebang} == '#!'*${EPYTHON}* ]]
401 then
402 debug-print "${FUNCNAME}: matching shebang: ${shebang}"
403
404 local newf=${f}-${EPYTHON}
405 debug-print "${FUNCNAME}: renaming to ${newf#${D}/}"
406 mv "${f}" "${newf}" || die
407
408 debug-print "${FUNCNAME}: installing wrapper at ${f#${D}/}"
409 _python_ln_rel "${path}${EPREFIX}"/usr/bin/python-exec "${f}" || die
410 fi
411 done < <(find "${path}" -type f -executable -print0)
412 }
413
414 # @FUNCTION: distutils-r1_python_install
415 # @USAGE: [additional-args...]
416 # @DESCRIPTION:
417 # The default python_install(). Runs 'esetup.py install', appending
418 # the optimization flags. Then renames the installed scripts.
419 # Any parameters passed to this function will be appended
420 # to the setup.py invocation (i.e. as options to the 'install' command).
421 distutils-r1_python_install() {
422 debug-print-function ${FUNCNAME} "${@}"
423
424 local flags
425
426 case "${EPYTHON}" in
427 jython*)
428 flags=(--compile);;
429 *)
430 flags=(--compile -O2);;
431 esac
432 debug-print "${FUNCNAME}: [${EPYTHON}] flags: ${flags}"
433
434 # enable compilation for the install phase.
435 local PYTHONDONTWRITEBYTECODE
436 export PYTHONDONTWRITEBYTECODE
437
438 # python likes to compile any module it sees, which triggers sandbox
439 # failures if some packages haven't compiled their modules yet.
440 addpredict "$(python_get_sitedir)"
441 addpredict /usr/lib/portage/pym
442
443 local root=${D}/_${EPYTHON}
444 [[ ${DISTUTILS_SINGLE_IMPL} ]] && root=${D}
445
446 esetup.py install "${flags[@]}" --root="${root}" "${@}"
447
448 if [[ -d ${root}$(python_get_sitedir)/tests ]]; then
449 die "Package installs 'tests' package, file collisions likely."
450 fi
451
452 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
453 _distutils-r1_rename_scripts "${root}"
454 multibuild_merge_root "${root}" "${D}"
455 fi
456 }
457
458 # @FUNCTION: distutils-r1_python_install_all
459 # @DESCRIPTION:
460 # The default python_install_all(). It installs the documentation.
461 distutils-r1_python_install_all() {
462 debug-print-function ${FUNCNAME} "${@}"
463
464 if declare -p DOCS &>/dev/null; then
465 # an empty list == don't install anything
466 if [[ ${DOCS[@]} ]]; then
467 dodoc -r "${DOCS[@]}"
468 fi
469 else
470 local f
471 # same list as in PMS
472 for f in README* ChangeLog AUTHORS NEWS TODO CHANGES \
473 THANKS BUGS FAQ CREDITS CHANGELOG; do
474 if [[ -s ${f} ]]; then
475 dodoc "${f}"
476 fi
477 done
478 fi
479
480 if declare -p HTML_DOCS &>/dev/null; then
481 dohtml -r "${HTML_DOCS[@]}"
482 fi
483
484 if declare -p EXAMPLES &>/dev/null; then
485 local INSDESTTREE=/usr/share/doc/${PF}/examples
486 doins -r "${EXAMPLES[@]}"
487 docompress -x "${INSDESTTREE}"
488 fi
489 }
490
491 # @FUNCTION: distutils-r1_run_phase
492 # @USAGE: [<argv>...]
493 # @INTERNAL
494 # @DESCRIPTION:
495 # Run the given command.
496 #
497 # If out-of-source builds are used, the phase function is run in source
498 # directory, with BUILD_DIR pointing at the build directory
499 # and PYTHONPATH having an entry for the module build directory.
500 #
501 # If in-source builds are used, the command is executed in the directory
502 # holding the per-implementation copy of sources. BUILD_DIR points
503 # to the 'build' subdirectory.
504 distutils-r1_run_phase() {
505 debug-print-function ${FUNCNAME} "${@}"
506
507 if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
508 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
509 pushd "${BUILD_DIR}" >/dev/null || die
510 fi
511 local BUILD_DIR=${BUILD_DIR}/build
512 fi
513 local -x PYTHONPATH="${BUILD_DIR}/lib:${PYTHONPATH}"
514
515 local TMPDIR=${T}/${EPYTHON}
516
517 mkdir -p "${TMPDIR}" || die
518
519 "${@}"
520
521 if [[ ${DISTUTILS_IN_SOURCE_BUILD} && ! ${DISTUTILS_SINGLE_IMPL} ]]
522 then
523 popd >/dev/null || die
524 fi
525 }
526
527 # @FUNCTION: _distutils-r1_run_common_phase
528 # @USAGE: [<argv>...]
529 # @INTERNAL
530 # @DESCRIPTION:
531 # Run the given command, restoring the best-implementation state.
532 #
533 # If in-source build is used, the command will be run in the copy
534 # of sources made for the best Python interpreter.
535 _distutils-r1_run_common_phase() {
536 local DISTUTILS_ORIG_BUILD_DIR=${BUILD_DIR}
537
538 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
539 local MULTIBUILD_VARIANTS
540 _python_obtain_impls
541
542 multibuild_for_best_variant _python_multibuild_wrapper \
543 distutils-r1_run_phase "${@}"
544 else
545 # semi-hack, be careful.
546 _distutils-r1_run_foreach_impl "${@}"
547 fi
548 }
549
550 # @FUNCTION: _distutils-r1_run_foreach_impl
551 # @INTERNAL
552 # @DESCRIPTION:
553 # Run the given phase for each implementation if multiple implementations
554 # are enabled, once otherwise.
555 _distutils-r1_run_foreach_impl() {
556 debug-print-function ${FUNCNAME} "${@}"
557
558 set -- distutils-r1_run_phase "${@}"
559
560 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
561 if [[ ${DISTUTILS_NO_PARALLEL_BUILD} || ${DISTUTILS_SINGLE_IMPL} ]]
562 then
563 python_foreach_impl "${@}"
564 else
565 python_parallel_foreach_impl "${@}"
566 fi
567 else
568 if [[ ! ${EPYTHON} ]]; then
569 die "EPYTHON unset, python-single-r1_pkg_setup not called?!"
570 fi
571 local BUILD_DIR=${BUILD_DIR:-${S}}
572 BUILD_DIR=${BUILD_DIR%%/}_${EPYTHON}
573
574 "${@}"
575 fi
576 }
577
578 distutils-r1_src_prepare() {
579 debug-print-function ${FUNCNAME} "${@}"
580
581 # common preparations
582 if declare -f python_prepare_all >/dev/null; then
583 python_prepare_all
584 else
585 distutils-r1_python_prepare_all
586 fi
587
588 if declare -f python_prepare >/dev/null; then
589 _distutils-r1_run_foreach_impl python_prepare
590 fi
591 }
592
593 distutils-r1_src_configure() {
594 if declare -f python_configure >/dev/null; then
595 _distutils-r1_run_foreach_impl python_configure
596 fi
597
598 if declare -f python_configure_all >/dev/null; then
599 _distutils-r1_run_common_phase python_configure_all
600 fi
601 }
602
603 distutils-r1_src_compile() {
604 debug-print-function ${FUNCNAME} "${@}"
605
606 if declare -f python_compile >/dev/null; then
607 _distutils-r1_run_foreach_impl python_compile
608 else
609 _distutils-r1_run_foreach_impl distutils-r1_python_compile
610 fi
611
612 if declare -f python_compile_all >/dev/null; then
613 _distutils-r1_run_common_phase python_compile_all
614 fi
615 }
616
617 distutils-r1_src_test() {
618 debug-print-function ${FUNCNAME} "${@}"
619
620 if declare -f python_test >/dev/null; then
621 _distutils-r1_run_foreach_impl python_test
622 fi
623
624 if declare -f python_test_all >/dev/null; then
625 _distutils-r1_run_common_phase python_test_all
626 fi
627 }
628
629 distutils-r1_src_install() {
630 debug-print-function ${FUNCNAME} "${@}"
631
632 if declare -f python_install >/dev/null; then
633 _distutils-r1_run_foreach_impl python_install
634 else
635 _distutils-r1_run_foreach_impl distutils-r1_python_install
636 fi
637
638 if declare -f python_install_all >/dev/null; then
639 _distutils-r1_run_common_phase python_install_all
640 else
641 _distutils-r1_run_common_phase distutils-r1_python_install_all
642 fi
643 }
644
645 _DISTUTILS_R1=1
646 fi

  ViewVC Help
Powered by ViewVC 1.1.20