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