/[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.31
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2013 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.31 2013/09/29 15:04:51 mgorny Exp $
4
5# @DEAD
6# Michał Górny <mgorny@gentoo.org> (29 Sep 2013)
7# This eclass has been superseded by distutils-r1 and python-r1 eclasses
8# and will be removed on 2013-10-29. Please modify your ebuilds to use
9# the new eclasses instead. Bug #450770.
4 10
5# @ECLASS: python-distutils-ng 11# @ECLASS: python-distutils-ng
6# @MAINTAINER: 12# @MAINTAINER:
7# Python herd <python@gentoo.org> 13# Python herd <python@gentoo.org>
8# @AUTHOR: 14# @AUTHOR:
9# Author: Krzysztof Pawlik <nelchael@gentoo.org> 15# Author: Krzysztof Pawlik <nelchael@gentoo.org>
10# @BLURB: An eclass for installing Python packages using distutils with proper 16# @BLURB: Install Python packages using distutils.
11# support for multiple Python slots.
12# @DESCRIPTION: 17# @DESCRIPTION:
13# The Python eclass is designed to allow an easier installation of Python 18# The Python eclass is designed to allow an easier installation of Python
14# packages and their incorporation into the Gentoo Linux system. 19# packages and their incorporation into the Gentoo Linux system.
15# 20#
16# This eclass provides functions for following phases: 21# This eclass provides functions for following phases:
23# each implementation, default function will run `setup.py build' 28# each implementation, default function will run `setup.py build'
24# - src_test - you can define python_test function that will be run for each 29# - src_test - you can define python_test function that will be run for each
25# implementation 30# implementation
26# - src_install - you can define python_install function that will be run for 31# - 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 32# each implementation and python_install_all that will be run in original
28# directory (so it wil lnot contain any implementation-specific files) 33# directory (so it will not contain any implementation-specific files)
29 34
30# @ECLASS-VARIABLE: PYTHON_COMPAT 35# @ECLASS-VARIABLE: PYTHON_COMPAT
36# @DEFAULT_UNSET
31# @DESCRIPTION: 37# @DESCRIPTION:
32# This variable contains a space separated list of implementations (see above) a 38# 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 39# package is compatible to. It must be set before the `inherit' call. The
34# default is to enable all implementations. 40# default is to enable all implementations.
35 41
36if [[ -z "${PYTHON_COMPAT}" ]]; then 42if [[ -z "${PYTHON_COMPAT}" ]]; then
37 # Default: pure python, support all implementations 43 # Default: pure python, support all implementations
38 PYTHON_COMPAT=" python2_5 python2_6 python2_7" 44 PYTHON_COMPAT=" python2_5 python2_6 python2_7"
39 PYTHON_COMPAT+=" python3_1 python3_2" 45 PYTHON_COMPAT+=" python3_1 python3_2"
40 PYTHON_COMPAT+=" jython2_5" 46 PYTHON_COMPAT+=" jython2_5"
41 PYTHON_COMPAT+=" pypy1_7 pypy1_8" 47 PYTHON_COMPAT+=" pypy1_8 pypy1_9"
42fi 48fi
43 49
44# @ECLASS-VARIABLE: PYTHON_OPTIONAL 50# @ECLASS-VARIABLE: PYTHON_OPTIONAL
51# @DEFAULT_UNSET
45# @DESCRIPTION: 52# @DESCRIPTION:
46# Set the value to "yes" to make the dependency on a Python interpreter 53# Set the value to "yes" to make the dependency on a Python interpreter
47# optional. 54# optional.
48 55
49# @ECLASS-VARIABLE: PYTHON_DISABLE_COMPILATION 56# @ECLASS-VARIABLE: PYTHON_DISABLE_COMPILATION
57# @DEFAULT_UNSET
50# @DESCRIPTION: 58# @DESCRIPTION:
51# Set the value to "yes" to skip compilation and/or optimization of Python 59# Set the value to "yes" to skip compilation and/or optimization of Python
52# modules. 60# modules.
61
62# @ECLASS-VARIABLE: PYTHON_DISABLE_SCRIPT_REDOS
63# @DEFAULT_UNSET
64# @DESCRIPTION:
65# Set to any value to disable automatic reinstallation of scripts in bin
66# directories. See python-distutils-ng_src_install function.
67
68# @ECLASS-VARIABLE: PYTHON_USE
69# @DEFAULT_UNSET
70# @DESCRIPTION:
71# Comma-separated list of useflags needed for all(!) allowed
72# implementations. This is directly substituted into one or more of
73# dev-lang/python[${PYTHON_USE}], dev-python/pypy[${PYTHON_USE}] and
74# dev-java/jython[${PYTHON_USE}].
75# @CODE
76# example 1: PYTHON_USE="xml,sqlite"
77# example 2: PYTHON_USE="xml?,threads?,-foo"
78# @CODE
53 79
54EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install 80EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
55 81
56case "${EAPI}" in 82case "${EAPI}" in
57 0|1|2|3) 83 0|1|2|3)
58 die "Unsupported EAPI=${EAPI} (too old) for python-distutils-ng.eclass" ;; 84 die "Unsupported EAPI=${EAPI} (too old) for python-distutils-ng.eclass" ;;
59 4) 85 4|5)
60 # EAPI=4 needed for REQUIRED_USE 86 # EAPI=4 needed for REQUIRED_USE
61 S="${S:-${WORKDIR}/${P}}" 87 S="${S:-${WORKDIR}/${P}}"
62 ;; 88 ;;
63 *) 89 *)
64 die "Unsupported EAPI=${EAPI} (unknown) for python-distutils-ng.eclass" ;; 90 die "Unsupported EAPI=${EAPI} (unknown) for python-distutils-ng.eclass" ;;
65esac 91esac
66 92
93DEPEND="${DEPEND} !<sys-apps/portage-2.1.10.58"
94
67# @FUNCTION: _python-distutils-ng_get_binary_for_implementation 95# @FUNCTION: _python-distutils-ng_get_binary_for_implementation
68# @USAGE: implementation 96# @USAGE: implementation
69# @RETURN: Full path to Python binary for given implementation. 97# @RETURN: Full path to Python binary for given implementation.
70# @DESCRIPTION: 98# @DESCRIPTION:
71# This function returns full path for Python binary for given implementation. 99# This function returns full path for Python binary for given implementation.
74# `python'. 102# `python'.
75_python-distutils-ng_get_binary_for_implementation() { 103_python-distutils-ng_get_binary_for_implementation() {
76 local impl="${1/_/.}" 104 local impl="${1/_/.}"
77 case "${impl}" in 105 case "${impl}" in
78 python?.?|jython?.?) 106 python?.?|jython?.?)
79 echo "/usr/bin/${impl}" ;; 107 echo "${EPREFIX}/usr/bin/${impl}" ;;
80 pypy?.?) 108 pypy?.?)
81 echo "/usr/bin/pypy-c${impl: -3}" ;; 109 echo "${EPREFIX}/usr/bin/pypy-c${impl: -3}" ;;
82 *) 110 *)
83 die "Unsupported implementation: ${1}" ;; 111 die "Unsupported implementation: ${1}" ;;
84 esac 112 esac
85} 113}
86 114
95else 123else
96 REQUIRED_USE+=" ${required_use_str}" 124 REQUIRED_USE+=" ${required_use_str}"
97fi 125fi
98unset required_use_str 126unset required_use_str
99 127
128# avoid empty use deps
129_PYTHON_USE="${PYTHON_USE:+[${PYTHON_USE}]}"
130
131# set python DEPEND and RDEPEND
100for impl in ${PYTHON_COMPAT}; do 132for impl in ${PYTHON_COMPAT}; do
101 IUSE+=" python_targets_${impl}" 133 IUSE+=" python_targets_${impl}"
102 dep_str="${impl/_/.}" 134 dep_str="${impl/_/.}"
103 case "${dep_str}" in 135 case "${dep_str}" in
104 python?.?) 136 python?.?)
105 dep_str="dev-lang/python:${dep_str: -3}" ;; 137 dep_str="dev-lang/python:${dep_str: -3}${_PYTHON_USE}" ;;
106 jython?.?) 138 jython?.?)
107 dep_str="dev-java/jython:${dep_str: -3}" ;; 139 dep_str="dev-java/jython:${dep_str: -3}${_PYTHON_USE}" ;;
108 pypy?.?) 140 pypy?.?)
109 dep_str="dev-python/pypy:${dep_str: -3}" ;; 141 dep_str="virtual/pypy:${dep_str: -3}${_PYTHON_USE}" ;;
110 *) 142 *)
111 die "Unsupported implementation: ${impl}" ;; 143 die "Unsupported implementation: ${impl}" ;;
112 esac 144 esac
113 dep_str="python_targets_${impl}? ( ${dep_str} )" 145 dep_str="python_targets_${impl}? ( ${dep_str} )"
114 146
132# This will run the command_to_run in implementation-specific working directory. 164# This will run the command_to_run in implementation-specific working directory.
133_python-distutils-ng_run_for_impl() { 165_python-distutils-ng_run_for_impl() {
134 local impl="${1}" 166 local impl="${1}"
135 local command="${2}" 167 local command="${2}"
136 168
137 S="${WORKDIR}/impl_${impl}/${_PACKAGE_SPECIFIC_S}" 169 local S="${WORKDIR}/impl_${impl}/${_PACKAGE_SPECIFIC_S}"
138 PYTHON="$(_python-distutils-ng_get_binary_for_implementation "${impl}")" 170 PYTHON="$(_python-distutils-ng_get_binary_for_implementation "${impl}")"
139 EPYTHON="${impl/_/.}" 171 EPYTHON="${impl/_/.}"
140 172
141 einfo "Running ${command} in ${S} for ${impl}" 173 einfo "Running ${command} in ${S} for ${impl}"
142 174
169 201
170# @FUNCTION: _python-distutils-ng_default_distutils_install 202# @FUNCTION: _python-distutils-ng_default_distutils_install
171# @DESCRIPTION: 203# @DESCRIPTION:
172# Default src_install for distutils-based packages. 204# Default src_install for distutils-based packages.
173_python-distutils-ng_default_distutils_install() { 205_python-distutils-ng_default_distutils_install() {
174 "${PYTHON}" setup.py install --no-compile --root="${D}/" || die 206 local compile_flags="--compile -O2"
175}
176 207
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 208 case "${1}" in
185 python?_?|jython?_?) 209 jython*)
186 return 0 ;; 210 # Jython does not support optimizations
187 *) 211 compile_flags="--compile" ;;
188 return 1 ;;
189 esac 212 esac
190}
191 213
214 unset PYTHONDONTWRITEBYTECODE
215 [[ -n "${PYTHON_DISABLE_COMPILATION}" ]] && compile_flags="--no-compile"
216 "${PYTHON}" setup.py install ${compile_flags} --root="${D}" || die
217}
218
219# @FUNCTION: python-distutils-ng_rewrite_hashbang
220# @USAGE: script_file_name implementation
221# @DESCRIPTION:
222# Rewrite #! line in named script, dies if #! line is not for Python or missing.
223python-distutils-ng_rewrite_hashbang() {
224 [[ -n "${1}" ]] || die "Missing file name"
225 [[ -n "${2}" ]] || die "Missing implementation"
226 local file_name="${1}"
227 local binary="$(_python-distutils-ng_get_binary_for_implementation "${2}")"
228 [[ $(head -n 1 "${file_name}") == '#!'*(python|jython|pypy-c)* ]] || \
229 die "Missing or invalid #! line in ${file_name}"
230 sed -i -e "1c#!${binary}" "${file_name}" || die
231}
232
192# @FUNCTION: _python-distutils-ng_has_compileall_opt 233# @FUNCTION: python-distutils-ng_redoscript
193# @USAGE: implementation 234# @USAGE: script_file_path [destination_directory]
194# @RETURN: 0 if given implementation has compileall module and supports # optimizations
195# @DESCRIPTION: 235# @DESCRIPTION:
196# This function is used to decide whenever to compile and optimize Python 236# Reinstall script installed already by setup.py. This works by first moving the
197# modules for given implementation. 237# script to ${T} directory and later running python-distutils-ng_doscript on it.
238# script_file_path has to be a full path relative to ${D}.
239# Warning: this function can be run automatically by the eclass in src_install,
240# see python-distutils-ng_src_install and PYTHON_DISABLE_SCRIPT_REDOS variable.
198_python-distutils-ng_has_compileall_opt() { 241python-distutils-ng_redoscript() {
199 case "${1}" in 242 local sbn="$(basename "${1}")"
200 python?_?) 243 mkdir -p "${T}/_${sbn}/" || die "failed to create directory"
201 return 0 ;; 244 mv "${D}${1}" "${T}/_${sbn}/${sbn}" || die "failed to move file"
202 *) 245 python-distutils-ng_doscript "${T}/_${sbn}/${sbn}" "${2}"
203 return 1 ;;
204 esac
205} 246}
206 247
207# @FUNCTION: python-distutils-ng_doscript 248# @FUNCTION: python-distutils-ng_doscript
208# @USAGE: script_file_name [destination_directory] 249# @USAGE: script_file_name [destination_directory]
209# @DESCRIPTION: 250# @DESCRIPTION:
249 use "python_targets_${impl}" || continue 290 use "python_targets_${impl}" || continue
250 enabled_impls=$((enabled_impls + 1)) 291 enabled_impls=$((enabled_impls + 1))
251 done 292 done
252 293
253 if [[ -z "${default_impl}" ]]; then 294 if [[ -z "${default_impl}" ]]; then
254 for impl in python{2_7,2_6,2_5,3_2,3_1} pypy{1_8,1_7} jython2_5; do 295 for impl in python{2_7,2_6,2_5,3_2,3_1} pypy{1_9,1_8,1_7} jython2_5; do
255 use "python_targets_${impl}" || continue 296 use "python_targets_${impl}" || continue
256 default_impl="${impl}" 297 default_impl="${impl}"
257 break 298 break
258 done 299 done
259 else 300 else
260 use "python_targets_${impl}" || \ 301 use "python_targets_${default_impl}" || \
261 die "default implementation ${default_impl} not enabled" 302 die "default implementation ${default_impl} not enabled"
262 fi 303 fi
263 304
264 [[ -n "${default_impl}" ]] || die "Could not select default implementation" 305 [[ -n "${default_impl}" ]] || die "Could not select default implementation"
265 306
267 insinto "${destination_directory}" 308 insinto "${destination_directory}"
268 if [[ "${enabled_impls}" = "1" ]]; then 309 if [[ "${enabled_impls}" = "1" ]]; then
269 einfo "Installing ${source_file} for single implementation (${default_impl}) in ${destination_directory}" 310 einfo "Installing ${source_file} for single implementation (${default_impl}) in ${destination_directory}"
270 newins "${source_file}" "${destination_file}" 311 newins "${source_file}" "${destination_file}"
271 fperms 755 "${destination_directory}/${destination_file}" 312 fperms 755 "${destination_directory}/${destination_file}"
272 sed -i \ 313 python-distutils-ng_rewrite_hashbang "${D}${destination_directory}/${destination_file}" "${default_impl}"
273 -e "1i#!$(_python-distutils-ng_get_binary_for_implementation "${impl}")" \
274 "${D}${destination_directory}/${destination_file}" || die
275 else 314 else
276 einfo "Installing ${source_file} for multiple implementations (default: ${default_impl}) in ${destination_directory}" 315 einfo "Installing ${source_file} for multiple implementations (default: ${default_impl}) in ${destination_directory}"
277 for impl in ${PYTHON_COMPAT}; do 316 for impl in ${PYTHON_COMPAT}; do
278 use "python_targets_${impl}" ${PYTHON_COMPAT} || continue 317 use "python_targets_${impl}" ${PYTHON_COMPAT} || continue
279 318
280 newins "${source_file}" "${destination_file}-${impl}" 319 newins "${source_file}" "${destination_file}-${impl}"
281 fperms 755 "${destination_directory}/${destination_file}-${impl}" 320 fperms 755 "${destination_directory}/${destination_file}-${impl}"
282 sed -i \ 321 python-distutils-ng_rewrite_hashbang "${D}${destination_directory}/${destination_file}-${impl}" "${impl}"
283 -e "1i#!$(_python-distutils-ng_get_binary_for_implementation "${impl}")" \
284 "${D}${destination_directory}/${destination_file}-${impl}" || die
285 done 322 done
286 323
287 dosym "${destination_file}-${default_impl}" "${destination_directory}/${destination_file}" 324 dosym "${destination_file}-${default_impl}" "${destination_directory}/${destination_file}"
288 fi 325 fi
289} 326}
359 else 396 else
360 _python-distutils-ng_run_for_each_impl \ 397 _python-distutils-ng_run_for_each_impl \
361 _python-distutils-ng_default_distutils_install 398 _python-distutils-ng_default_distutils_install
362 fi 399 fi
363 400
364 S="${WORKDIR}/${_PACKAGE_SPECIFIC_S}"
365 if type python_install_all &> /dev/null; then 401 if type python_install_all &> /dev/null; then
366 einfo "Running python_install_all in ${S} for all" 402 einfo "Running python_install_all in ${S} for all"
403 pushd "${S}" &> /dev/null
367 python_install_all 404 python_install_all
405 popd &> /dev/null
368 fi 406 fi
369 407
370 for impl in ${PYTHON_COMPAT}; do 408 if [[ -z "${PYTHON_DISABLE_SCRIPT_REDOS}" ]]; then
371 [[ "${PYTHON_DISABLE_COMPILATION}" = "yes" ]] && continue 409 for script_file in $(find "${ED}"{,usr/}{,s}bin/ -type f -executable 2> /dev/null); do
372 use "python_targets_${impl}" ${PYTHON_COMPAT} || continue 410 python-distutils-ng_redoscript "/${script_file#${D}}"
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; 411 done
390 done 412 fi
391} 413}

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

  ViewVC Help
Powered by ViewVC 1.1.20