/[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.5 Revision 1.18
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.5 2012/03/26 19:12:28 nelchael Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/Attic/python-distutils-ng.eclass,v 1.18 2012/05/05 18:03:33 floppym 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:
23# each implementation, default function will run `setup.py build' 23# each implementation, default function will run `setup.py build'
24# - src_test - you can define python_test function that will be run for each 24# - src_test - you can define python_test function that will be run for each
25# implementation 25# implementation
26# - src_install - you can define python_install function that will be run for 26# - 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 27# each implementation and python_install_all that will be run in original
28# directory (so it wil lnot contain any implementation-specific files) 28# directory (so it will not contain any implementation-specific files)
29 29
30# @ECLASS-VARIABLE: PYTHON_COMPAT 30# @ECLASS-VARIABLE: PYTHON_COMPAT
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
49# @ECLASS-VARIABLE: PYTHON_DISABLE_COMPILATION 49# @ECLASS-VARIABLE: PYTHON_DISABLE_COMPILATION
50# @DESCRIPTION: 50# @DESCRIPTION:
51# Set the value to "yes" to skip compilation and/or optimization of Python 51# Set the value to "yes" to skip compilation and/or optimization of Python
52# modules. 52# modules.
53 53
54EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install 54EXPORT_FUNCTIONS pkg_pretend src_prepare src_configure src_compile src_test src_install
55 55
56case "${EAPI}" in 56case "${EAPI}" in
57 0|1|2|3) 57 0|1|2|3)
58 die "Unsupported EAPI=${EAPI} (too old) for python-distutils-ng.eclass" ;; 58 die "Unsupported EAPI=${EAPI} (too old) for python-distutils-ng.eclass" ;;
59 4) 59 4)
61 S="${S:-${WORKDIR}/${P}}" 61 S="${S:-${WORKDIR}/${P}}"
62 ;; 62 ;;
63 *) 63 *)
64 die "Unsupported EAPI=${EAPI} (unknown) for python-distutils-ng.eclass" ;; 64 die "Unsupported EAPI=${EAPI} (unknown) for python-distutils-ng.eclass" ;;
65esac 65esac
66
67# @FUNCTION: _python-distutils-ng_generate_depend
68# @USAGE: implementation
69# @RETURN: Package atom of a Python implementation for *DEPEND.
70# @DESCRIPTION:
71# This function returns the full package atom of a Python implementation.
72#
73# `implementation' has to be one of the valid values for PYTHON_COMPAT.
74_python-distutils-ng_generate_depend() {
75 local impl="${1/_/.}"
76 case "${impl}" in
77 python?.?)
78 echo "dev-lang/python:${impl: -3}" ;;
79 jython?.?)
80 echo "dev-java/jython:${impl: -3}" ;;
81 pypy?.?)
82 echo "dev-python/pypy:${impl: -3}" ;;
83 *)
84 die "Unsupported implementation: ${1}" ;;
85 esac
86}
87 66
88# @FUNCTION: _python-distutils-ng_get_binary_for_implementation 67# @FUNCTION: _python-distutils-ng_get_binary_for_implementation
89# @USAGE: implementation 68# @USAGE: implementation
90# @RETURN: Full path to Python binary for given implementation. 69# @RETURN: Full path to Python binary for given implementation.
91# @DESCRIPTION: 70# @DESCRIPTION:
118fi 97fi
119unset required_use_str 98unset required_use_str
120 99
121for impl in ${PYTHON_COMPAT}; do 100for impl in ${PYTHON_COMPAT}; do
122 IUSE+=" python_targets_${impl}" 101 IUSE+=" python_targets_${impl}"
123 dep_str="python_targets_${impl}? ( $(_python-distutils-ng_generate_depend "${impl}") )" 102 dep_str="${impl/_/.}"
103 case "${dep_str}" in
104 python?.?)
105 dep_str="dev-lang/python:${dep_str: -3}" ;;
106 jython?.?)
107 dep_str="dev-java/jython:${dep_str: -3}" ;;
108 pypy?.?)
109 dep_str="dev-python/pypy:${dep_str: -3}" ;;
110 *)
111 die "Unsupported implementation: ${impl}" ;;
112 esac
113 dep_str="python_targets_${impl}? ( ${dep_str} )"
124 114
125 if [[ "${PYTHON_OPTIONAL}" = "yes" ]]; then 115 if [[ "${PYTHON_OPTIONAL}" = "yes" ]]; then
126 RDEPEND="${RDEPEND} python? ( ${dep_str} )" 116 RDEPEND="${RDEPEND} python? ( ${dep_str} )"
127 DEPEND="${DEPEND} python? ( ${dep_str} )" 117 DEPEND="${DEPEND} python? ( ${dep_str} )"
128 else 118 else
142# This will run the command_to_run in implementation-specific working directory. 132# This will run the command_to_run in implementation-specific working directory.
143_python-distutils-ng_run_for_impl() { 133_python-distutils-ng_run_for_impl() {
144 local impl="${1}" 134 local impl="${1}"
145 local command="${2}" 135 local command="${2}"
146 136
147 S="${WORKDIR}/impl_${impl}/${_PACKAGE_SPECIFIC_S}" 137 local S="${WORKDIR}/impl_${impl}/${_PACKAGE_SPECIFIC_S}"
148 PYTHON="$(_python-distutils-ng_get_binary_for_implementation "${impl}")" 138 PYTHON="$(_python-distutils-ng_get_binary_for_implementation "${impl}")"
149 EPYTHON="${impl/_/.}" 139 EPYTHON="${impl/_/.}"
150 140
151 einfo "Running ${command} in ${S} for ${impl}" 141 einfo "Running ${command} in ${S} for ${impl}"
152 142
179 169
180# @FUNCTION: _python-distutils-ng_default_distutils_install 170# @FUNCTION: _python-distutils-ng_default_distutils_install
181# @DESCRIPTION: 171# @DESCRIPTION:
182# Default src_install for distutils-based packages. 172# Default src_install for distutils-based packages.
183_python-distutils-ng_default_distutils_install() { 173_python-distutils-ng_default_distutils_install() {
184 "${PYTHON}" setup.py install --no-compile --root="${D}/" || die 174 local compile_flags="--compile -O2"
185}
186 175
187# @FUNCTION: _python-distutils-ng_has_compileall
188# @USAGE: implementation
189# @RETURN: 0 if given implementation has compileall module
190# @DESCRIPTION:
191# This function is used to decide whenever to compile Python modules for given
192# implementation.
193_python-distutils-ng_has_compileall() {
194 case "${1}" in 176 case "${1}" in
195 python?_?|jython?_?) 177 jython*)
196 return 0 ;; 178 # Jython does not support optimizations
197 *) 179 compile_flags="--compile" ;;
198 return 1 ;;
199 esac 180 esac
200}
201 181
182 unset PYTHONDONTWRITEBYTECODE
183 [[ -n "${PYTHON_DISABLE_COMPILATION}" ]] && compile_flags="--no-compile"
184 "${PYTHON}" setup.py install ${compile_flags} --root="${D}" || die
185}
186
202# @FUNCTION: _python-distutils-ng_has_compileall_opt 187# @FUNCTION: python-distutils-ng_redoscript
203# @USAGE: implementation 188# @USAGE: script_file_path [destination_directory]
204# @RETURN: 0 if given implementation has compileall module and supports # optimizations
205# @DESCRIPTION: 189# @DESCRIPTION:
206# This function is used to decide whenever to compile and optimize Python 190# Reinstall script installed already by setup.py. This works by first moving the
207# modules for given implementation. 191# script to ${T} directory and later running python-distutils-ng_doscript on it.
192# script_file_path has to be a full path relative to ${D}.
208_python-distutils-ng_has_compileall_opt() { 193python-distutils-ng_redoscript() {
209 case "${1}" in 194 local sbn="$(basename "${1}")"
210 python?_?) 195 mkdir -p "${T}/_${sbn}/" || die "failed to create directory"
211 return 0 ;; 196 mv "${D}${1}" "${T}/_${sbn}/${sbn}" || die "failed to move file"
212 *) 197 python-distutils-ng_doscript "${T}/_${sbn}/${sbn}" "${2}"
213 return 1 ;;
214 esac
215} 198}
216 199
217# @FUNCTION: python-distutils-ng_doscript 200# @FUNCTION: python-distutils-ng_doscript
218# @USAGE: script_file_name [destination_directory] 201# @USAGE: script_file_name [destination_directory]
219# @DESCRIPTION: 202# @DESCRIPTION:
265 use "python_targets_${impl}" || continue 248 use "python_targets_${impl}" || continue
266 default_impl="${impl}" 249 default_impl="${impl}"
267 break 250 break
268 done 251 done
269 else 252 else
270 use "python_targets_${impl}" || \ 253 use "python_targets_${default_impl}" || \
271 die "default implementation ${default_impl} not enabled" 254 die "default implementation ${default_impl} not enabled"
272 fi 255 fi
273 256
274 [[ -n "${default_impl}" ]] || die "Could not select default implementation" 257 [[ -n "${default_impl}" ]] || die "Could not select default implementation"
275 258
296 279
297 dosym "${destination_file}-${default_impl}" "${destination_directory}/${destination_file}" 280 dosym "${destination_file}-${default_impl}" "${destination_directory}/${destination_file}"
298 fi 281 fi
299} 282}
300 283
284# Phase function: pkg_pretend
285python-distutils-ng_pkg_pretend() {
286 if has "collision-protect" ${FEATURES}; then
287 ewarn "Due to previous eclass compiling Python files outside of src_install"
288 ewarn "(and not recording resulting .pyc and .pyo files as owned by any package)"
289 ewarn "merging this package with \"collision-protect\" in FEATURES may result"
290 ewarn "in an error, please switch to using \"protect-owned\" instead."
291 fi
292}
293
301# Phase function: src_prepare 294# Phase function: src_prepare
302python-distutils-ng_src_prepare() { 295python-distutils-ng_src_prepare() {
303 [[ "${PYTHON_OPTIONAL}" = "yes" ]] && { use python || return; } 296 [[ "${PYTHON_OPTIONAL}" = "yes" ]] && { use python || return; }
304 297
305 # Try to run binary for each implementation: 298 # Try to run binary for each implementation:
369 else 362 else
370 _python-distutils-ng_run_for_each_impl \ 363 _python-distutils-ng_run_for_each_impl \
371 _python-distutils-ng_default_distutils_install 364 _python-distutils-ng_default_distutils_install
372 fi 365 fi
373 366
374 S="${WORKDIR}/${_PACKAGE_SPECIFIC_S}"
375 if type python_install_all &> /dev/null; then 367 if type python_install_all &> /dev/null; then
376 einfo "Running python_install_all in ${S} for all" 368 einfo "Running python_install_all in ${S} for all"
369 pushd "${S}" &> /dev/null
377 python_install_all 370 python_install_all
371 popd &> /dev/null
378 fi 372 fi
379
380 for impl in ${PYTHON_COMPAT}; do
381 [[ "${PYTHON_DISABLE_COMPILATION}" = "yes" ]] && continue
382 use "python_targets_${impl}" ${PYTHON_COMPAT} || continue
383
384 PYTHON="$(_python-distutils-ng_get_binary_for_implementation "${impl}")"
385 for accessible_path in $(${PYTHON} -c 'import sys; print " ".join(sys.path)'); do
386 [[ -d "${D}/${accessible_path}" ]] || continue
387
388 _python-distutils-ng_has_compileall "${impl}" || continue
389 ebegin "Compiling ${accessible_path} for ${impl}"
390 ${PYTHON} \
391 -m compileall -q -f "${D}/${accessible_path}" || die
392 eend $?
393
394 _python-distutils-ng_has_compileall_opt "${impl}" || continue
395 ebegin "Optimizing ${accessible_path} for ${impl}"
396 PYTHONOPTIMIZE=1 ${PYTHON} \
397 -m compileall -q -f "${D}/${accessible_path}" || die
398 eend $?
399 done;
400 done
401} 373}

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.20