/[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.18 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.18 2012/05/05 18:03:33 floppym 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:
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 will not 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.
53 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
79
54EXPORT_FUNCTIONS pkg_pretend 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
182 unset PYTHONDONTWRITEBYTECODE 214 unset PYTHONDONTWRITEBYTECODE
183 [[ -n "${PYTHON_DISABLE_COMPILATION}" ]] && compile_flags="--no-compile" 215 [[ -n "${PYTHON_DISABLE_COMPILATION}" ]] && compile_flags="--no-compile"
184 "${PYTHON}" setup.py install ${compile_flags} --root="${D}" || die 216 "${PYTHON}" setup.py install ${compile_flags} --root="${D}" || die
185} 217}
186 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
187# @FUNCTION: python-distutils-ng_redoscript 233# @FUNCTION: python-distutils-ng_redoscript
188# @USAGE: script_file_path [destination_directory] 234# @USAGE: script_file_path [destination_directory]
189# @DESCRIPTION: 235# @DESCRIPTION:
190# Reinstall script installed already by setup.py. This works by first moving the 236# Reinstall script installed already by setup.py. This works by first moving the
191# script to ${T} directory and later running python-distutils-ng_doscript on it. 237# 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}. 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.
193python-distutils-ng_redoscript() { 241python-distutils-ng_redoscript() {
194 local sbn="$(basename "${1}")" 242 local sbn="$(basename "${1}")"
195 mkdir -p "${T}/_${sbn}/" || die "failed to create directory" 243 mkdir -p "${T}/_${sbn}/" || die "failed to create directory"
196 mv "${D}${1}" "${T}/_${sbn}/${sbn}" || die "failed to move file" 244 mv "${D}${1}" "${T}/_${sbn}/${sbn}" || die "failed to move file"
197 python-distutils-ng_doscript "${T}/_${sbn}/${sbn}" "${2}" 245 python-distutils-ng_doscript "${T}/_${sbn}/${sbn}" "${2}"
242 use "python_targets_${impl}" || continue 290 use "python_targets_${impl}" || continue
243 enabled_impls=$((enabled_impls + 1)) 291 enabled_impls=$((enabled_impls + 1))
244 done 292 done
245 293
246 if [[ -z "${default_impl}" ]]; then 294 if [[ -z "${default_impl}" ]]; then
247 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
248 use "python_targets_${impl}" || continue 296 use "python_targets_${impl}" || continue
249 default_impl="${impl}" 297 default_impl="${impl}"
250 break 298 break
251 done 299 done
252 else 300 else
260 insinto "${destination_directory}" 308 insinto "${destination_directory}"
261 if [[ "${enabled_impls}" = "1" ]]; then 309 if [[ "${enabled_impls}" = "1" ]]; then
262 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}"
263 newins "${source_file}" "${destination_file}" 311 newins "${source_file}" "${destination_file}"
264 fperms 755 "${destination_directory}/${destination_file}" 312 fperms 755 "${destination_directory}/${destination_file}"
265 sed -i \ 313 python-distutils-ng_rewrite_hashbang "${D}${destination_directory}/${destination_file}" "${default_impl}"
266 -e "1i#!$(_python-distutils-ng_get_binary_for_implementation "${impl}")" \
267 "${D}${destination_directory}/${destination_file}" || die
268 else 314 else
269 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}"
270 for impl in ${PYTHON_COMPAT}; do 316 for impl in ${PYTHON_COMPAT}; do
271 use "python_targets_${impl}" ${PYTHON_COMPAT} || continue 317 use "python_targets_${impl}" ${PYTHON_COMPAT} || continue
272 318
273 newins "${source_file}" "${destination_file}-${impl}" 319 newins "${source_file}" "${destination_file}-${impl}"
274 fperms 755 "${destination_directory}/${destination_file}-${impl}" 320 fperms 755 "${destination_directory}/${destination_file}-${impl}"
275 sed -i \ 321 python-distutils-ng_rewrite_hashbang "${D}${destination_directory}/${destination_file}-${impl}" "${impl}"
276 -e "1i#!$(_python-distutils-ng_get_binary_for_implementation "${impl}")" \
277 "${D}${destination_directory}/${destination_file}-${impl}" || die
278 done 322 done
279 323
280 dosym "${destination_file}-${default_impl}" "${destination_directory}/${destination_file}" 324 dosym "${destination_file}-${default_impl}" "${destination_directory}/${destination_file}"
281 fi
282}
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 325 fi
292} 326}
293 327
294# Phase function: src_prepare 328# Phase function: src_prepare
295python-distutils-ng_src_prepare() { 329python-distutils-ng_src_prepare() {
368 einfo "Running python_install_all in ${S} for all" 402 einfo "Running python_install_all in ${S} for all"
369 pushd "${S}" &> /dev/null 403 pushd "${S}" &> /dev/null
370 python_install_all 404 python_install_all
371 popd &> /dev/null 405 popd &> /dev/null
372 fi 406 fi
407
408 if [[ -z "${PYTHON_DISABLE_SCRIPT_REDOS}" ]]; then
409 for script_file in $(find "${ED}"{,usr/}{,s}bin/ -type f -executable 2> /dev/null); do
410 python-distutils-ng_redoscript "/${script_file#${D}}"
411 done
412 fi
373} 413}

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

  ViewVC Help
Powered by ViewVC 1.1.20