/[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.2 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.2 2012/03/26 06:12:53 jlec 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/${impl::-3}:${impl: -3}" ;;
79 jython?.?)
80 echo "dev-java/${impl::-3}:${impl: -3}" ;;
81 pypy?.?)
82 echo "dev-python/${impl::-3}:${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:
103 *) 82 *)
104 die "Unsupported implementation: ${1}" ;; 83 die "Unsupported implementation: ${1}" ;;
105 esac 84 esac
106} 85}
107 86
108required_use_str=" || ( 87required_use_str=""
109 python_targets_python2_5 python_targets_python2_6 python_targets_python2_7 88for impl in ${PYTHON_COMPAT}; do
110 python_targets_python3_1 python_targets_python3_2 89 required_use_str+=" python_targets_${impl}"
111 python_targets_jython2_5 90done
112 python_targets_pypy1_7 python_targets_pypy1_8 )" 91required_use_str=" || ( ${required_use_str} )"
113if [[ "${PYTHON_OPTIONAL}" = "yes" ]]; then 92if [[ "${PYTHON_OPTIONAL}" = "yes" ]]; then
114 IUSE+="python" 93 IUSE+=" python"
115 REQUIRED_USE+=" python? ( ${required_use_str} )" 94 REQUIRED_USE+=" python? ( ${required_use_str} )"
116else 95else
117 REQUIRED_USE+=" ${required_use_str}" 96 REQUIRED_USE+=" ${required_use_str}"
118fi 97fi
98unset required_use_str
119 99
120for impl in ${PYTHON_COMPAT}; do 100for impl in ${PYTHON_COMPAT}; do
121 IUSE+=" python_targets_${impl} " 101 IUSE+=" python_targets_${impl}"
122 local 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} )"
123 114
124 if [[ "${PYTHON_OPTIONAL}" = "yes" ]]; then 115 if [[ "${PYTHON_OPTIONAL}" = "yes" ]]; then
125 RDEPEND="${RDEPEND} python? ( ${dep_str} )" 116 RDEPEND="${RDEPEND} python? ( ${dep_str} )"
126 DEPEND="${DEPEND} python? ( ${dep_str} )" 117 DEPEND="${DEPEND} python? ( ${dep_str} )"
127 else 118 else
128 RDEPEND="${RDEPEND} ${dep_str}" 119 RDEPEND="${RDEPEND} ${dep_str}"
129 DEPEND="${DEPEND} ${dep_str}" 120 DEPEND="${DEPEND} ${dep_str}"
130 fi 121 fi
122 unset dep_str
131done 123done
132 124
133_PACKAGE_SPECIFIC_S="${S#${WORKDIR}/}" 125_PACKAGE_SPECIFIC_S="${S#${WORKDIR}/}"
134 126
135# @FUNCTION: _python-distutils-ng_run_for_impl 127# @FUNCTION: _python-distutils-ng_run_for_impl
140# 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.
141_python-distutils-ng_run_for_impl() { 133_python-distutils-ng_run_for_impl() {
142 local impl="${1}" 134 local impl="${1}"
143 local command="${2}" 135 local command="${2}"
144 136
145 S="${WORKDIR}/impl_${impl}/${_PACKAGE_SPECIFIC_S}" 137 local S="${WORKDIR}/impl_${impl}/${_PACKAGE_SPECIFIC_S}"
146 PYTHON="$(_python-distutils-ng_get_binary_for_implementation "${impl}")" 138 PYTHON="$(_python-distutils-ng_get_binary_for_implementation "${impl}")"
147 EPYTHON="${impl/_/.}" 139 EPYTHON="${impl/_/.}"
148 140
149 einfo "Running ${command} in ${S} for ${impl}" 141 einfo "Running ${command} in ${S} for ${impl}"
150 142
177 169
178# @FUNCTION: _python-distutils-ng_default_distutils_install 170# @FUNCTION: _python-distutils-ng_default_distutils_install
179# @DESCRIPTION: 171# @DESCRIPTION:
180# Default src_install for distutils-based packages. 172# Default src_install for distutils-based packages.
181_python-distutils-ng_default_distutils_install() { 173_python-distutils-ng_default_distutils_install() {
182 "${PYTHON}" setup.py install --no-compile --root="${D}/" || die 174 local compile_flags="--compile -O2"
183}
184 175
185# @FUNCTION: _python-distutils-ng_has_compileall
186# @USAGE: implementation
187# @RETURN: 0 if given implementation has compileall module
188# @DESCRIPTION:
189# This function is used to decide whenever to compile Python modules for given
190# implementation.
191_python-distutils-ng_has_compileall() {
192 case "${1}" in 176 case "${1}" in
193 python?_?|jython?_?) 177 jython*)
194 return 0 ;; 178 # Jython does not support optimizations
195 *) 179 compile_flags="--compile" ;;
196 return 1 ;;
197 esac 180 esac
198}
199 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
200# @FUNCTION: _python-distutils-ng_has_compileall_opt 187# @FUNCTION: python-distutils-ng_redoscript
201# @USAGE: implementation 188# @USAGE: script_file_path [destination_directory]
202# @RETURN: 0 if given implementation has compileall module and supports # optimizations
203# @DESCRIPTION: 189# @DESCRIPTION:
204# 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
205# 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}.
206_python-distutils-ng_has_compileall_opt() { 193python-distutils-ng_redoscript() {
207 case "${1}" in 194 local sbn="$(basename "${1}")"
208 python?_?) 195 mkdir -p "${T}/_${sbn}/" || die "failed to create directory"
209 return 0 ;; 196 mv "${D}${1}" "${T}/_${sbn}/${sbn}" || die "failed to move file"
210 *) 197 python-distutils-ng_doscript "${T}/_${sbn}/${sbn}" "${2}"
211 return 1 ;;
212 esac
213} 198}
214 199
215# @FUNCTION: python-distutils-ng_doscript 200# @FUNCTION: python-distutils-ng_doscript
216# @USAGE: script_file_name [destination_directory] 201# @USAGE: script_file_name [destination_directory]
217# @DESCRIPTION: 202# @DESCRIPTION:
263 use "python_targets_${impl}" || continue 248 use "python_targets_${impl}" || continue
264 default_impl="${impl}" 249 default_impl="${impl}"
265 break 250 break
266 done 251 done
267 else 252 else
268 use "python_targets_${impl}" || \ 253 use "python_targets_${default_impl}" || \
269 die "default implementation ${default_impl} not enabled" 254 die "default implementation ${default_impl} not enabled"
270 fi 255 fi
271 256
272 [[ -n "${default_impl}" ]] || die "Could not select default implementation" 257 [[ -n "${default_impl}" ]] || die "Could not select default implementation"
273 258
294 279
295 dosym "${destination_file}-${default_impl}" "${destination_directory}/${destination_file}" 280 dosym "${destination_file}-${default_impl}" "${destination_directory}/${destination_file}"
296 fi 281 fi
297} 282}
298 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
299# Phase function: src_prepare 294# Phase function: src_prepare
300python-distutils-ng_src_prepare() { 295python-distutils-ng_src_prepare() {
301 [[ "${PYTHON_OPTIONAL}" = "yes" ]] && { use python || return; } 296 [[ "${PYTHON_OPTIONAL}" = "yes" ]] && { use python || return; }
302 297
303 # Try to run binary for each implementation: 298 # Try to run binary for each implementation:
367 else 362 else
368 _python-distutils-ng_run_for_each_impl \ 363 _python-distutils-ng_run_for_each_impl \
369 _python-distutils-ng_default_distutils_install 364 _python-distutils-ng_default_distutils_install
370 fi 365 fi
371 366
372 S="${WORKDIR}/${_PACKAGE_SPECIFIC_S}"
373 if type python_install_all &> /dev/null; then 367 if type python_install_all &> /dev/null; then
374 einfo "Running python_install_all in ${S} for all" 368 einfo "Running python_install_all in ${S} for all"
369 pushd "${S}" &> /dev/null
375 python_install_all 370 python_install_all
371 popd &> /dev/null
376 fi 372 fi
377
378 for impl in ${PYTHON_COMPAT}; do
379 [[ "${PYTHON_DISABLE_COMPILATION}" = "yes" ]] && continue
380 use "python_targets_${impl}" ${PYTHON_COMPAT} || continue
381
382 PYTHON="$(_python-distutils-ng_get_binary_for_implementation "${impl}")"
383 for accessible_path in $(${PYTHON} -c 'import sys; print " ".join(sys.path)'); do
384 [[ -d "${D}/${accessible_path}" ]] || continue
385
386 _python-distutils-ng_has_compileall "${impl}" || continue
387 ebegin "Compiling ${accessible_path} for ${impl}"
388 ${PYTHON} \
389 -m compileall -q -f "${D}/${accessible_path}" || die
390 eend $?
391
392 _python-distutils-ng_has_compileall_opt "${impl}" || continue
393 ebegin "Optimizing ${accessible_path} for ${impl}"
394 PYTHONOPTIMIZE=1 ${PYTHON} \
395 -m compileall -q -f "${D}/${accessible_path}" || die
396 eend $?
397 done;
398 done
399} 373}

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

  ViewVC Help
Powered by ViewVC 1.1.20