net-wireless/hostapd: use #!/sbin/openrc-run instead of #!/sbin/runscript
[gentoo.git] / eclass / python-utils-r1.eclass
1 # Copyright 1999-2016 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 # @FUNCTION: python_scriptinto
655 # @USAGE: <new-path>
656 # @DESCRIPTION:
657 # Set the directory to which files passed to python_doexe(),
658 # python_doscript(), python_newexe() and python_newscript()
659 # are going to be installed. The new value needs to be relative
660 # to the installation root (${ED}).
661 #
662 # If not set explicitly, the directory defaults to /usr/bin.
663 #
664 # Example:
665 # @CODE
666 # src_install() {
667 #   python_scriptinto /usr/sbin
668 #   python_foreach_impl python_doscript foo
669 # }
670 # @CODE
671 python_scriptinto() {
672         debug-print-function ${FUNCNAME} "${@}"
673
674         python_scriptroot=${1}
675 }
676
677 # @FUNCTION: python_doexe
678 # @USAGE: <files>...
679 # @DESCRIPTION:
680 # Install the given executables into the executable install directory,
681 # for the current Python implementation (${EPYTHON}).
682 #
683 # The executable will be wrapped properly for the Python implementation,
684 # though no shebang mangling will be performed.
685 python_doexe() {
686         debug-print-function ${FUNCNAME} "${@}"
687
688         local f
689         for f; do
690                 python_newexe "${f}" "${f##*/}"
691         done
692 }
693
694 # @FUNCTION: python_newexe
695 # @USAGE: <path> <new-name>
696 # @DESCRIPTION:
697 # Install the given executable into the executable install directory,
698 # for the current Python implementation (${EPYTHON}).
699 #
700 # The executable will be wrapped properly for the Python implementation,
701 # though no shebang mangling will be performed. It will be renamed
702 # to <new-name>.
703 python_newexe() {
704         debug-print-function ${FUNCNAME} "${@}"
705
706         [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
707         [[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <path> <new-name>"
708         if [[ ${EAPI:-0} == [0123] ]]; then
709                 die "python_do* and python_new* helpers are banned in EAPIs older than 4."
710         fi
711
712         local wrapd=${python_scriptroot:-/usr/bin}
713
714         local f=${1}
715         local newfn=${2}
716
717         local PYTHON_SCRIPTDIR d
718         python_export PYTHON_SCRIPTDIR
719         d=${PYTHON_SCRIPTDIR#${EPREFIX}}
720
721         (
722                 dodir "${wrapd}"
723                 exeinto "${d}"
724                 newexe "${f}" "${newfn}" || return ${?}
725         )
726
727         # install the wrapper
728         _python_ln_rel "${ED%/}"/usr/lib/python-exec/python-exec2 \
729                 "${ED%/}/${wrapd}/${newfn}" || die
730
731         # don't use this at home, just call python_doscript() instead
732         if [[ ${_PYTHON_REWRITE_SHEBANG} ]]; then
733                 python_fix_shebang -q "${ED%/}/${d}/${newfn}"
734         fi
735 }
736
737 # @FUNCTION: python_doscript
738 # @USAGE: <files>...
739 # @DESCRIPTION:
740 # Install the given scripts into the executable install directory,
741 # for the current Python implementation (${EPYTHON}).
742 #
743 # All specified files must start with a 'python' shebang. The shebang
744 # will be converted, and the files will be wrapped properly
745 # for the Python implementation.
746 #
747 # Example:
748 # @CODE
749 # src_install() {
750 #   python_foreach_impl python_doscript ${PN}
751 # }
752 # @CODE
753 python_doscript() {
754         debug-print-function ${FUNCNAME} "${@}"
755
756         local _PYTHON_REWRITE_SHEBANG=1
757         python_doexe "${@}"
758 }
759
760 # @FUNCTION: python_newscript
761 # @USAGE: <path> <new-name>
762 # @DESCRIPTION:
763 # Install the given script into the executable install directory
764 # for the current Python implementation (${EPYTHON}), and name it
765 # <new-name>.
766 #
767 # The file must start with a 'python' shebang. The shebang will be
768 # converted, and the file will be wrapped properly for the Python
769 # implementation. It will be renamed to <new-name>.
770 #
771 # Example:
772 # @CODE
773 # src_install() {
774 #   python_foreach_impl python_newscript foo.py foo
775 # }
776 # @CODE
777 python_newscript() {
778         debug-print-function ${FUNCNAME} "${@}"
779
780         local _PYTHON_REWRITE_SHEBANG=1
781         python_newexe "${@}"
782 }
783
784 # @FUNCTION: python_moduleinto
785 # @USAGE: <new-path>
786 # @DESCRIPTION:
787 # Set the Python module install directory for python_domodule().
788 # The <new-path> can either be an absolute target system path (in which
789 # case it needs to start with a slash, and ${ED} will be prepended to
790 # it) or relative to the implementation's site-packages directory
791 # (then it must not start with a slash).
792 #
793 # When not set explicitly, the modules are installed to the top
794 # site-packages directory.
795 #
796 # Example:
797 # @CODE
798 # src_install() {
799 #   python_moduleinto bar
800 #   # installs ${PYTHON_SITEDIR}/bar/baz.py
801 #   python_foreach_impl python_domodule baz.py
802 # }
803 # @CODE
804
805 # Set the current module root. The new value will be stored
806 # in the 'python_moduleroot' environment variable. The new value need
807 # be relative to the site-packages root.
808 #
809 # Alternatively, you can set the variable directly.
810 python_moduleinto() {
811         debug-print-function ${FUNCNAME} "${@}"
812
813         python_moduleroot=${1}
814 }
815
816 # @FUNCTION: python_domodule
817 # @USAGE: <files>...
818 # @DESCRIPTION:
819 # Install the given modules (or packages) into the current Python module
820 # installation directory. The list can mention both modules (files)
821 # and packages (directories). All listed files will be installed
822 # for all enabled implementations, and compiled afterwards.
823 #
824 # Example:
825 # @CODE
826 # src_install() {
827 #   # (${PN} being a directory)
828 #   python_foreach_impl python_domodule ${PN}
829 # }
830 # @CODE
831 python_domodule() {
832         debug-print-function ${FUNCNAME} "${@}"
833
834         [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
835         if [[ ${EAPI:-0} == [0123] ]]; then
836                 die "python_do* and python_new* helpers are banned in EAPIs older than 4."
837         fi
838
839         local d
840         if [[ ${python_moduleroot} == /* ]]; then
841                 # absolute path
842                 d=${python_moduleroot}
843         else
844                 # relative to site-packages
845                 local PYTHON_SITEDIR=${PYTHON_SITEDIR}
846                 [[ ${PYTHON_SITEDIR} ]] || python_export PYTHON_SITEDIR
847
848                 d=${PYTHON_SITEDIR#${EPREFIX}}/${python_moduleroot}
849         fi
850
851         (
852                 insinto "${d}"
853                 doins -r "${@}" || return ${?}
854         )
855
856         python_optimize "${ED}/${d}"
857 }
858
859 # @FUNCTION: python_doheader
860 # @USAGE: <files>...
861 # @DESCRIPTION:
862 # Install the given headers into the implementation-specific include
863 # directory. This function is unconditionally recursive, i.e. you can
864 # pass directories instead of files.
865 #
866 # Example:
867 # @CODE
868 # src_install() {
869 #   python_foreach_impl python_doheader foo.h bar.h
870 # }
871 # @CODE
872 python_doheader() {
873         debug-print-function ${FUNCNAME} "${@}"
874
875         [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
876         if [[ ${EAPI:-0} == [0123] ]]; then
877                 die "python_do* and python_new* helpers are banned in EAPIs older than 4."
878         fi
879
880         local d PYTHON_INCLUDEDIR=${PYTHON_INCLUDEDIR}
881         [[ ${PYTHON_INCLUDEDIR} ]] || python_export PYTHON_INCLUDEDIR
882
883         d=${PYTHON_INCLUDEDIR#${EPREFIX}}
884
885         (
886                 insinto "${d}"
887                 doins -r "${@}" || return ${?}
888         )
889 }
890
891 # @FUNCTION: python_wrapper_setup
892 # @USAGE: [<path> [<impl>]]
893 # @DESCRIPTION:
894 # Create proper 'python' executable and pkg-config wrappers
895 # (if available) in the directory named by <path>. Set up PATH
896 # and PKG_CONFIG_PATH appropriately. <path> defaults to ${T}/${EPYTHON}.
897 #
898 # The wrappers will be created for implementation named by <impl>,
899 # or for one named by ${EPYTHON} if no <impl> passed.
900 #
901 # If the named directory contains a python symlink already, it will
902 # be assumed to contain proper wrappers already and only environment
903 # setup will be done. If wrapper update is requested, the directory
904 # shall be removed first.
905 python_wrapper_setup() {
906         debug-print-function ${FUNCNAME} "${@}"
907
908         local workdir=${1:-${T}/${EPYTHON}}
909         local impl=${2:-${EPYTHON}}
910
911         [[ ${workdir} ]] || die "${FUNCNAME}: no workdir specified."
912         [[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON specified."
913
914         if [[ ! -x ${workdir}/bin/python ]]; then
915                 _python_check_dead_variables
916
917                 mkdir -p "${workdir}"/{bin,pkgconfig} || die
918
919                 # Clean up, in case we were supposed to do a cheap update.
920                 rm -f "${workdir}"/bin/python{,2,3}{,-config} || die
921                 rm -f "${workdir}"/bin/2to3 || die
922                 rm -f "${workdir}"/pkgconfig/python{,2,3}.pc || die
923
924                 local EPYTHON PYTHON PYTHON_CONFIG
925                 python_export "${impl}" EPYTHON PYTHON
926
927                 local pyver pyother
928                 if python_is_python3; then
929                         pyver=3
930                         pyother=2
931                 else
932                         pyver=2
933                         pyother=3
934                 fi
935
936                 # Python interpreter
937                 # note: we don't use symlinks because python likes to do some
938                 # symlink reading magic that breaks stuff
939                 # https://bugs.gentoo.org/show_bug.cgi?id=555752
940                 cat > "${workdir}/bin/python" <<-_EOF_ || die
941                         #!/bin/sh
942                         exec "${PYTHON}" "\${@}"
943                 _EOF_
944                 cp "${workdir}/bin/python" "${workdir}/bin/python${pyver}" || die
945                 chmod +x "${workdir}/bin/python" "${workdir}/bin/python${pyver}" || die
946
947                 local nonsupp=( "python${pyother}" "python${pyother}-config" )
948
949                 # CPython-specific
950                 if [[ ${EPYTHON} == python* ]]; then
951                         python_export "${impl}" PYTHON_CONFIG
952
953                         cat > "${workdir}/bin/python-config" <<-_EOF_ || die
954                                 #!/bin/sh
955                                 exec "${PYTHON_CONFIG}" "\${@}"
956                         _EOF_
957                         cp "${workdir}/bin/python-config" \
958                                 "${workdir}/bin/python${pyver}-config" || die
959                         chmod +x "${workdir}/bin/python-config" \
960                                 "${workdir}/bin/python${pyver}-config" || die
961
962                         # Python 2.6+.
963                         ln -s "${PYTHON/python/2to3-}" "${workdir}"/bin/2to3 || die
964
965                         # Python 2.7+.
966                         ln -s "${EPREFIX}"/usr/$(get_libdir)/pkgconfig/${EPYTHON/n/n-}.pc \
967                                 "${workdir}"/pkgconfig/python.pc || die
968                         ln -s python.pc "${workdir}"/pkgconfig/python${pyver}.pc || die
969                 else
970                         nonsupp+=( 2to3 python-config "python${pyver}-config" )
971                 fi
972
973                 local x
974                 for x in "${nonsupp[@]}"; do
975                         cat >"${workdir}"/bin/${x} <<-_EOF_ || die
976                                 #!/bin/sh
977                                 echo "${x} is not supported by ${EPYTHON}" >&2
978                                 exit 127
979                         _EOF_
980                         chmod +x "${workdir}"/bin/${x} || die
981                 done
982
983                 # Now, set the environment.
984                 # But note that ${workdir} may be shared with something else,
985                 # and thus already on top of PATH.
986                 if [[ ${PATH##:*} != ${workdir}/bin ]]; then
987                         PATH=${workdir}/bin${PATH:+:${PATH}}
988                 fi
989                 if [[ ${PKG_CONFIG_PATH##:*} != ${workdir}/pkgconfig ]]; then
990                         PKG_CONFIG_PATH=${workdir}/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
991                 fi
992                 export PATH PKG_CONFIG_PATH
993         fi
994 }
995
996 # @FUNCTION: python_is_python3
997 # @USAGE: [<impl>]
998 # @DESCRIPTION:
999 # Check whether <impl> (or ${EPYTHON}) is a Python3k variant
1000 # (i.e. uses syntax and stdlib of Python 3.*).
1001 #
1002 # Returns 0 (true) if it is, 1 (false) otherwise.
1003 python_is_python3() {
1004         local impl=${1:-${EPYTHON}}
1005         [[ ${impl} ]] || die "python_is_python3: no impl nor EPYTHON"
1006
1007         [[ ${impl} == python3* || ${impl} == pypy3 ]]
1008 }
1009
1010 # @FUNCTION: python_is_installed
1011 # @USAGE: [<impl>]
1012 # @DESCRIPTION:
1013 # Check whether the interpreter for <impl> (or ${EPYTHON}) is installed.
1014 # Uses has_version with a proper dependency string.
1015 #
1016 # Returns 0 (true) if it is, 1 (false) otherwise.
1017 python_is_installed() {
1018         local impl=${1:-${EPYTHON}}
1019         [[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON"
1020
1021         # for has_version
1022         local -x ROOT=/
1023         case "${impl}" in
1024                 pypy|pypy3)
1025                         local append=
1026                         if [[ ${PYTHON_REQ_USE} ]]; then
1027                                 append=[${PYTHON_REQ_USE}]
1028                         fi
1029
1030                         # be happy with just the interpeter, no need for the virtual
1031                         has_version "dev-python/${impl}${append}" \
1032                                 || has_version "dev-python/${impl}-bin${append}"
1033                         ;;
1034                 *)
1035                         local PYTHON_PKG_DEP
1036                         python_export "${impl}" PYTHON_PKG_DEP
1037                         has_version "${PYTHON_PKG_DEP}"
1038                         ;;
1039         esac
1040 }
1041
1042 # @FUNCTION: python_fix_shebang
1043 # @USAGE: [-f|--force] [-q|--quiet] <path>...
1044 # @DESCRIPTION:
1045 # Replace the shebang in Python scripts with the current Python
1046 # implementation (EPYTHON). If a directory is passed, works recursively
1047 # on all Python scripts.
1048 #
1049 # Only files having a 'python*' shebang will be modified. Files with
1050 # other shebang will either be skipped when working recursively
1051 # on a directory or treated as error when specified explicitly.
1052 #
1053 # Shebangs matching explicitly current Python version will be left
1054 # unmodified. Shebangs requesting another Python version will be treated
1055 # as fatal error, unless --force is given.
1056 #
1057 # --force causes the function to replace even shebangs that require
1058 # incompatible Python version. --quiet causes the function not to list
1059 # modified files verbosely.
1060 python_fix_shebang() {
1061         debug-print-function ${FUNCNAME} "${@}"
1062
1063         [[ ${EPYTHON} ]] || die "${FUNCNAME}: EPYTHON unset (pkg_setup not called?)"
1064
1065         local force quiet
1066         while [[ ${@} ]]; do
1067                 case "${1}" in
1068                         -f|--force) force=1; shift;;
1069                         -q|--quiet) quiet=1; shift;;
1070                         --) shift; break;;
1071                         *) break;;
1072                 esac
1073         done
1074
1075         [[ ${1} ]] || die "${FUNCNAME}: no paths given"
1076
1077         local path f
1078         for path; do
1079                 local any_correct any_fixed is_recursive
1080
1081                 [[ -d ${path} ]] && is_recursive=1
1082
1083                 while IFS= read -r -d '' f; do
1084                         local shebang i
1085                         local error= from=
1086
1087                         # note: we can't ||die here since read will fail if file
1088                         # has no newline characters
1089                         IFS= read -r shebang <"${f}"
1090
1091                         # First, check if it's shebang at all...
1092                         if [[ ${shebang} == '#!'* ]]; then
1093                                 local split_shebang=()
1094                                 read -r -a split_shebang <<<${shebang} || die
1095
1096                                 # Match left-to-right in a loop, to avoid matching random
1097                                 # repetitions like 'python2.7 python2'.
1098                                 for i in "${split_shebang[@]}"; do
1099                                         case "${i}" in
1100                                                 *"${EPYTHON}")
1101                                                         debug-print "${FUNCNAME}: in file ${f#${D}}"
1102                                                         debug-print "${FUNCNAME}: shebang matches EPYTHON: ${shebang}"
1103
1104                                                         # Nothing to do, move along.
1105                                                         any_correct=1
1106                                                         from=${EPYTHON}
1107                                                         break
1108                                                         ;;
1109                                                 *python|*python[23])
1110                                                         debug-print "${FUNCNAME}: in file ${f#${D}}"
1111                                                         debug-print "${FUNCNAME}: rewriting shebang: ${shebang}"
1112
1113                                                         if [[ ${i} == *python2 ]]; then
1114                                                                 from=python2
1115                                                                 if [[ ! ${force} ]]; then
1116                                                                         python_is_python3 "${EPYTHON}" && error=1
1117                                                                 fi
1118                                                         elif [[ ${i} == *python3 ]]; then
1119                                                                 from=python3
1120                                                                 if [[ ! ${force} ]]; then
1121                                                                         python_is_python3 "${EPYTHON}" || error=1
1122                                                                 fi
1123                                                         else
1124                                                                 from=python
1125                                                         fi
1126                                                         break
1127                                                         ;;
1128                                                 *python[23].[0123456789]|*pypy|*pypy3|*jython[23].[0123456789])
1129                                                         # Explicit mismatch.
1130                                                         if [[ ! ${force} ]]; then
1131                                                                 error=1
1132                                                         else
1133                                                                 case "${i}" in
1134                                                                         *python[23].[0123456789])
1135                                                                                 from="python[23].[0123456789]";;
1136                                                                         *pypy)
1137                                                                                 from="pypy";;
1138                                                                         *pypy3)
1139                                                                                 from="pypy3";;
1140                                                                         *jython[23].[0123456789])
1141                                                                                 from="jython[23].[0123456789]";;
1142                                                                         *)
1143                                                                                 die "${FUNCNAME}: internal error in 2nd pattern match";;
1144                                                                 esac
1145                                                         fi
1146                                                         break
1147                                                         ;;
1148                                         esac
1149                                 done
1150                         fi
1151
1152                         if [[ ! ${error} && ! ${from} ]]; then
1153                                 # Non-Python shebang. Allowed in recursive mode,
1154                                 # disallowed when specifying file explicitly.
1155                                 [[ ${is_recursive} ]] && continue
1156                                 error=1
1157                         fi
1158
1159                         if [[ ! ${quiet} ]]; then
1160                                 einfo "Fixing shebang in ${f#${D}}."
1161                         fi
1162
1163                         if [[ ! ${error} ]]; then
1164                                 # We either want to match ${from} followed by space
1165                                 # or at end-of-string.
1166                                 if [[ ${shebang} == *${from}" "* ]]; then
1167                                         sed -i -e "1s:${from} :${EPYTHON} :" "${f}" || die
1168                                 else
1169                                         sed -i -e "1s:${from}$:${EPYTHON}:" "${f}" || die
1170                                 fi
1171                                 any_fixed=1
1172                         else
1173                                 eerror "The file has incompatible shebang:"
1174                                 eerror "  file: ${f#${D}}"
1175                                 eerror "  current shebang: ${shebang}"
1176                                 eerror "  requested impl: ${EPYTHON}"
1177                                 die "${FUNCNAME}: conversion of incompatible shebang requested"
1178                         fi
1179                 done < <(find -H "${path}" -type f -print0 || die)
1180
1181                 if [[ ! ${any_fixed} ]]; then
1182                         local cmd=eerror
1183                         [[ ${EAPI:-0} == [012345] ]] && cmd=eqawarn
1184
1185                         "${cmd}" "QA warning: ${FUNCNAME}, ${path#${D}} did not match any fixable files."
1186                         if [[ ${any_correct} ]]; then
1187                                 "${cmd}" "All files have ${EPYTHON} shebang already."
1188                         else
1189                                 "${cmd}" "There are no Python files in specified directory."
1190                         fi
1191
1192                         [[ ${cmd} == eerror ]] && die "${FUNCNAME} did not match any fixable files (QA warning fatal in EAPI ${EAPI})"
1193                 fi
1194         done
1195 }
1196
1197 # @FUNCTION: _python_check_locale_sanity
1198 # @USAGE: <locale>
1199 # @RETURN: 0 if sane, 1 otherwise
1200 # @DESCRIPTION:
1201 # Check whether the specified locale sanely maps between lowercase
1202 # and uppercase ASCII characters.
1203 _python_check_locale_sanity() {
1204         local -x LC_CTYPE=${1}
1205         local IFS=
1206
1207         local lc=( {a..z} )
1208         local uc=( {A..Z} )
1209         local input="${lc[*]}${uc[*]}"
1210
1211         local output=$(tr '[:lower:][:upper:]' '[:upper:][:lower:]' <<<"${input}")
1212         [[ ${output} == "${uc[*]}${lc[*]}" ]]
1213 }
1214
1215 # @FUNCTION: python_export_utf8_locale
1216 # @RETURN: 0 on success, 1 on failure.
1217 # @DESCRIPTION:
1218 # Attempts to export a usable UTF-8 locale in the LC_CTYPE variable. Does
1219 # nothing if LC_ALL is defined, or if the current locale uses a UTF-8 charmap.
1220 # This may be used to work around the quirky open() behavior of python3.
1221 python_export_utf8_locale() {
1222         debug-print-function ${FUNCNAME} "${@}"
1223
1224         # If the locale program isn't available, just return.
1225         type locale >/dev/null || return 0
1226
1227         if [[ $(locale charmap) != UTF-8 ]]; then
1228                 # Try English first, then everything else.
1229                 local lang locales="en_US.UTF-8 $(locale -a)"
1230
1231                 for lang in ${locales}; do
1232                         if [[ $(LC_ALL=${lang} locale charmap 2>/dev/null) == UTF-8 ]]; then
1233                                 if _python_check_locale_sanity "${lang}"; then
1234                                         export LC_CTYPE=${lang}
1235                                         if [[ -n ${LC_ALL} ]]; then
1236                                                 export LC_NUMERIC=${LC_ALL}
1237                                                 export LC_TIME=${LC_ALL}
1238                                                 export LC_COLLATE=${LC_ALL}
1239                                                 export LC_MONETARY=${LC_ALL}
1240                                                 export LC_MESSAGES=${LC_ALL}
1241                                                 export LC_PAPER=${LC_ALL}
1242                                                 export LC_NAME=${LC_ALL}
1243                                                 export LC_ADDRESS=${LC_ALL}
1244                                                 export LC_TELEPHONE=${LC_ALL}
1245                                                 export LC_MEASUREMENT=${LC_ALL}
1246                                                 export LC_IDENTIFICATION=${LC_ALL}
1247                                                 export LC_ALL=
1248                                         fi
1249                                         return 0
1250                                 fi
1251                         fi  
1252                 done
1253
1254                 ewarn "Could not find a UTF-8 locale. This may trigger build failures in"
1255                 ewarn "some python packages. Please ensure that a UTF-8 locale is listed in"
1256                 ewarn "/etc/locale.gen and run locale-gen."
1257                 return 1
1258         fi  
1259
1260         return 0
1261 }
1262
1263 # -- python.eclass functions --
1264
1265 _python_check_dead_variables() {
1266         local v
1267
1268         for v in PYTHON_DEPEND PYTHON_USE_WITH{,_OR,_OPT} {RESTRICT,SUPPORT}_PYTHON_ABIS
1269         do
1270                 if [[ ${!v} ]]; then
1271                         die "${v} is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#Ebuild_head"
1272                 fi
1273         done
1274
1275         for v in PYTHON_{CPPFLAGS,CFLAGS,CXXFLAGS,LDFLAGS}
1276         do
1277                 if [[ ${!v} ]]; then
1278                         die "${v} is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#PYTHON_CFLAGS"
1279                 fi
1280         done
1281
1282         for v in PYTHON_TESTS_RESTRICTED_ABIS PYTHON_EXPORT_PHASE_FUNCTIONS \
1283                 PYTHON_VERSIONED_{SCRIPTS,EXECUTABLES} PYTHON_NONVERSIONED_EXECUTABLES
1284         do
1285                 if [[ ${!v} ]]; then
1286                         die "${v} is invalid for python-r1 suite"
1287                 fi
1288         done
1289
1290         for v in DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES DISTUTILS_SETUP_FILES \
1291                 DISTUTILS_GLOBAL_OPTIONS DISTUTILS_SRC_TEST PYTHON_MODNAME
1292         do
1293                 if [[ ${!v} ]]; then
1294                         die "${v} is invalid for distutils-r1, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#${v}"
1295                 fi
1296         done
1297
1298         if [[ ${DISTUTILS_DISABLE_TEST_DEPENDENCY} ]]; then
1299                 die "${v} is invalid for distutils-r1, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#DISTUTILS_SRC_TEST"
1300         fi
1301
1302         # python.eclass::progress
1303         for v in PYTHON_BDEPEND PYTHON_MULTIPLE_ABIS PYTHON_ABI_TYPE \
1304                 PYTHON_RESTRICTED_ABIS PYTHON_TESTS_FAILURES_TOLERANT_ABIS \
1305                 PYTHON_CFFI_MODULES_GENERATION_COMMANDS
1306         do
1307                 if [[ ${!v} ]]; then
1308                         die "${v} is invalid for python-r1 suite"
1309                 fi
1310         done
1311 }
1312
1313 python_pkg_setup() {
1314         die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#pkg_setup"
1315 }
1316
1317 python_convert_shebangs() {
1318         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"
1319 }
1320
1321 python_clean_py-compile_files() {
1322         die "${FUNCNAME}() is invalid for python-r1 suite"
1323 }
1324
1325 python_clean_installation_image() {
1326         die "${FUNCNAME}() is invalid for python-r1 suite"
1327 }
1328
1329 python_execute_function() {
1330         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"
1331 }
1332
1333 python_generate_wrapper_scripts() {
1334         die "${FUNCNAME}() is invalid for python-r1 suite"
1335 }
1336
1337 python_merge_intermediate_installation_images() {
1338         die "${FUNCNAME}() is invalid for python-r1 suite"
1339 }
1340
1341 python_set_active_version() {
1342         die "${FUNCNAME}() is invalid for python-r1 suite, please take a look @ https://wiki.gentoo.org/wiki/Project:Python/Python.eclass_conversion#pkg_setup"
1343 }
1344
1345 python_need_rebuild() {
1346         die "${FUNCNAME}() is invalid for python-r1 suite"
1347 }
1348
1349 PYTHON() {
1350         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"
1351 }
1352
1353 python_get_implementation() {
1354         die "${FUNCNAME}() is invalid for python-r1 suite"
1355 }
1356
1357 python_get_implementational_package() {
1358         die "${FUNCNAME}() is invalid for python-r1 suite"
1359 }
1360
1361 python_get_libdir() {
1362         die "${FUNCNAME}() is invalid for python-r1 suite"
1363 }
1364
1365 python_get_library() {
1366         die "${FUNCNAME}() is invalid for python-r1 suite"
1367 }
1368
1369 python_get_version() {
1370         die "${FUNCNAME}() is invalid for python-r1 suite"
1371 }
1372
1373 python_get_implementation_and_version() {
1374         die "${FUNCNAME}() is invalid for python-r1 suite"
1375 }
1376
1377 python_execute_nosetests() {
1378         die "${FUNCNAME}() is invalid for python-r1 suite"
1379 }
1380
1381 python_execute_py.test() {
1382         die "${FUNCNAME}() is invalid for python-r1 suite"
1383 }
1384
1385 python_execute_trial() {
1386         die "${FUNCNAME}() is invalid for python-r1 suite"
1387 }
1388
1389 python_enable_pyc() {
1390         die "${FUNCNAME}() is invalid for python-r1 suite"
1391 }
1392
1393 python_disable_pyc() {
1394         die "${FUNCNAME}() is invalid for python-r1 suite"
1395 }
1396
1397 python_mod_optimize() {
1398         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"
1399 }
1400
1401 python_mod_cleanup() {
1402         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"
1403 }
1404
1405 # python.eclass::progress
1406
1407 python_abi_depend() {
1408         die "${FUNCNAME}() is invalid for python-r1 suite"
1409 }
1410
1411 python_install_executables() {
1412         die "${FUNCNAME}() is invalid for python-r1 suite"
1413 }
1414
1415 python_get_extension_module_suffix() {
1416         die "${FUNCNAME}() is invalid for python-r1 suite"
1417 }
1418
1419 python_byte-compile_modules() {
1420         die "${FUNCNAME}() is invalid for python-r1 suite"
1421 }
1422
1423 python_clean_byte-compiled_modules() {
1424         die "${FUNCNAME}() is invalid for python-r1 suite"
1425 }
1426
1427 python_generate_cffi_modules() {
1428         die "${FUNCNAME}() is invalid for python-r1 suite"
1429 }
1430
1431 _PYTHON_UTILS_R1=1
1432 fi