perl-functions.eclass: should 'just work' in EAPI=6
[gentoo.git] / eclass / python-utils-r1.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: python-utils-r1.eclass
6 # @MAINTAINER:
7 # Python team <python@gentoo.org>
8 # @AUTHOR:
9 # Author: Michał Górny <mgorny@gentoo.org>
10 # Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
11 # @BLURB: Utility functions for packages with Python parts.
12 # @DESCRIPTION:
13 # A utility eclass providing functions to query Python implementations,
14 # install Python modules and scripts.
15 #
16 # This eclass does not set any metadata variables nor export any phase
17 # functions. It can be inherited safely.
18 #
19 # For more information, please see the wiki:
20 # https://wiki.gentoo.org/wiki/Project:Python/python-utils-r1
21
22 case "${EAPI:-0}" in
23         0|1|2|3|4|5|6)
24                 ;;
25         *)
26                 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
27                 ;;
28 esac
29
30 if [[ ${_PYTHON_ECLASS_INHERITED} ]]; then
31         die 'python-r1 suite eclasses can not be used with python.eclass.'
32 fi
33
34 if [[ ! ${_PYTHON_UTILS_R1} ]]; then
35
36 [[ ${EAPI:-0} == [012345] ]] && inherit eutils multilib
37 inherit toolchain-funcs
38
39 # @ECLASS-VARIABLE: _PYTHON_ALL_IMPLS
40 # @INTERNAL
41 # @DESCRIPTION:
42 # All supported Python implementations, most preferred last.
43 _PYTHON_ALL_IMPLS=(
44         jython2_5 jython2_7
45         pypy pypy3
46         python3_3 python3_4 python3_5
47         python2_7
48 )
49
50 # @FUNCTION: _python_impl_supported
51 # @USAGE: <impl>
52 # @INTERNAL
53 # @DESCRIPTION:
54 # Check whether the implementation <impl> (PYTHON_COMPAT-form)
55 # is still supported.
56 #
57 # Returns 0 if the implementation is valid and supported. If it is
58 # unsupported, returns 1 -- and the caller should ignore the entry.
59 # If it is invalid, dies with an appopriate error messages.
60 _python_impl_supported() {
61         debug-print-function ${FUNCNAME} "${@}"
62
63         [[ ${#} -eq 1 ]] || die "${FUNCNAME}: takes exactly 1 argument (impl)."
64
65         local impl=${1}
66
67         # keep in sync with _PYTHON_ALL_IMPLS!
68         # (not using that list because inline patterns shall be faster)
69         case "${impl}" in
70                 python2_7|python3_[345]|jython2_[57])
71                         return 0
72                         ;;
73                 pypy1_[89]|pypy2_0|python2_[56]|python3_[12])
74                         return 1
75                         ;;
76                 pypy|pypy3)
77                         if [[ ${EAPI:-0} == [01234] ]]; then
78                                 die "PyPy is supported in EAPI 5 and newer only."
79                         fi
80                         ;;
81                 *)
82                         die "Invalid implementation in PYTHON_COMPAT: ${impl}"
83         esac
84 }
85
86 # @ECLASS-VARIABLE: PYTHON
87 # @DEFAULT_UNSET
88 # @DESCRIPTION:
89 # The absolute path to the current Python interpreter.
90 #
91 # This variable is set automatically in the following contexts:
92 #
93 # python-r1: Set in functions called by python_foreach_impl() or after
94 # calling python_export_best().
95 #
96 # python-single-r1: Set after calling python-single-r1_pkg_setup().
97 #
98 # distutils-r1: Set within any of the python sub-phase functions.
99 #
100 # Example value:
101 # @CODE
102 # /usr/bin/python2.7
103 # @CODE
104
105 # @ECLASS-VARIABLE: EPYTHON
106 # @DEFAULT_UNSET
107 # @DESCRIPTION:
108 # The executable name of the current Python interpreter.
109 #
110 # This variable is set automatically in the following contexts:
111 #
112 # python-r1: Set in functions called by python_foreach_impl() or after
113 # calling python_export_best().
114 #
115 # python-single-r1: Set after calling python-single-r1_pkg_setup().
116 #
117 # distutils-r1: Set within any of the python sub-phase functions.
118 #
119 # Example value:
120 # @CODE
121 # python2.7
122 # @CODE
123
124 # @ECLASS-VARIABLE: PYTHON_SITEDIR
125 # @DEFAULT_UNSET
126 # @DESCRIPTION:
127 # The path to Python site-packages directory.
128 #
129 # Set and exported on request using python_export().
130 # Requires a proper build-time dependency on the Python implementation.
131 #
132 # Example value:
133 # @CODE
134 # /usr/lib64/python2.7/site-packages
135 # @CODE
136
137 # @ECLASS-VARIABLE: PYTHON_INCLUDEDIR
138 # @DEFAULT_UNSET
139 # @DESCRIPTION:
140 # The path to Python include directory.
141 #
142 # Set and exported on request using python_export().
143 # Requires a proper build-time dependency on the Python implementation.
144 #
145 # Example value:
146 # @CODE
147 # /usr/include/python2.7
148 # @CODE
149
150 # @ECLASS-VARIABLE: PYTHON_LIBPATH
151 # @DEFAULT_UNSET
152 # @DESCRIPTION:
153 # The path to Python library.
154 #
155 # Set and exported on request using python_export().
156 # Valid only for CPython. Requires a proper build-time dependency
157 # on the Python implementation.
158 #
159 # Example value:
160 # @CODE
161 # /usr/lib64/libpython2.7.so
162 # @CODE
163
164 # @ECLASS-VARIABLE: PYTHON_CFLAGS
165 # @DEFAULT_UNSET
166 # @DESCRIPTION:
167 # Proper C compiler flags for building against Python. Obtained from
168 # pkg-config or python-config.
169 #
170 # Set and exported on request using python_export().
171 # Valid only for CPython. Requires a proper build-time dependency
172 # on the Python implementation and on pkg-config.
173 #
174 # Example value:
175 # @CODE
176 # -I/usr/include/python2.7
177 # @CODE
178
179 # @ECLASS-VARIABLE: PYTHON_LIBS
180 # @DEFAULT_UNSET
181 # @DESCRIPTION:
182 # Proper C compiler flags for linking against Python. Obtained from
183 # pkg-config or python-config.
184 #
185 # Set and exported on request using python_export().
186 # Valid only for CPython. Requires a proper build-time dependency
187 # on the Python implementation and on pkg-config.
188 #
189 # Example value:
190 # @CODE
191 # -lpython2.7
192 # @CODE
193
194 # @ECLASS-VARIABLE: PYTHON_CONFIG
195 # @DEFAULT_UNSET
196 # @DESCRIPTION:
197 # Path to the python-config executable.
198 #
199 # Set and exported on request using python_export().
200 # Valid only for CPython. Requires a proper build-time dependency
201 # on the Python implementation and on pkg-config.
202 #
203 # Example value:
204 # @CODE
205 # /usr/bin/python2.7-config
206 # @CODE
207
208 # @ECLASS-VARIABLE: PYTHON_PKG_DEP
209 # @DEFAULT_UNSET
210 # @DESCRIPTION:
211 # The complete dependency on a particular Python package as a string.
212 #
213 # Set and exported on request using python_export().
214 #
215 # Example value:
216 # @CODE
217 # dev-lang/python:2.7[xml]
218 # @CODE
219
220 # @ECLASS-VARIABLE: PYTHON_SCRIPTDIR
221 # @DEFAULT_UNSET
222 # @DESCRIPTION:
223 # The location where Python scripts must be installed for current impl.
224 #
225 # Set and exported on request using python_export().
226 #
227 # Example value:
228 # @CODE
229 # /usr/lib/python-exec/python2.7
230 # @CODE
231
232 # @FUNCTION: python_export
233 # @USAGE: [<impl>] <variables>...
234 # @DESCRIPTION:
235 # Set and export the Python implementation-relevant variables passed
236 # as parameters.
237 #
238 # The optional first parameter may specify the requested Python
239 # implementation (either as PYTHON_TARGETS value, e.g. python2_7,
240 # or an EPYTHON one, e.g. python2.7). If no implementation passed,
241 # the current one will be obtained from ${EPYTHON}.
242 #
243 # The variables which can be exported are: PYTHON, EPYTHON,
244 # PYTHON_SITEDIR. They are described more completely in the eclass
245 # variable documentation.
246 python_export() {
247         debug-print-function ${FUNCNAME} "${@}"
248
249         local impl var
250
251         case "${1}" in
252                 python*|jython*)
253                         impl=${1/_/.}
254                         shift
255                         ;;
256                 pypy|pypy3)
257                         impl=${1}
258                         shift
259                         ;;
260                 *)
261                         impl=${EPYTHON}
262                         if [[ -z ${impl} ]]; then
263                                 die "python_export called without a python implementation and EPYTHON is unset"
264                         fi
265                         ;;
266         esac
267         debug-print "${FUNCNAME}: implementation: ${impl}"
268
269         for var; do
270                 case "${var}" in
271                         EPYTHON)
272                                 export EPYTHON=${impl}
273                                 debug-print "${FUNCNAME}: EPYTHON = ${EPYTHON}"
274                                 ;;
275                         PYTHON)
276                                 export PYTHON=${EPREFIX}/usr/bin/${impl}
277                                 debug-print "${FUNCNAME}: PYTHON = ${PYTHON}"
278                                 ;;
279                         PYTHON_SITEDIR)
280                                 [[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it"
281                                 # sysconfig can't be used because:
282                                 # 1) pypy doesn't give site-packages but stdlib
283                                 # 2) jython gives paths with wrong case
284                                 PYTHON_SITEDIR=$("${PYTHON}" -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())') || die
285                                 export PYTHON_SITEDIR
286                                 debug-print "${FUNCNAME}: PYTHON_SITEDIR = ${PYTHON_SITEDIR}"
287                                 ;;
288                         PYTHON_INCLUDEDIR)
289                                 [[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it"
290                                 PYTHON_INCLUDEDIR=$("${PYTHON}" -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_inc())') || die
291                                 export PYTHON_INCLUDEDIR
292                                 debug-print "${FUNCNAME}: PYTHON_INCLUDEDIR = ${PYTHON_INCLUDEDIR}"
293
294                                 # Jython gives a non-existing directory
295                                 if [[ ! -d ${PYTHON_INCLUDEDIR} ]]; then
296                                         die "${impl} does not install any header files!"
297                                 fi
298                                 ;;
299                         PYTHON_LIBPATH)
300                                 [[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it"
301                                 PYTHON_LIBPATH=$("${PYTHON}" -c 'import os.path, sysconfig; print(os.path.join(sysconfig.get_config_var("LIBDIR"), sysconfig.get_config_var("LDLIBRARY")) if sysconfig.get_config_var("LDLIBRARY") else "")') || die
302                                 export PYTHON_LIBPATH
303                                 debug-print "${FUNCNAME}: PYTHON_LIBPATH = ${PYTHON_LIBPATH}"
304
305                                 if [[ ! ${PYTHON_LIBPATH} ]]; then
306                                         die "${impl} lacks a (usable) dynamic library"
307                                 fi
308                                 ;;
309                         PYTHON_CFLAGS)
310                                 local val
311
312                                 case "${impl}" in
313                                         python*)
314                                                 # python-2.7, python-3.2, etc.
315                                                 val=$($(tc-getPKG_CONFIG) --cflags ${impl/n/n-}) || die
316                                                 ;;
317                                         *)
318                                                 die "${impl}: obtaining ${var} not supported"
319                                                 ;;
320                                 esac
321
322                                 export PYTHON_CFLAGS=${val}
323                                 debug-print "${FUNCNAME}: PYTHON_CFLAGS = ${PYTHON_CFLAGS}"
324                                 ;;
325                         PYTHON_LIBS)
326                                 local val
327
328                                 case "${impl}" in
329                                         python*)
330                                                 # python-2.7, python-3.2, etc.
331                                                 val=$($(tc-getPKG_CONFIG) --libs ${impl/n/n-}) || die
332                                                 ;;
333                                         *)
334                                                 die "${impl}: obtaining ${var} not supported"
335                                                 ;;
336                                 esac
337
338                                 export PYTHON_LIBS=${val}
339                                 debug-print "${FUNCNAME}: PYTHON_LIBS = ${PYTHON_LIBS}"
340                                 ;;
341                         PYTHON_CONFIG)
342                                 local flags val
343
344                                 case "${impl}" in
345                                         python*)
346                                                 [[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it"
347                                                 flags=$("${PYTHON}" -c 'import sysconfig; print(sysconfig.get_config_var("ABIFLAGS") or "")') || die
348                                                 val=${PYTHON}${flags}-config
349                                                 ;;
350                                         *)
351                                                 die "${impl}: obtaining ${var} not supported"
352                                                 ;;
353                                 esac
354
355                                 export PYTHON_CONFIG=${val}
356                                 debug-print "${FUNCNAME}: PYTHON_CONFIG = ${PYTHON_CONFIG}"
357                                 ;;
358                         PYTHON_PKG_DEP)
359                                 local d
360                                 case ${impl} in
361                                         python2.7)
362                                                 PYTHON_PKG_DEP='>=dev-lang/python-2.7.5-r2:2.7';;
363                                         python3.3)
364                                                 PYTHON_PKG_DEP='>=dev-lang/python-3.3.2-r2:3.3';;
365                                         python*)
366                                                 PYTHON_PKG_DEP="dev-lang/python:${impl#python}";;
367                                         pypy)
368                                                 PYTHON_PKG_DEP='virtual/pypy:0=';;
369                                         pypy3)
370                                                 PYTHON_PKG_DEP='virtual/pypy3:0=';;
371                                         jython2.5)
372                                                 PYTHON_PKG_DEP='>=dev-java/jython-2.5.3-r2:2.5';;
373                                         jython2.7)
374                                                 PYTHON_PKG_DEP='dev-java/jython:2.7';;
375                                         *)
376                                                 die "Invalid implementation: ${impl}"
377                                 esac
378
379                                 # use-dep
380                                 if [[ ${PYTHON_REQ_USE} ]]; then
381                                         PYTHON_PKG_DEP+=[${PYTHON_REQ_USE}]
382                                 fi
383
384                                 export PYTHON_PKG_DEP
385                                 debug-print "${FUNCNAME}: PYTHON_PKG_DEP = ${PYTHON_PKG_DEP}"
386                                 ;;
387                         PYTHON_SCRIPTDIR)
388                                 local dir
389                                 export PYTHON_SCRIPTDIR=${EPREFIX}/usr/lib/python-exec/${impl}
390                                 debug-print "${FUNCNAME}: PYTHON_SCRIPTDIR = ${PYTHON_SCRIPTDIR}"
391                                 ;;
392                         *)
393                                 die "python_export: unknown variable ${var}"
394                 esac
395         done
396 }
397
398 # @FUNCTION: python_get_sitedir
399 # @USAGE: [<impl>]
400 # @DESCRIPTION:
401 # Obtain and print the 'site-packages' path for the given
402 # implementation. If no implementation is provided, ${EPYTHON} will
403 # be used.
404 #
405 # If you just need to have PYTHON_SITEDIR set (and exported), then it is
406 # better to use python_export() directly instead.
407 python_get_sitedir() {
408         debug-print-function ${FUNCNAME} "${@}"
409
410         python_export "${@}" PYTHON_SITEDIR
411         echo "${PYTHON_SITEDIR}"
412 }
413
414 # @FUNCTION: python_get_includedir
415 # @USAGE: [<impl>]
416 # @DESCRIPTION:
417 # Obtain and print the include path for the given implementation. If no
418 # implementation is provided, ${EPYTHON} will be used.
419 #
420 # If you just need to have PYTHON_INCLUDEDIR set (and exported), then it
421 # is better to use python_export() directly instead.
422 python_get_includedir() {
423         debug-print-function ${FUNCNAME} "${@}"
424
425         python_export "${@}" PYTHON_INCLUDEDIR
426         echo "${PYTHON_INCLUDEDIR}"
427 }
428
429 # @FUNCTION: python_get_library_path
430 # @USAGE: [<impl>]
431 # @DESCRIPTION:
432 # Obtain and print the Python library path for the given implementation.
433 # If no implementation is provided, ${EPYTHON} will be used.
434 #
435 # Please note that this function can be used with CPython only. Use
436 # in another implementation will result in a fatal failure.
437 python_get_library_path() {
438         debug-print-function ${FUNCNAME} "${@}"
439
440         python_export "${@}" PYTHON_LIBPATH
441         echo "${PYTHON_LIBPATH}"
442 }
443
444 # @FUNCTION: python_get_CFLAGS
445 # @USAGE: [<impl>]
446 # @DESCRIPTION:
447 # Obtain and print the compiler flags for building against Python,
448 # for the given implementation. If no implementation is provided,
449 # ${EPYTHON} will be used.
450 #
451 # Please note that this function can be used with CPython only.
452 # It requires Python and pkg-config installed, and therefore proper
453 # build-time dependencies need be added to the ebuild.
454 python_get_CFLAGS() {
455         debug-print-function ${FUNCNAME} "${@}"
456
457         python_export "${@}" PYTHON_CFLAGS
458         echo "${PYTHON_CFLAGS}"
459 }
460
461 # @FUNCTION: python_get_LIBS
462 # @USAGE: [<impl>]
463 # @DESCRIPTION:
464 # Obtain and print the compiler flags for linking against Python,
465 # for the given implementation. If no implementation is provided,
466 # ${EPYTHON} will be used.
467 #
468 # Please note that this function can be used with CPython only.
469 # It requires Python and pkg-config installed, and therefore proper
470 # build-time dependencies need be added to the ebuild.
471 python_get_LIBS() {
472         debug-print-function ${FUNCNAME} "${@}"
473
474         python_export "${@}" PYTHON_LIBS
475         echo "${PYTHON_LIBS}"
476 }
477
478 # @FUNCTION: python_get_PYTHON_CONFIG
479 # @USAGE: [<impl>]
480 # @DESCRIPTION:
481 # Obtain and print the PYTHON_CONFIG location for the given
482 # implementation. If no implementation is provided, ${EPYTHON} will be
483 # used.
484 #
485 # Please note that this function can be used with CPython only.
486 # It requires Python installed, and therefore proper build-time
487 # dependencies need be added to the ebuild.
488 python_get_PYTHON_CONFIG() {
489         debug-print-function ${FUNCNAME} "${@}"
490
491         python_export "${@}" PYTHON_CONFIG
492         echo "${PYTHON_CONFIG}"
493 }
494
495 # @FUNCTION: python_get_scriptdir
496 # @USAGE: [<impl>]
497 # @DESCRIPTION:
498 # Obtain and print the script install path for the given
499 # implementation. If no implementation is provided, ${EPYTHON} will
500 # be used.
501 python_get_scriptdir() {
502         debug-print-function ${FUNCNAME} "${@}"
503
504         python_export "${@}" PYTHON_SCRIPTDIR
505         echo "${PYTHON_SCRIPTDIR}"
506 }
507
508 # @FUNCTION: _python_ln_rel
509 # @USAGE: <from> <to>
510 # @INTERNAL
511 # @DESCRIPTION:
512 # Create a relative symlink.
513 _python_ln_rel() {
514         debug-print-function ${FUNCNAME} "${@}"
515
516         local target=${1}
517         local symname=${2}
518
519         local tgpath=${target%/*}/
520         local sympath=${symname%/*}/
521         local rel_target=
522
523         while [[ ${sympath} ]]; do
524                 local tgseg= symseg=
525
526                 while [[ ! ${tgseg} && ${tgpath} ]]; do
527                         tgseg=${tgpath%%/*}
528                         tgpath=${tgpath#${tgseg}/}
529                 done
530
531                 while [[ ! ${symseg} && ${sympath} ]]; do
532                         symseg=${sympath%%/*}
533                         sympath=${sympath#${symseg}/}
534                 done
535
536                 if [[ ${tgseg} != ${symseg} ]]; then
537                         rel_target=../${rel_target}${tgseg:+${tgseg}/}
538                 fi
539         done
540         rel_target+=${tgpath}${target##*/}
541
542         debug-print "${FUNCNAME}: ${symname} -> ${target}"
543         debug-print "${FUNCNAME}: rel_target = ${rel_target}"
544
545         ln -fs "${rel_target}" "${symname}"
546 }
547
548 # @FUNCTION: python_optimize
549 # @USAGE: [<directory>...]
550 # @DESCRIPTION:
551 # Compile and optimize Python modules in specified directories (absolute
552 # paths). If no directories are provided, the default system paths
553 # are used (prepended with ${D}).
554 python_optimize() {
555         debug-print-function ${FUNCNAME} "${@}"
556
557         if [[ ${EBUILD_PHASE} == pre* || ${EBUILD_PHASE} == post* ]]; then
558                 eerror "The new Python eclasses expect the compiled Python files to"
559                 eerror "be controlled by the Package Manager. For this reason,"
560                 eerror "the python_optimize function can be used only during src_* phases"
561                 eerror "(src_install most commonly) and not during pkg_* phases."
562                 echo
563                 die "python_optimize is not to be used in pre/post* phases"
564         fi
565
566         [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
567
568         local PYTHON=${PYTHON}
569         [[ ${PYTHON} ]] || python_export PYTHON
570
571         # default to sys.path
572         if [[ ${#} -eq 0 ]]; then
573                 local f
574                 while IFS= read -r -d '' f; do
575                         # 1) accept only absolute paths
576                         #    (i.e. skip '', '.' or anything like that)
577                         # 2) skip paths which do not exist
578                         #    (python2.6 complains about them verbosely)
579
580                         if [[ ${f} == /* && -d ${D}${f} ]]; then
581                                 set -- "${D}${f}" "${@}"
582                         fi
583                 done < <("${PYTHON}" -c 'import sys; print("\0".join(sys.path))' || die)
584
585                 debug-print "${FUNCNAME}: using sys.path: ${*/%/;}"
586         fi
587
588         local d
589         for d; do
590                 # make sure to get a nice path without //
591                 local instpath=${d#${D}}
592                 instpath=/${instpath##/}
593
594                 case "${EPYTHON}" in
595                         python*)
596                                 "${PYTHON}" -m compileall -q -f -d "${instpath}" "${d}"
597                                 "${PYTHON}" -OO -m compileall -q -f -d "${instpath}" "${d}"
598                                 ;;
599                         *)
600                                 "${PYTHON}" -m compileall -q -f -d "${instpath}" "${d}"
601                                 ;;
602                 esac
603         done
604 }
605
606 # @ECLASS-VARIABLE: python_scriptroot
607 # @DEFAULT_UNSET
608 # @DESCRIPTION:
609 # The current script destination for python_doscript(). The path
610 # is relative to the installation root (${ED}).
611 #
612 # When unset, ${DESTTREE}/bin (/usr/bin by default) will be used.
613 #
614 # Can be set indirectly through the python_scriptinto() function.
615 #
616 # Example:
617 # @CODE
618 # src_install() {
619 #   local python_scriptroot=${GAMES_BINDIR}
620 #   python_foreach_impl python_doscript foo
621 # }
622 # @CODE
623
624 # @FUNCTION: python_scriptinto
625 # @USAGE: <new-path>
626 # @DESCRIPTION:
627 # Set the current scriptroot. The new value will be stored
628 # in the 'python_scriptroot' environment variable. The new value need
629 # be relative to the installation root (${ED}).
630 #
631 # Alternatively, you can set the variable directly.
632 python_scriptinto() {
633         debug-print-function ${FUNCNAME} "${@}"
634
635         python_scriptroot=${1}
636 }
637
638 # @FUNCTION: python_doexe
639 # @USAGE: <files>...
640 # @DESCRIPTION:
641 # Install the given executables into current python_scriptroot,
642 # for the current Python implementation (${EPYTHON}).
643 #
644 # The executable will be wrapped properly for the Python implementation,
645 # though no shebang mangling will be performed.
646 python_doexe() {
647         debug-print-function ${FUNCNAME} "${@}"
648
649         local f
650         for f; do
651                 python_newexe "${f}" "${f##*/}"
652         done
653 }
654
655 # @FUNCTION: python_newexe
656 # @USAGE: <path> <new-name>
657 # @DESCRIPTION:
658 # Install the given executable into current python_scriptroot,
659 # for the current Python implementation (${EPYTHON}).
660 #
661 # The executable will be wrapped properly for the Python implementation,
662 # though no shebang mangling will be performed. It will be renamed
663 # to <new-name>.
664 python_newexe() {
665         debug-print-function ${FUNCNAME} "${@}"
666
667         [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
668         [[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <path> <new-name>"
669         if [[ ${EAPI:-0} == [0123] ]]; then
670                 die "python_do* and python_new* helpers are banned in EAPIs older than 4."
671         fi
672
673         local wrapd=${python_scriptroot:-${DESTTREE}/bin}
674
675         local f=${1}
676         local newfn=${2}
677
678         local PYTHON_SCRIPTDIR d
679         python_export PYTHON_SCRIPTDIR
680         d=${PYTHON_SCRIPTDIR#${EPREFIX}}
681
682         (
683                 dodir "${wrapd}"
684                 exeinto "${d}"
685                 newexe "${f}" "${newfn}" || return ${?}
686         )
687
688         # install the wrapper
689         _python_ln_rel "${ED%/}"/usr/lib/python-exec/python-exec2 \
690                 "${ED%/}/${wrapd}/${newfn}" || die
691
692         # don't use this at home, just call python_doscript() instead
693         if [[ ${_PYTHON_REWRITE_SHEBANG} ]]; then
694                 python_fix_shebang -q "${ED%/}/${d}/${newfn}"
695         fi
696 }
697
698 # @FUNCTION: python_doscript
699 # @USAGE: <files>...
700 # @DESCRIPTION:
701 # Install the given scripts into current python_scriptroot,
702 # for the current Python implementation (${EPYTHON}).
703 #
704 # All specified files must start with a 'python' shebang. The shebang
705 # will be converted, and the files will be wrapped properly
706 # for the Python implementation.
707 #
708 # Example:
709 # @CODE
710 # src_install() {
711 #   python_foreach_impl python_doscript ${PN}
712 # }
713 # @CODE
714 python_doscript() {
715         debug-print-function ${FUNCNAME} "${@}"
716
717         local _PYTHON_REWRITE_SHEBANG=1
718         python_doexe "${@}"
719 }
720
721 # @FUNCTION: python_newscript
722 # @USAGE: <path> <new-name>
723 # @DESCRIPTION:
724 # Install the given script into current python_scriptroot
725 # for the current Python implementation (${EPYTHON}), and name it
726 # <new-name>.
727 #
728 # The file must start with a 'python' shebang. The shebang will be
729 # converted, and the file will be wrapped properly for the Python
730 # implementation. It will be renamed to <new-name>.
731 #
732 # Example:
733 # @CODE
734 # src_install() {
735 #   python_foreach_impl python_newscript foo.py foo
736 # }
737 # @CODE
738 python_newscript() {
739         debug-print-function ${FUNCNAME} "${@}"
740
741         local _PYTHON_REWRITE_SHEBANG=1
742         python_newexe "${@}"
743 }
744
745 # @ECLASS-VARIABLE: python_moduleroot
746 # @DEFAULT_UNSET
747 # @DESCRIPTION:
748 # The current module root for python_domodule(). The path can be either
749 # an absolute system path (it must start with a slash, and ${ED} will be
750 # prepended to it) or relative to the implementation's site-packages directory
751 # (then it must start with a non-slash character).
752 #
753 # When unset, the modules will be installed in the site-packages root.
754 #
755 # Can be set indirectly through the python_moduleinto() function.
756 #
757 # Example:
758 # @CODE
759 # src_install() {
760 #   local python_moduleroot=bar
761 #   # installs ${PYTHON_SITEDIR}/bar/baz.py
762 #   python_foreach_impl python_domodule baz.py
763 # }
764 # @CODE
765
766 # @FUNCTION: python_moduleinto
767 # @USAGE: <new-path>
768 # @DESCRIPTION:
769 # Set the current module root. The new value will be stored
770 # in the 'python_moduleroot' environment variable. The new value need
771 # be relative to the site-packages root.
772 #
773 # Alternatively, you can set the variable directly.
774 python_moduleinto() {
775         debug-print-function ${FUNCNAME} "${@}"
776
777         python_moduleroot=${1}
778 }
779
780 # @FUNCTION: python_domodule
781 # @USAGE: <files>...
782 # @DESCRIPTION:
783 # Install the given modules (or packages) into the current
784 # python_moduleroot. The list can mention both modules (files)
785 # and packages (directories). All listed files will be installed
786 # for all enabled implementations, and compiled afterwards.
787 #
788 # Example:
789 # @CODE
790 # src_install() {
791 #   # (${PN} being a directory)
792 #   python_foreach_impl python_domodule ${PN}
793 # }
794 # @CODE
795 python_domodule() {
796         debug-print-function ${FUNCNAME} "${@}"
797
798         [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
799         if [[ ${EAPI:-0} == [0123] ]]; then
800                 die "python_do* and python_new* helpers are banned in EAPIs older than 4."
801         fi
802
803         local d
804         if [[ ${python_moduleroot} == /* ]]; then
805                 # absolute path
806                 d=${python_moduleroot}
807         else
808                 # relative to site-packages
809                 local PYTHON_SITEDIR=${PYTHON_SITEDIR}
810                 [[ ${PYTHON_SITEDIR} ]] || python_export PYTHON_SITEDIR
811
812                 d=${PYTHON_SITEDIR#${EPREFIX}}/${python_moduleroot}
813         fi
814
815         (
816                 insinto "${d}"
817                 doins -r "${@}" || return ${?}
818         )
819
820         python_optimize "${ED}/${d}"
821 }
822
823 # @FUNCTION: python_doheader
824 # @USAGE: <files>...
825 # @DESCRIPTION:
826 # Install the given headers into the implementation-specific include
827 # directory. This function is unconditionally recursive, i.e. you can
828 # pass directories instead of files.
829 #
830 # Example:
831 # @CODE
832 # src_install() {
833 #   python_foreach_impl python_doheader foo.h bar.h
834 # }
835 # @CODE
836 python_doheader() {
837         debug-print-function ${FUNCNAME} "${@}"
838
839         [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
840         if [[ ${EAPI:-0} == [0123] ]]; then
841                 die "python_do* and python_new* helpers are banned in EAPIs older than 4."
842         fi
843
844         local d PYTHON_INCLUDEDIR=${PYTHON_INCLUDEDIR}
845         [[ ${PYTHON_INCLUDEDIR} ]] || python_export PYTHON_INCLUDEDIR
846
847         d=${PYTHON_INCLUDEDIR#${EPREFIX}}
848
849         (
850                 insinto "${d}"
851                 doins -r "${@}" || return ${?}
852         )
853 }
854
855 # @FUNCTION: python_wrapper_setup
856 # @USAGE: [<path> [<impl>]]
857 # @DESCRIPTION:
858 # Create proper 'python' executable and pkg-config wrappers
859 # (if available) in the directory named by <path>. Set up PATH
860 # and PKG_CONFIG_PATH appropriately. <path> defaults to ${T}/${EPYTHON}.
861 #
862 # The wrappers will be created for implementation named by <impl>,
863 # or for one named by ${EPYTHON} if no <impl> passed.
864 #
865 # If the named directory contains a python symlink already, it will
866 # be assumed to contain proper wrappers already and only environment
867 # setup will be done. If wrapper update is requested, the directory
868 # shall be removed first.
869 python_wrapper_setup() {
870         debug-print-function ${FUNCNAME} "${@}"
871
872         local workdir=${1:-${T}/${EPYTHON}}
873         local impl=${2:-${EPYTHON}}
874
875         [[ ${workdir} ]] || die "${FUNCNAME}: no workdir specified."
876         [[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON specified."
877
878         if [[ ! -x ${workdir}/bin/python ]]; then
879                 _python_check_dead_variables
880
881                 mkdir -p "${workdir}"/{bin,pkgconfig} || die
882
883                 # Clean up, in case we were supposed to do a cheap update.
884                 rm -f "${workdir}"/bin/python{,2,3,-config} || die
885                 rm -f "${workdir}"/bin/2to3 || die
886                 rm -f "${workdir}"/pkgconfig/python{,2,3}.pc || die
887
888                 local EPYTHON PYTHON PYTHON_CONFIG
889                 python_export "${impl}" EPYTHON PYTHON
890
891                 local pyver pyother
892                 if python_is_python3; then
893                         pyver=3
894                         pyother=2
895                 else
896                         pyver=2
897                         pyother=3
898                 fi
899
900                 # Python interpreter
901                 # note: we don't use symlinks because python likes to do some
902                 # symlink reading magic that breaks stuff
903                 # https://bugs.gentoo.org/show_bug.cgi?id=555752
904                 cat > "${workdir}/bin/python" <<-_EOF_ || die
905                         #!/bin/sh
906                         exec "${PYTHON}" "\${@}"
907                 _EOF_
908                 cp "${workdir}/bin/python" "${workdir}/bin/python${pyver}" || die
909                 chmod +x "${workdir}/bin/python" "${workdir}/bin/python${pyver}" || die
910
911                 local nonsupp=( "python${pyother}" "python${pyother}-config" )
912
913                 # CPython-specific
914                 if [[ ${EPYTHON} == python* ]]; then
915                         python_export "${impl}" PYTHON_CONFIG
916
917                         cat > "${workdir}/bin/python-config" <<-_EOF_ || die
918                                 #!/bin/sh
919                                 exec "${PYTHON_CONFIG}" "\${@}"
920                         _EOF_
921                         cp "${workdir}/bin/python-config" \
922                                 "${workdir}/bin/python${pyver}-config" || die
923                         chmod +x "${workdir}/bin/python-config" \
924                                 "${workdir}/bin/python${pyver}-config" || die
925
926                         # Python 2.6+.
927                         ln -s "${PYTHON/python/2to3-}" "${workdir}"/bin/2to3 || die
928
929                         # Python 2.7+.
930                         ln -s "${EPREFIX}"/usr/$(get_libdir)/pkgconfig/${EPYTHON/n/n-}.pc \
931                                 "${workdir}"/pkgconfig/python.pc || die
932                         ln -s python.pc "${workdir}"/pkgconfig/python${pyver}.pc || die
933                 else
934                         nonsupp+=( 2to3 python-config "python${pyver}-config" )
935                 fi
936
937                 local x
938                 for x in "${nonsupp[@]}"; do
939                         cat >"${workdir}"/bin/${x} <<-_EOF_ || die
940                                 #!/bin/sh
941                                 echo "${x} is not supported by ${EPYTHON}" >&2
942                                 exit 127
943                         _EOF_
944                         chmod +x "${workdir}"/bin/${x} || die
945                 done
946
947                 # Now, set the environment.
948                 # But note that ${workdir} may be shared with something else,
949                 # and thus already on top of PATH.
950                 if [[ ${PATH##:*} != ${workdir}/bin ]]; then
951                         PATH=${workdir}/bin${PATH:+:${PATH}}
952                 fi
953                 if [[ ${PKG_CONFIG_PATH##:*} != ${workdir}/pkgconfig ]]; then
954                         PKG_CONFIG_PATH=${workdir}/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
955                 fi
956                 export PATH PKG_CONFIG_PATH
957         fi
958 }
959
960 # @FUNCTION: python_is_python3
961 # @USAGE: [<impl>]
962 # @DESCRIPTION:
963 # Check whether <impl> (or ${EPYTHON}) is a Python3k variant
964 # (i.e. uses syntax and stdlib of Python 3.*).
965 #
966 # Returns 0 (true) if it is, 1 (false) otherwise.
967 python_is_python3() {
968         local impl=${1:-${EPYTHON}}
969         [[ ${impl} ]] || die "python_is_python3: no impl nor EPYTHON"
970
971         [[ ${impl} == python3* || ${impl} == pypy3 ]]
972 }
973
974 # @FUNCTION: python_is_installed
975 # @USAGE: [<impl>]
976 # @DESCRIPTION:
977 # Check whether the interpreter for <impl> (or ${EPYTHON}) is installed.
978 # Uses has_version with a proper dependency string.
979 #
980 # Returns 0 (true) if it is, 1 (false) otherwise.
981 python_is_installed() {
982         local impl=${1:-${EPYTHON}}
983         [[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON"
984
985         # for has_version
986         local -x ROOT=/
987         case "${impl}" in
988                 pypy|pypy3)
989                         local append=
990                         if [[ ${PYTHON_REQ_USE} ]]; then
991                                 append=[${PYTHON_REQ_USE}]
992                         fi
993
994                         # be happy with just the interpeter, no need for the virtual
995                         has_version "dev-python/${impl}${append}" \
996                                 || has_version "dev-python/${impl}-bin${append}"
997                         ;;
998                 *)
999                         local PYTHON_PKG_DEP
1000                         python_export "${impl}" PYTHON_PKG_DEP
1001                         has_version "${PYTHON_PKG_DEP}"
1002                         ;;
1003         esac
1004 }
1005
1006 # @FUNCTION: python_fix_shebang
1007 # @USAGE: [-f|--force] [-q|--quiet] <path>...
1008 # @DESCRIPTION:
1009 # Replace the shebang in Python scripts with the current Python
1010 # implementation (EPYTHON). If a directory is passed, works recursively
1011 # on all Python scripts.
1012 #
1013 # Only files having a 'python*' shebang will be modified. Files with
1014 # other shebang will either be skipped when working recursively
1015 # on a directory or treated as error when specified explicitly.
1016 #
1017 # Shebangs matching explicitly current Python version will be left
1018 # unmodified. Shebangs requesting another Python version will be treated
1019 # as fatal error, unless --force is given.
1020 #
1021 # --force causes the function to replace even shebangs that require
1022 # incompatible Python version. --quiet causes the function not to list
1023 # modified files verbosely.
1024 python_fix_shebang() {
1025         debug-print-function ${FUNCNAME} "${@}"
1026
1027         [[ ${EPYTHON} ]] || die "${FUNCNAME}: EPYTHON unset (pkg_setup not called?)"
1028
1029         local force quiet
1030         while [[ ${@} ]]; do
1031                 case "${1}" in
1032                         -f|--force) force=1; shift;;
1033                         -q|--quiet) quiet=1; shift;;
1034                         --) shift; break;;
1035                         *) break;;
1036                 esac
1037         done
1038
1039         [[ ${1} ]] || die "${FUNCNAME}: no paths given"
1040
1041         local path f
1042         for path; do
1043                 local any_correct any_fixed is_recursive
1044
1045                 [[ -d ${path} ]] && is_recursive=1
1046
1047                 while IFS= read -r -d '' f; do
1048                         local shebang i
1049                         local error= from=
1050
1051                         # note: we can't ||die here since read will fail if file
1052                         # has no newline characters
1053                         IFS= read -r shebang <"${f}"
1054
1055                         # First, check if it's shebang at all...
1056                         if [[ ${shebang} == '#!'* ]]; then
1057                                 local split_shebang=()
1058                                 read -r -a split_shebang <<<${shebang} || die
1059
1060                                 # Match left-to-right in a loop, to avoid matching random
1061                                 # repetitions like 'python2.7 python2'.
1062                                 for i in "${split_shebang[@]}"; do
1063                                         case "${i}" in
1064                                                 *"${EPYTHON}")
1065                                                         debug-print "${FUNCNAME}: in file ${f#${D}}"
1066                                                         debug-print "${FUNCNAME}: shebang matches EPYTHON: ${shebang}"
1067
1068                                                         # Nothing to do, move along.
1069                                                         any_correct=1
1070                                                         from=${EPYTHON}
1071                                                         break
1072                                                         ;;
1073                                                 *python|*python[23])
1074                                                         debug-print "${FUNCNAME}: in file ${f#${D}}"
1075                                                         debug-print "${FUNCNAME}: rewriting shebang: ${shebang}"
1076
1077                                                         if [[ ${i} == *python2 ]]; then
1078                                                                 from=python2
1079                                                                 if [[ ! ${force} ]]; then
1080                                                                         python_is_python3 "${EPYTHON}" && error=1
1081                                                                 fi
1082                                                         elif [[ ${i} == *python3 ]]; then
1083                                                                 from=python3
1084                                                                 if [[ ! ${force} ]]; then
1085                                                                         python_is_python3 "${EPYTHON}" || error=1
1086                                                                 fi
1087                                                         else
1088                                                                 from=python
1089                                                         fi
1090                                                         break
1091                                                         ;;
1092                                                 *python[23].[0123456789]|*pypy|*pypy3|*jython[23].[0123456789])
1093                                                         # Explicit mismatch.
1094                                                         if [[ ! ${force} ]]; then
1095                                                                 error=1
1096                                                         else
1097                                                                 case "${i}" in
1098                                                                         *python[23].[0123456789])
1099                                                                                 from="python[23].[0123456789]";;
1100                                                                         *pypy)
1101                                                                                 from="pypy";;
1102                                                                         *pypy3)
1103                                                                                 from="pypy3";;
1104                                                                         *jython[23].[0123456789])
1105                                                                                 from="jython[23].[0123456789]";;
1106                                                                         *)
1107                                                                                 die "${FUNCNAME}: internal error in 2nd pattern match";;
1108                                                                 esac
1109                                                         fi
1110                                                         break
1111                                                         ;;
1112                                         esac
1113                                 done
1114                         fi
1115
1116                         if [[ ! ${error} && ! ${from} ]]; then
1117                                 # Non-Python shebang. Allowed in recursive mode,
1118                                 # disallowed when specifying file explicitly.
1119                                 [[ ${is_recursive} ]] && continue
1120                                 error=1
1121                         fi
1122
1123                         if [[ ! ${quiet} ]]; then
1124                                 einfo "Fixing shebang in ${f#${D}}."
1125                         fi
1126
1127                         if [[ ! ${error} ]]; then
1128                                 # We either want to match ${from} followed by space
1129                                 # or at end-of-string.
1130                                 if [[ ${shebang} == *${from}" "* ]]; then
1131                                         sed -i -e "1s:${from} :${EPYTHON} :" "${f}" || die
1132                                 else
1133                                         sed -i -e "1s:${from}$:${EPYTHON}:" "${f}" || die
1134                                 fi
1135                                 any_fixed=1
1136                         else
1137                                 eerror "The file has incompatible shebang:"
1138                                 eerror "  file: ${f#${D}}"
1139                                 eerror "  current shebang: ${shebang}"
1140                                 eerror "  requested impl: ${EPYTHON}"
1141                                 die "${FUNCNAME}: conversion of incompatible shebang requested"
1142                         fi
1143                 done < <(find -H "${path}" -type f -print0 || die)
1144
1145                 if [[ ! ${any_fixed} ]]; then
1146                         local cmd=eerror
1147                         [[ ${EAPI:-0} == [012345] ]] && cmd=eqawarn
1148
1149                         "${cmd}" "QA warning: ${FUNCNAME}, ${path#${D}} did not match any fixable files."
1150                         if [[ ${any_correct} ]]; then
1151                                 "${cmd}" "All files have ${EPYTHON} shebang already."
1152                         else
1153                                 "${cmd}" "There are no Python files in specified directory."
1154                         fi
1155
1156                         [[ ${cmd} == eerror ]] && die "${FUNCNAME} did not match any fixable files (QA warning fatal in EAPI ${EAPI})"
1157                 fi
1158         done
1159 }
1160
1161 # @FUNCTION: _python_check_locale_sanity
1162 # @USAGE: <locale>
1163 # @RETURN: 0 if sane, 1 otherwise
1164 # @DESCRIPTION:
1165 # Check whether the specified locale sanely maps between lowercase
1166 # and uppercase ASCII characters.
1167 _python_check_locale_sanity() {
1168         local -x LC_CTYPE=${1}
1169         local IFS=
1170
1171         local lc=( {a..z} )
1172         local uc=( {A..Z} )
1173         local input="${lc[*]}${uc[*]}"
1174
1175         local output=$(tr '[:lower:][:upper:]' '[:upper:][:lower:]' <<<"${input}")
1176         [[ ${output} == "${uc[*]}${lc[*]}" ]]
1177 }
1178
1179 # @FUNCTION: python_export_utf8_locale
1180 # @RETURN: 0 on success, 1 on failure.
1181 # @DESCRIPTION:
1182 # Attempts to export a usable UTF-8 locale in the LC_CTYPE variable. Does
1183 # nothing if LC_ALL is defined, or if the current locale uses a UTF-8 charmap.
1184 # This may be used to work around the quirky open() behavior of python3.
1185 python_export_utf8_locale() {
1186         debug-print-function ${FUNCNAME} "${@}"
1187
1188         # If the locale program isn't available, just return.
1189         type locale >/dev/null || return 0
1190
1191         if [[ $(locale charmap) != UTF-8 ]]; then
1192                 # Try English first, then everything else.
1193                 local lang locales="en_US.UTF-8 $(locale -a)"
1194
1195                 for lang in ${locales}; do
1196                         if [[ $(LC_ALL=${lang} locale charmap 2>/dev/null) == UTF-8 ]]; then
1197                                 if _python_check_locale_sanity "${lang}"; then
1198                                         export LC_CTYPE=${lang}
1199                                         if [[ -n ${LC_ALL} ]]; then
1200                                                 export LC_NUMERIC=${LC_ALL}
1201                                                 export LC_TIME=${LC_ALL}
1202                                                 export LC_COLLATE=${LC_ALL}
1203                                                 export LC_MONETARY=${LC_ALL}
1204                                                 export LC_MESSAGES=${LC_ALL}
1205                                                 export LC_PAPER=${LC_ALL}
1206                                                 export LC_NAME=${LC_ALL}
1207                                                 export LC_ADDRESS=${LC_ALL}
1208                                                 export LC_TELEPHONE=${LC_ALL}
1209                                                 export LC_MEASUREMENT=${LC_ALL}
1210                                                 export LC_IDENTIFICATION=${LC_ALL}
1211                                                 export LC_ALL=
1212                                         fi
1213                                         return 0
1214                                 fi
1215                         fi  
1216                 done
1217
1218                 ewarn "Could not find a UTF-8 locale. This may trigger build failures in"
1219                 ewarn "some python packages. Please ensure that a UTF-8 locale is listed in"
1220                 ewarn "/etc/locale.gen and run locale-gen."
1221                 return 1
1222         fi  
1223
1224         return 0
1225 }
1226
1227 # -- python.eclass functions --
1228
1229 _python_check_dead_variables() {
1230         local v
1231
1232         for v in PYTHON_DEPEND PYTHON_USE_WITH{,_OR,_OPT} {RESTRICT,SUPPORT}_PYTHON_ABIS
1233         do
1234                 if [[ ${!v} ]]; then
1235                         die "${v} is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#Ebuild_head"
1236                 fi
1237         done
1238
1239         for v in PYTHON_{CPPFLAGS,CFLAGS,CXXFLAGS,LDFLAGS}
1240         do
1241                 if [[ ${!v} ]]; then
1242                         die "${v} is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#PYTHON_CFLAGS"
1243                 fi
1244         done
1245
1246         for v in PYTHON_TESTS_RESTRICTED_ABIS PYTHON_EXPORT_PHASE_FUNCTIONS \
1247                 PYTHON_VERSIONED_{SCRIPTS,EXECUTABLES} PYTHON_NONVERSIONED_EXECUTABLES
1248         do
1249                 if [[ ${!v} ]]; then
1250                         die "${v} is invalid for python-r1 suite"
1251                 fi
1252         done
1253
1254         for v in DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES DISTUTILS_SETUP_FILES \
1255                 DISTUTILS_GLOBAL_OPTIONS DISTUTILS_SRC_TEST PYTHON_MODNAME
1256         do
1257                 if [[ ${!v} ]]; then
1258                         die "${v} is invalid for distutils-r1, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#${v}"
1259                 fi
1260         done
1261
1262         if [[ ${DISTUTILS_DISABLE_TEST_DEPENDENCY} ]]; then
1263                 die "${v} is invalid for distutils-r1, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#DISTUTILS_SRC_TEST"
1264         fi
1265
1266         # python.eclass::progress
1267         for v in PYTHON_BDEPEND PYTHON_MULTIPLE_ABIS PYTHON_ABI_TYPE \
1268                 PYTHON_RESTRICTED_ABIS PYTHON_TESTS_FAILURES_TOLERANT_ABIS \
1269                 PYTHON_CFFI_MODULES_GENERATION_COMMANDS
1270         do
1271                 if [[ ${!v} ]]; then
1272                         die "${v} is invalid for python-r1 suite"
1273                 fi
1274         done
1275 }
1276
1277 python_pkg_setup() {
1278         die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#pkg_setup"
1279 }
1280
1281 python_convert_shebangs() {
1282         die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#python_convert_shebangs"
1283 }
1284
1285 python_clean_py-compile_files() {
1286         die "${FUNCNAME}() is invalid for python-r1 suite"
1287 }
1288
1289 python_clean_installation_image() {
1290         die "${FUNCNAME}() is invalid for python-r1 suite"
1291 }
1292
1293 python_execute_function() {
1294         die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#python_execute_function"
1295 }
1296
1297 python_generate_wrapper_scripts() {
1298         die "${FUNCNAME}() is invalid for python-r1 suite"
1299 }
1300
1301 python_merge_intermediate_installation_images() {
1302         die "${FUNCNAME}() is invalid for python-r1 suite"
1303 }
1304
1305 python_set_active_version() {
1306         die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#pkg_setup"
1307 }
1308
1309 python_need_rebuild() {
1310         die "${FUNCNAME}() is invalid for python-r1 suite"
1311 }
1312
1313 PYTHON() {
1314         die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#.24.28PYTHON.29.2C_.24.7BEPYTHON.7D"
1315 }
1316
1317 python_get_implementation() {
1318         die "${FUNCNAME}() is invalid for python-r1 suite"
1319 }
1320
1321 python_get_implementational_package() {
1322         die "${FUNCNAME}() is invalid for python-r1 suite"
1323 }
1324
1325 python_get_libdir() {
1326         die "${FUNCNAME}() is invalid for python-r1 suite"
1327 }
1328
1329 python_get_library() {
1330         die "${FUNCNAME}() is invalid for python-r1 suite"
1331 }
1332
1333 python_get_version() {
1334         die "${FUNCNAME}() is invalid for python-r1 suite"
1335 }
1336
1337 python_get_implementation_and_version() {
1338         die "${FUNCNAME}() is invalid for python-r1 suite"
1339 }
1340
1341 python_execute_nosetests() {
1342         die "${FUNCNAME}() is invalid for python-r1 suite"
1343 }
1344
1345 python_execute_py.test() {
1346         die "${FUNCNAME}() is invalid for python-r1 suite"
1347 }
1348
1349 python_execute_trial() {
1350         die "${FUNCNAME}() is invalid for python-r1 suite"
1351 }
1352
1353 python_enable_pyc() {
1354         die "${FUNCNAME}() is invalid for python-r1 suite"
1355 }
1356
1357 python_disable_pyc() {
1358         die "${FUNCNAME}() is invalid for python-r1 suite"
1359 }
1360
1361 python_mod_optimize() {
1362         die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#Python_byte-code_compilation"
1363 }
1364
1365 python_mod_cleanup() {
1366         die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#Python_byte-code_compilation"
1367 }
1368
1369 # python.eclass::progress
1370
1371 python_abi_depend() {
1372         die "${FUNCNAME}() is invalid for python-r1 suite"
1373 }
1374
1375 python_install_executables() {
1376         die "${FUNCNAME}() is invalid for python-r1 suite"
1377 }
1378
1379 python_get_extension_module_suffix() {
1380         die "${FUNCNAME}() is invalid for python-r1 suite"
1381 }
1382
1383 python_byte-compile_modules() {
1384         die "${FUNCNAME}() is invalid for python-r1 suite"
1385 }
1386
1387 python_clean_byte-compiled_modules() {
1388         die "${FUNCNAME}() is invalid for python-r1 suite"
1389 }
1390
1391 python_generate_cffi_modules() {
1392         die "${FUNCNAME}() is invalid for python-r1 suite"
1393 }
1394
1395 _PYTHON_UTILS_R1=1
1396 fi