/[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.8 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.8 2012/03/28 14:21:55 marienz 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)
132# 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.
133_python-distutils-ng_run_for_impl() { 133_python-distutils-ng_run_for_impl() {
134 local impl="${1}" 134 local impl="${1}"
135 local command="${2}" 135 local command="${2}"
136 136
137 S="${WORKDIR}/impl_${impl}/${_PACKAGE_SPECIFIC_S}" 137 local S="${WORKDIR}/impl_${impl}/${_PACKAGE_SPECIFIC_S}"
138 PYTHON="$(_python-distutils-ng_get_binary_for_implementation "${impl}")" 138 PYTHON="$(_python-distutils-ng_get_binary_for_implementation "${impl}")"
139 EPYTHON="${impl/_/.}" 139 EPYTHON="${impl/_/.}"
140 140
141 einfo "Running ${command} in ${S} for ${impl}" 141 einfo "Running ${command} in ${S} for ${impl}"
142 142
169 169
170# @FUNCTION: _python-distutils-ng_default_distutils_install 170# @FUNCTION: _python-distutils-ng_default_distutils_install
171# @DESCRIPTION: 171# @DESCRIPTION:
172# Default src_install for distutils-based packages. 172# Default src_install for distutils-based packages.
173_python-distutils-ng_default_distutils_install() { 173_python-distutils-ng_default_distutils_install() {
174 "${PYTHON}" setup.py install --no-compile --root="${D}/" || die 174 local compile_flags="--compile -O2"
175}
176 175
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 176 case "${1}" in
185 python?_?|jython?_?) 177 jython*)
186 return 0 ;; 178 # Jython does not support optimizations
187 *) 179 compile_flags="--compile" ;;
188 return 1 ;;
189 esac 180 esac
190}
191 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
192# @FUNCTION: _python-distutils-ng_has_compileall_opt 187# @FUNCTION: python-distutils-ng_redoscript
193# @USAGE: implementation 188# @USAGE: script_file_path [destination_directory]
194# @RETURN: 0 if given implementation has compileall module and supports # optimizations
195# @DESCRIPTION: 189# @DESCRIPTION:
196# 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
197# 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}.
198_python-distutils-ng_has_compileall_opt() { 193python-distutils-ng_redoscript() {
199 case "${1}" in 194 local sbn="$(basename "${1}")"
200 python?_?) 195 mkdir -p "${T}/_${sbn}/" || die "failed to create directory"
201 return 0 ;; 196 mv "${D}${1}" "${T}/_${sbn}/${sbn}" || die "failed to move file"
202 *) 197 python-distutils-ng_doscript "${T}/_${sbn}/${sbn}" "${2}"
203 return 1 ;;
204 esac
205} 198}
206 199
207# @FUNCTION: python-distutils-ng_doscript 200# @FUNCTION: python-distutils-ng_doscript
208# @USAGE: script_file_name [destination_directory] 201# @USAGE: script_file_name [destination_directory]
209# @DESCRIPTION: 202# @DESCRIPTION:
255 use "python_targets_${impl}" || continue 248 use "python_targets_${impl}" || continue
256 default_impl="${impl}" 249 default_impl="${impl}"
257 break 250 break
258 done 251 done
259 else 252 else
260 use "python_targets_${impl}" || \ 253 use "python_targets_${default_impl}" || \
261 die "default implementation ${default_impl} not enabled" 254 die "default implementation ${default_impl} not enabled"
262 fi 255 fi
263 256
264 [[ -n "${default_impl}" ]] || die "Could not select default implementation" 257 [[ -n "${default_impl}" ]] || die "Could not select default implementation"
265 258
286 279
287 dosym "${destination_file}-${default_impl}" "${destination_directory}/${destination_file}" 280 dosym "${destination_file}-${default_impl}" "${destination_directory}/${destination_file}"
288 fi 281 fi
289} 282}
290 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
291# Phase function: src_prepare 294# Phase function: src_prepare
292python-distutils-ng_src_prepare() { 295python-distutils-ng_src_prepare() {
293 [[ "${PYTHON_OPTIONAL}" = "yes" ]] && { use python || return; } 296 [[ "${PYTHON_OPTIONAL}" = "yes" ]] && { use python || return; }
294 297
295 # Try to run binary for each implementation: 298 # Try to run binary for each implementation:
359 else 362 else
360 _python-distutils-ng_run_for_each_impl \ 363 _python-distutils-ng_run_for_each_impl \
361 _python-distutils-ng_default_distutils_install 364 _python-distutils-ng_default_distutils_install
362 fi 365 fi
363 366
364 S="${WORKDIR}/${_PACKAGE_SPECIFIC_S}"
365 if type python_install_all &> /dev/null; then 367 if type python_install_all &> /dev/null; then
366 einfo "Running python_install_all in ${S} for all" 368 einfo "Running python_install_all in ${S} for all"
369 pushd "${S}" &> /dev/null
367 python_install_all 370 python_install_all
371 popd &> /dev/null
368 fi 372 fi
369
370 for impl in ${PYTHON_COMPAT}; do
371 [[ "${PYTHON_DISABLE_COMPILATION}" = "yes" ]] && continue
372 use "python_targets_${impl}" ${PYTHON_COMPAT} || continue
373
374 PYTHON="$(_python-distutils-ng_get_binary_for_implementation "${impl}")"
375 for accessible_path in $(${PYTHON} -c 'import sys; print " ".join(sys.path)'); do
376 [[ -d "${D}/${accessible_path}" ]] || continue
377
378 _python-distutils-ng_has_compileall "${impl}" || continue
379 ebegin "Compiling ${accessible_path} for ${impl}"
380 ${PYTHON} \
381 -m compileall -q -f "${D}/${accessible_path}" || die
382 eend $?
383
384 _python-distutils-ng_has_compileall_opt "${impl}" || continue
385 ebegin "Optimizing ${accessible_path} for ${impl}"
386 PYTHONOPTIMIZE=1 ${PYTHON} \
387 -m compileall -q -f "${D}/${accessible_path}" || die
388 eend $?
389 done;
390 done
391} 373}

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

  ViewVC Help
Powered by ViewVC 1.1.20