/[gentoo-x86]/eclass/python-distutils-ng.eclass
Gentoo

Diff of /eclass/python-distutils-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.15 Revision 1.23
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2012 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/Attic/python-distutils-ng.eclass,v 1.15 2012/05/03 00:31:58 floppym Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/Attic/python-distutils-ng.eclass,v 1.23 2012/05/21 18:10:33 nelchael Exp $
4 4
5# @ECLASS: python-distutils-ng 5# @ECLASS: python-distutils-ng
6# @MAINTAINER: 6# @MAINTAINER:
7# Python herd <python@gentoo.org> 7# Python herd <python@gentoo.org>
8# @AUTHOR: 8# @AUTHOR:
9# Author: Krzysztof Pawlik <nelchael@gentoo.org> 9# Author: Krzysztof Pawlik <nelchael@gentoo.org>
10# @BLURB: An eclass for installing Python packages using distutils with proper 10# @BLURB: Install Python packages using distutils.
11# support for multiple Python slots.
12# @DESCRIPTION: 11# @DESCRIPTION:
13# The Python eclass is designed to allow an easier installation of Python 12# The Python eclass is designed to allow an easier installation of Python
14# packages and their incorporation into the Gentoo Linux system. 13# packages and their incorporation into the Gentoo Linux system.
15# 14#
16# This eclass provides functions for following phases: 15# This eclass provides functions for following phases:
26# - src_install - you can define python_install function that will be run for 25# - src_install - you can define python_install function that will be run for
27# each implementation and python_install_all that will be run in original 26# each implementation and python_install_all that will be run in original
28# directory (so it will not contain any implementation-specific files) 27# directory (so it will not contain any implementation-specific files)
29 28
30# @ECLASS-VARIABLE: PYTHON_COMPAT 29# @ECLASS-VARIABLE: PYTHON_COMPAT
30# @DEFAULT_UNSET
31# @DESCRIPTION: 31# @DESCRIPTION:
32# This variable contains a space separated list of implementations (see above) a 32# This variable contains a space separated list of implementations (see above) a
33# package is compatible to. It must be set before the `inherit' call. The 33# package is compatible to. It must be set before the `inherit' call. The
34# default is to enable all implementations. 34# default is to enable all implementations.
35 35
40 PYTHON_COMPAT+=" jython2_5" 40 PYTHON_COMPAT+=" jython2_5"
41 PYTHON_COMPAT+=" pypy1_7 pypy1_8" 41 PYTHON_COMPAT+=" pypy1_7 pypy1_8"
42fi 42fi
43 43
44# @ECLASS-VARIABLE: PYTHON_OPTIONAL 44# @ECLASS-VARIABLE: PYTHON_OPTIONAL
45# @DEFAULT_UNSET
45# @DESCRIPTION: 46# @DESCRIPTION:
46# Set the value to "yes" to make the dependency on a Python interpreter 47# Set the value to "yes" to make the dependency on a Python interpreter
47# optional. 48# optional.
48 49
49# @ECLASS-VARIABLE: PYTHON_DISABLE_COMPILATION 50# @ECLASS-VARIABLE: PYTHON_DISABLE_COMPILATION
51# @DEFAULT_UNSET
50# @DESCRIPTION: 52# @DESCRIPTION:
51# Set the value to "yes" to skip compilation and/or optimization of Python 53# Set the value to "yes" to skip compilation and/or optimization of Python
52# modules. 54# modules.
55
56# @ECLASS-VARIABLE: PYTHON_DISABLE_SCRIPT_REDOS
57# @DEFAULT_UNSET
58# @DESCRIPTION:
59# Set to any value to disable automatic reinstallation of scripts in bin
60# directories. See python-distutils-ng_src_install function.
53 61
54EXPORT_FUNCTIONS pkg_pretend src_prepare src_configure src_compile src_test src_install 62EXPORT_FUNCTIONS pkg_pretend src_prepare src_configure src_compile src_test src_install
55 63
56case "${EAPI}" in 64case "${EAPI}" in
57 0|1|2|3) 65 0|1|2|3)
61 S="${S:-${WORKDIR}/${P}}" 69 S="${S:-${WORKDIR}/${P}}"
62 ;; 70 ;;
63 *) 71 *)
64 die "Unsupported EAPI=${EAPI} (unknown) for python-distutils-ng.eclass" ;; 72 die "Unsupported EAPI=${EAPI} (unknown) for python-distutils-ng.eclass" ;;
65esac 73esac
74
75DEPEND="${DEPEND} !<sys-apps/portage-2.1.10.58"
66 76
67# @FUNCTION: _python-distutils-ng_get_binary_for_implementation 77# @FUNCTION: _python-distutils-ng_get_binary_for_implementation
68# @USAGE: implementation 78# @USAGE: implementation
69# @RETURN: Full path to Python binary for given implementation. 79# @RETURN: Full path to Python binary for given implementation.
70# @DESCRIPTION: 80# @DESCRIPTION:
169 179
170# @FUNCTION: _python-distutils-ng_default_distutils_install 180# @FUNCTION: _python-distutils-ng_default_distutils_install
171# @DESCRIPTION: 181# @DESCRIPTION:
172# Default src_install for distutils-based packages. 182# Default src_install for distutils-based packages.
173_python-distutils-ng_default_distutils_install() { 183_python-distutils-ng_default_distutils_install() {
174 "${PYTHON}" setup.py install --no-compile --root="${D}/" || die 184 local compile_flags="--compile -O2"
175}
176 185
177# @FUNCTION: _python-distutils-ng_has_compileall
178# @USAGE: implementation
179# @RETURN: 0 if given implementation has compileall module
180# @DESCRIPTION:
181# This function is used to decide whenever to compile Python modules for given
182# implementation.
183_python-distutils-ng_has_compileall() {
184 case "${1}" in 186 case "${1}" in
185 python?_?|jython?_?) 187 jython*)
186 return 0 ;; 188 # Jython does not support optimizations
187 *) 189 compile_flags="--compile" ;;
188 return 1 ;;
189 esac 190 esac
190}
191 191
192# @FUNCTION: _python-distutils-ng_has_compileall_opt 192 unset PYTHONDONTWRITEBYTECODE
193# @USAGE: implementation 193 [[ -n "${PYTHON_DISABLE_COMPILATION}" ]] && compile_flags="--no-compile"
194# @RETURN: 0 if given implementation has compileall module and supports # optimizations 194 "${PYTHON}" setup.py install ${compile_flags} --root="${D}" || die
195# @DESCRIPTION:
196# This function is used to decide whenever to compile and optimize Python
197# modules for given implementation.
198_python-distutils-ng_has_compileall_opt() {
199 case "${1}" in
200 python?_?)
201 return 0 ;;
202 *)
203 return 1 ;;
204 esac
205} 195}
206 196
207# @FUNCTION: python-distutils-ng_redoscript 197# @FUNCTION: python-distutils-ng_redoscript
208# @USAGE: script_file_path [destination_directory] 198# @USAGE: script_file_path [destination_directory]
209# @DESCRIPTION: 199# @DESCRIPTION:
210# Reinstall script installed already by setup.py. This works by first moving the 200# Reinstall script installed already by setup.py. This works by first moving the
211# script to ${T} directory and later running python-distutils-ng_doscript on it. 201# script to ${T} directory and later running python-distutils-ng_doscript on it.
212# script_file_path has to be a full path relative to ${D}. 202# script_file_path has to be a full path relative to ${D}.
203# Warning: this function can be run automatically by the eclass in src_install,
204# see python-distutils-ng_src_install and PYTHON_DISABLE_SCRIPT_REDOS variable.
213python-distutils-ng_redoscript() { 205python-distutils-ng_redoscript() {
214 local sbn="$(basename "${1}")" 206 local sbn="$(basename "${1}")"
215 mkdir -p "${T}/_${sbn}/" || die "failed to create directory" 207 mkdir -p "${T}/_${sbn}/" || die "failed to create directory"
216 mv "${D}/${1}" "${T}/_${sbn}/${sbn}" || die "failed to move file" 208 mv "${D}${1}" "${T}/_${sbn}/${sbn}" || die "failed to move file"
217 python-distutils-ng_doscript "${T}/_${sbn}/${sbn}" "${2}" 209 python-distutils-ng_doscript "${T}/_${sbn}/${sbn}" "${2}"
218} 210}
219 211
220# @FUNCTION: python-distutils-ng_doscript 212# @FUNCTION: python-distutils-ng_doscript
221# @USAGE: script_file_name [destination_directory] 213# @USAGE: script_file_name [destination_directory]
389 pushd "${S}" &> /dev/null 381 pushd "${S}" &> /dev/null
390 python_install_all 382 python_install_all
391 popd &> /dev/null 383 popd &> /dev/null
392 fi 384 fi
393 385
394 for impl in ${PYTHON_COMPAT}; do 386 if [[ -z "${PYTHON_DISABLE_SCRIPT_REDOS}" ]]; then
395 [[ "${PYTHON_DISABLE_COMPILATION}" = "yes" ]] && continue 387 for script_file in $(find "${D}"{,usr/}{,s}bin/ -type f -executable 2> /dev/null); do
396 use "python_targets_${impl}" ${PYTHON_COMPAT} || continue 388 python-distutils-ng_redoscript "/${script_file#${D}}"
397
398 PYTHON="$(_python-distutils-ng_get_binary_for_implementation "${impl}")"
399 for accessible_path in $(${PYTHON} -c 'import sys; print(" ".join(sys.path))'); do
400 [[ -d "${D}/${accessible_path}" ]] || continue
401
402 _python-distutils-ng_has_compileall "${impl}" || continue
403 ebegin "Compiling ${accessible_path} for ${impl}"
404 ${PYTHON} \
405 -m compileall -q -f "${D}/${accessible_path}" || die
406 eend $?
407
408 _python-distutils-ng_has_compileall_opt "${impl}" || continue
409 ebegin "Optimizing ${accessible_path} for ${impl}"
410 PYTHONOPTIMIZE=1 ${PYTHON} \
411 -m compileall -q -f "${D}/${accessible_path}" || die
412 eend $?
413 done; 389 done
414 done 390 fi
415} 391}

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.23

  ViewVC Help
Powered by ViewVC 1.1.20