/[gentoo-x86]/eclass/distutils.eclass
Gentoo

Diff of /eclass/distutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.57 Revision 1.68
1# Copyright 1999-2009 Gentoo Foundation 1# Copyright 1999-2009 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/distutils.eclass,v 1.57 2009/08/02 00:30:29 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/distutils.eclass,v 1.68 2009/12/24 04:21:39 arfrever Exp $
4 4
5# @ECLASS: distutils.eclass 5# @ECLASS: distutils.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# <python@gentoo.org> 7# <python@gentoo.org>
8# 8#
10# @BLURB: This eclass allows easier installation of distutils-based python modules 10# @BLURB: This eclass allows easier installation of distutils-based python modules
11# @DESCRIPTION: 11# @DESCRIPTION:
12# The distutils eclass is designed to allow easier installation of 12# The distutils eclass is designed to allow easier installation of
13# distutils-based python modules and their incorporation into 13# distutils-based python modules and their incorporation into
14# the Gentoo Linux system. 14# the Gentoo Linux system.
15#
16# It inherits python, multilib, and eutils
17 15
18inherit python multilib eutils 16inherit eutils multilib python
19 17
20case "${EAPI:-0}" in 18case "${EAPI:-0}" in
21 0|1) 19 0|1)
22 EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_postinst pkg_postrm 20 EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_postinst pkg_postrm
23 ;; 21 ;;
24 *) 22 *)
25 EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install pkg_postinst pkg_postrm 23 EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install pkg_postinst pkg_postrm
26 ;; 24 ;;
27esac 25esac
28 26
29# @ECLASS-VARIABLE: PYTHON_SLOT_VERSION 27if [[ -z "${DISTUTILS_DISABLE_PYTHON_DEPENDENCY}" ]]; then
30# @DESCRIPTION: 28 DEPEND="virtual/python"
31# This helps make it possible to add extensions to python slots. 29 RDEPEND="${DEPEND}"
32# Normally only a -py21- ebuild would set PYTHON_SLOT_VERSION. 30fi
33if [ "${PYTHON_SLOT_VERSION}" = "2.1" ] ; then 31
34 DEPEND="=dev-lang/python-2.1*" 32if has "${EAPI:-0}" 0 1 2; then
35 python="python2.1" 33 python="python"
36elif [ "${PYTHON_SLOT_VERSION}" = "2.3" ] ; then
37 DEPEND="=dev-lang/python-2.3*"
38 python="python2.3"
39else 34else
40 DEPEND="virtual/python" 35 python="die"
41 python="python"
42fi 36fi
43 37
38# @ECLASS-VARIABLE: DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES
39# @DESCRIPTION:
40# Set this to use separate source directories for each enabled version of Python.
41
42# @ECLASS-VARIABLE: DISTUTILS_GLOBAL_OPTIONS
43# @DESCRIPTION:
44# Global options passed to setup.py.
45
46# @ECLASS-VARIABLE: DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS
47# @DESCRIPTION:
48# Set this to disable renaming of Python scripts containing versioned shebangs
49# and generation of wrapper scripts.
50
44# @ECLASS-VARIABLE: DOCS 51# @ECLASS-VARIABLE: DOCS
45# @DESCRIPTION: 52# @DESCRIPTION:
46# Additional DOCS 53# Additional DOCS
47 54
55_distutils_hook() {
56 if [[ "$#" -ne 1 ]]; then
57 die "${FUNCNAME}() requires 1 argument"
58 fi
59 if [[ "$(type -t "distutils_src_${EBUILD_PHASE}_$1_hook")" == "function" ]]; then
60 "distutils_src_${EBUILD_PHASE}_$1_hook"
61 fi
62}
63
48# @FUNCTION: distutils_src_unpack 64# @FUNCTION: distutils_src_unpack
49# @DESCRIPTION: 65# @DESCRIPTION:
50# The distutils src_unpack function, this function is exported 66# The distutils src_unpack function, this function is exported.
51distutils_src_unpack() { 67distutils_src_unpack() {
68 if [[ "${EBUILD_PHASE}" != "unpack" ]]; then
69 die "${FUNCNAME}() can be used only in src_unpack() phase"
70 fi
71
52 unpack ${A} 72 unpack ${A}
53 cd "${S}" 73 cd "${S}"
54 74
55 has "${EAPI:-0}" 0 1 && distutils_src_prepare 75 has "${EAPI:-0}" 0 1 && distutils_src_prepare
56} 76}
57 77
58# @FUNCTION: distutils_src_prepare 78# @FUNCTION: distutils_src_prepare
59# @DESCRIPTION: 79# @DESCRIPTION:
60# The distutils src_prepare function, this function is exported 80# The distutils src_prepare function, this function is exported.
61distutils_src_prepare() { 81distutils_src_prepare() {
62 # remove ez_setup stuff to prevent packages 82 if ! has "${EAPI:-0}" 0 1 && [[ "${EBUILD_PHASE}" != "prepare" ]]; then
63 # from installing setuptools on their own 83 die "${FUNCNAME}() can be used only in src_prepare() phase"
84 fi
85
86 # Delete ez_setup files to prevent packages from installing
87 # Setuptools on their own.
88 local ez_setup_existence="0"
89 [[ -d ez_setup || -f ez_setup.py ]] && ez_setup_existence="1"
64 rm -rf ez_setup* 90 rm -fr ez_setup*
91 if [[ "${ez_setup_existence}" == "1" ]]; then
65 echo "def use_setuptools(*args, **kwargs): pass" > ez_setup.py 92 echo "def use_setuptools(*args, **kwargs): pass" > ez_setup.py
93 fi
94
95 # Delete distribute_setup files to prevent packages from installing
96 # Distribute on their own.
97 local distribute_setup_existence="0"
98 [[ -d distribute_setup || -f distribute_setup.py ]] && distribute_setup_existence="1"
99 rm -fr distribute_setup*
100 if [[ "${distribute_setup_existence}" == "1" ]]; then
101 echo "def use_setuptools(*args, **kwargs): pass" > distribute_setup.py
102 fi
103
104 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
105 python_copy_sources
106 fi
66} 107}
67 108
68# @FUNCTION: distutils_src_compile 109# @FUNCTION: distutils_src_compile
69# @DESCRIPTION: 110# @DESCRIPTION:
70# The distutils src_compile function, this function is exported 111# The distutils src_compile function, this function is exported.
112# In newer EAPIs this function calls distutils_src_compile_pre_hook() and
113# distutils_src_compile_post_hook(), if they are defined.
71distutils_src_compile() { 114distutils_src_compile() {
115 if [[ "${EBUILD_PHASE}" != "compile" ]]; then
116 die "${FUNCNAME}() can be used only in src_compile() phase"
117 fi
118
72 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 119 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
73 build_modules() { 120 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
74 echo "$(get_python)" setup.py build -b "build-${PYTHON_ABI}" "$@" 121 building() {
75 "$(get_python)" setup.py build -b "build-${PYTHON_ABI}" "$@" 122 _distutils_hook pre
123
124 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@"
125 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || return "$?"
126
127 _distutils_hook post
76 } 128 }
129 python_execute_function -s building "$@"
130 else
131 building() {
132 _distutils_hook pre
133
134 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" "$@"
135 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" "$@" || return "$?"
136
137 _distutils_hook post
138 }
77 python_execute_function build_modules "$@" 139 python_execute_function building "$@"
140 fi
78 else 141 else
79 ${python} setup.py build "$@" || die "compilation failed" 142 python_version
143 echo "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@"
144 "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || die "Building failed"
80 fi 145 fi
81} 146}
82 147
83# @FUNCTION: distutils_src_install 148# @FUNCTION: distutils_src_install
84# @DESCRIPTION: 149# @DESCRIPTION:
85# The distutils src_install function, this function is exported. 150# The distutils src_install function, this function is exported.
151# In newer EAPIs this function calls distutils_src_install_pre_hook() and
152# distutils_src_install_post_hook(), if they are defined.
86# It also installs the "standard docs" (CHANGELOG, Change*, KNOWN_BUGS, MAINTAINERS, 153# It also installs the "standard docs" (CHANGELOG, Change*, KNOWN_BUGS, MAINTAINERS,
87# PKG-INFO, CONTRIBUTORS, TODO, NEWS, MANIFEST*, README*, and AUTHORS) 154# PKG-INFO, CONTRIBUTORS, TODO, NEWS, MANIFEST*, README*, and AUTHORS)
88distutils_src_install() { 155distutils_src_install() {
156 if [[ "${EBUILD_PHASE}" != "install" ]]; then
157 die "${FUNCNAME}() can be used only in src_install() phase"
158 fi
159
160 local pylibdir
89 161
90 # Mark the package to be rebuilt after a python upgrade. 162 # Mark the package to be rebuilt after a python upgrade.
91 python_need_rebuild 163 python_need_rebuild
92 164
93 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 165 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
94 install_modules() { 166 if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${BASH_VERSINFO[0]}" -ge "4" ]]; then
167 declare -A wrapper_scripts=()
168
169 rename_scripts_with_versioned_shebangs() {
170 if [[ -d "${D}usr/bin" ]]; then
171 cd "${D}usr/bin"
172
173 local file
174 for file in *; do
175 if [[ -f "${file}" && ! "${file}" =~ [[:digit:]]+\.[[:digit:]]+$ && "$(head -n1 "${file}")" =~ ^'#!'.*python[[:digit:]]+\.[[:digit:]]+ ]]; then
176 mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed"
177 wrapper_scripts+=(["${D}usr/bin/${file}"]=)
178 fi
179 done
180 fi
181 }
182 fi
183
184 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
185 installation() {
186 _distutils_hook pre
187
95 # need this for python-2.5 + setuptools in cases where 188 # need this for python-2.5 + setuptools in cases where
96 # a package uses distutils but does not install anything 189 # a package uses distutils but does not install anything
97 # in site-packages. (eg. dev-java/java-config-2.x) 190 # in site-packages. (eg. dev-java/java-config-2.x)
98 # - liquidx (14/08/2006) 191 # - liquidx (14/08/2006)
99 pylibdir="$("$(get_python)" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')" 192 pylibdir="$("$(PYTHON)" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
100 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}" 193 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
101 194
102 echo "$(get_python)" setup.py build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@" 195 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@"
103 "$(get_python)" setup.py build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@" 196 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || return "$?"
197
198 if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${BASH_VERSINFO[0]}" -ge "4" ]]; then
199 rename_scripts_with_versioned_shebangs
200 fi
201
202 _distutils_hook post
104 } 203 }
204 python_execute_function -s installation "$@"
205 else
206 installation() {
207 _distutils_hook pre
208
209 # need this for python-2.5 + setuptools in cases where
210 # a package uses distutils but does not install anything
211 # in site-packages. (eg. dev-java/java-config-2.x)
212 # - liquidx (14/08/2006)
213 pylibdir="$("$(PYTHON)" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
214 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
215
216 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@"
217 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@" || return "$?"
218
219 if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${BASH_VERSINFO[0]}" -ge "4" ]]; then
220 rename_scripts_with_versioned_shebangs
221 fi
222
223 _distutils_hook post
224 }
105 python_execute_function install_modules "$@" 225 python_execute_function installation "$@"
226 fi
227
228 if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${#wrapper_scripts[@]}" -ne "0" && "${BASH_VERSINFO[0]}" -ge "4" ]]; then
229 python_generate_wrapper_scripts "${!wrapper_scripts[@]}"
230 fi
231 unset wrapper_scripts
106 else 232 else
107 # need this for python-2.5 + setuptools in cases where 233 # need this for python-2.5 + setuptools in cases where
108 # a package uses distutils but does not install anything 234 # a package uses distutils but does not install anything
109 # in site-packages. (eg. dev-java/java-config-2.x) 235 # in site-packages. (eg. dev-java/java-config-2.x)
110 # - liquidx (14/08/2006) 236 # - liquidx (14/08/2006)
111 pylibdir="$(${python} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')" 237 pylibdir="$("$(PYTHON "${PYVER}")" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
112 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}" 238 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
113 239
114 ${python} setup.py install --root="${D}" --no-compile "$@" || die "python setup.py install failed" 240 echo "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@"
241 "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || die "Installation failed"
115 fi 242 fi
116 243
117 DDOCS="CHANGELOG KNOWN_BUGS MAINTAINERS PKG-INFO CONTRIBUTORS TODO NEWS" 244 if [[ -e "${D}usr/local" ]]; then
118 DDOCS="${DDOCS} Change* MANIFEST* README* AUTHORS" 245 die "Illegal installation into /usr/local"
246 fi
247
248 local default_docs
249 default_docs="AUTHORS Change* CHANGELOG CONTRIBUTORS KNOWN_BUGS MAINTAINERS MANIFEST* NEWS PKG-INFO README* TODO"
119 250
120 local doc 251 local doc
121 for doc in ${DDOCS}; do 252 for doc in ${default_docs}; do
122 [[ -s "$doc" ]] && dodoc $doc 253 [[ -s "${doc}" ]] && dodoc "${doc}"
123 done 254 done
124 255
125 [[ -n "${DOCS}" ]] && dodoc ${DOCS} 256 if [[ -n "${DOCS}" ]]; then
257 dodoc ${DOCS} || die "dodoc failed"
258 fi
126} 259}
127 260
128# @FUNCTION: distutils_pkg_postrm 261# @FUNCTION: distutils_pkg_postinst
129# @DESCRIPTION: 262# @DESCRIPTION:
130# Generic pyc/pyo cleanup script. This function is exported. 263# This is a generic optimization, you should override it if your package
264# installs modules in another directory. This function is exported.
131distutils_pkg_postrm() { 265distutils_pkg_postinst() {
266 if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
267 die "${FUNCNAME}() can be used only in pkg_postinst() phase"
268 fi
269
132 local pylibdir pymod 270 local pylibdir pymod
133 if [[ -z "${PYTHON_MODNAME}" ]]; then 271 if [[ -z "${PYTHON_MODNAME}" ]]; then
134 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do 272 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
135 if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then 273 if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
136 PYTHON_MODNAME="${PN}" 274 PYTHON_MODNAME="${PN}"
137 fi 275 fi
138 done 276 done
139 fi 277 fi
140 278
141 ebegin "Performing cleanup of Python modules..." 279 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
142 if [[ -n "${PYTHON_MODNAME}" ]]; then 280 python_mod_optimize ${PYTHON_MODNAME}
281 else
143 for pymod in ${PYTHON_MODNAME}; do 282 for pymod in ${PYTHON_MODNAME}; do
144 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do 283 python_mod_optimize "$(python_get_sitedir)/${pymod}"
145 if [[ -d "${pylibdir}/site-packages/${pymod}" ]]; then
146 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
147 python_mod_cleanup "${pymod}"
148 else
149 python_mod_cleanup "${pylibdir#${ROOT}}/site-packages/${pymod}"
150 fi
151 fi
152 done
153 done 284 done
154 else
155 python_mod_cleanup
156 fi 285 fi
157 eend 0
158} 286}
159 287
160# @FUNCTION: distutils_pkg_postinst 288# @FUNCTION: distutils_pkg_postrm
161# @DESCRIPTION: 289# @DESCRIPTION:
162# This is a generic optimization, you should override it if your package 290# Generic pyc/pyo cleanup script. This function is exported.
163# installs modules in another directory. This function is exported.
164distutils_pkg_postinst() { 291distutils_pkg_postrm() {
292 if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
293 die "${FUNCNAME}() can be used only in pkg_postrm() phase"
294 fi
295
165 local pylibdir pymod 296 local pylibdir pymod
166 if [[ -z "${PYTHON_MODNAME}" ]]; then 297 if [[ -z "${PYTHON_MODNAME}" ]]; then
167 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do 298 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
168 if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then 299 if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
169 PYTHON_MODNAME="${PN}" 300 PYTHON_MODNAME="${PN}"
170 fi 301 fi
171 done 302 done
172 fi 303 fi
173 304
305 if [[ -n "${PYTHON_MODNAME}" ]]; then
174 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 306 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
307 python_mod_cleanup ${PYTHON_MODNAME}
308 else
175 for pymod in ${PYTHON_MODNAME}; do 309 for pymod in ${PYTHON_MODNAME}; do
176 python_mod_optimize "${pymod}" 310 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
311 if [[ -d "${pylibdir}/site-packages/${pymod}" ]]; then
312 python_mod_cleanup "${pylibdir#${ROOT}}/site-packages/${pymod}"
313 fi
314 done
177 done 315 done
316 fi
178 else 317 else
179 python_version 318 python_mod_cleanup
180 for pymod in ${PYTHON_MODNAME}; do
181 python_mod_optimize "/usr/$(get_libdir)/python${PYVER}/site-packages/${pymod}"
182 done
183 fi 319 fi
184} 320}
185 321
186# @FUNCTION: distutils_python_version 322# @FUNCTION: distutils_python_version
187# @DESCRIPTION: 323# @DESCRIPTION:
188# Calls python_version, so that you can use something like 324# Calls python_version, so that you can use something like
189# e.g. insinto ${ROOT}/usr/include/python${PYVER} 325# e.g. insinto ${ROOT}/usr/include/python${PYVER}
190distutils_python_version() { 326distutils_python_version() {
327 if ! has "${EAPI:-0}" 0 1 2; then
328 die "${FUNCNAME}() cannot be used in this EAPI"
329 fi
330
191 python_version 331 python_version
192} 332}
193 333
194# @FUNCTION: distutils_python_tkinter 334# @FUNCTION: distutils_python_tkinter
195# @DESCRIPTION: 335# @DESCRIPTION:
196# Checks for if tkinter support is compiled into python 336# Checks for if tkinter support is compiled into python
197distutils_python_tkinter() { 337distutils_python_tkinter() {
338 if ! has "${EAPI:-0}" 0 1 2; then
339 die "${FUNCNAME}() cannot be used in this EAPI"
340 fi
341
198 python_tkinter_exists 342 python_tkinter_exists
199} 343}

Legend:
Removed from v.1.57  
changed lines
  Added in v.1.68

  ViewVC Help
Powered by ViewVC 1.1.20