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

Diff of /eclass/distutils.eclass

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

Revision 1.32 Revision 1.72
1# Copyright 1999-2004 Gentoo Foundation 1# Copyright 1999-2010 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.32 2006/08/07 00:21:49 liquidx Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/distutils.eclass,v 1.72 2010/02/08 09:35:38 pva Exp $
4
5# @ECLASS: distutils.eclass
6# @MAINTAINER:
7# Gentoo Python Project <python@gentoo.org>
4# 8#
5# Author: Jon Nelson <jnelson@gentoo.org> 9# Original author: Jon Nelson <jnelson@gentoo.org>
6# Current Maintainer: Alastair Tse <liquidx@gentoo.org> 10# @BLURB: Eclass for packages with build systems using Distutils
7# 11# @DESCRIPTION:
8# The distutils eclass is designed to allow easier installation of 12# The distutils eclass defines phase functions for packages with build systems using Distutils
9# distutils-based python modules and their incorporation into
10# the Gentoo Linux system.
11#
12# - Features:
13# distutils_src_compile() - does python setup.py build
14# distutils_src_install() - does python setup.py install and install docs
15# distutils_python_version() - sets PYVER/PYVER_MAJOR/PYVER_MINOR
16# distutils_python_tkinter() - checks for tkinter support in python
17#
18# - Variables:
19# PYTHON_SLOT_VERSION - for Zope support
20# DOCS - additional DOCS
21 13
22inherit python eutils 14inherit multilib python
23 15
24# This helps make it possible to add extensions to python slots. 16case "${EAPI:-0}" in
25# Normally only a -py21- ebuild would set PYTHON_SLOT_VERSION. 17 0|1)
26if [ "${PYTHON_SLOT_VERSION}" = "2.1" ] ; then 18 EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_postinst pkg_postrm
27 DEPEND="=dev-lang/python-2.1*" 19 ;;
20 *)
21 EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install pkg_postinst pkg_postrm
22 ;;
23esac
24
25if [[ -z "${PYTHON_DEPEND}" ]]; then
26 DEPEND="virtual/python"
27 RDEPEND="${DEPEND}"
28fi
29
30if has "${EAPI:-0}" 0 1 2; then
28 python="python2.1" 31 python="python"
29elif [ "${PYTHON_SLOT_VERSION}" = "2.3" ] ; then
30 DEPEND="=dev-lang/python-2.3*"
31 python="python2.3"
32else 32else
33 DEPEND="virtual/python" 33 # Use "$(PYTHON)" or "$(PYTHON -A)" instead of "${python}".
34 python="python" 34 python="die"
35fi
36
37# @ECLASS-VARIABLE: DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES
38# @DESCRIPTION:
39# Set this to use separate source directories for each enabled version of Python.
40
41# @ECLASS-VARIABLE: DISTUTILS_GLOBAL_OPTIONS
42# @DESCRIPTION:
43# Global options passed to setup.py.
44
45# @ECLASS-VARIABLE: DISTUTILS_SRC_TEST
46# @DESCRIPTION:
47# Type of test command used by distutils_src_test().
48# IUSE and DEPEND are automatically adjusted, unless DISTUTILS_DISABLE_TEST_DEPENDENCY is set.
49# Valid values:
50# setup.py
51# nosetests
52# py.test
53# trial [arguments]
54
55# @ECLASS-VARIABLE: DISTUTILS_DISABLE_TEST_DEPENDENCY
56# @DESCRIPTION:
57# Disable modification of IUSE and DEPEND caused by setting of DISTUTILS_SRC_TEST.
58
59if [[ -n "${DISTUTILS_SRC_TEST}" && ! "${DISTUTILS_SRC_TEST}" =~ ^(setup\.py|nosetests|py\.test|trial(\ .*)?)$ ]]; then
60 die "'DISTUTILS_SRC_TEST' variable has unsupported value '${DISTUTILS_SRC_TEST}'"
61fi
62
63if [[ -z "${DISTUTILS_DISABLE_TEST_DEPENDENCY}" ]]; then
64 if [[ "${DISTUTILS_SRC_TEST}" == "nosetests" ]]; then
65 IUSE="test"
66 DEPEND+="${DEPEND:+ }test? ( dev-python/nose )"
67 elif [[ "${DISTUTILS_SRC_TEST}" == "py.test" ]]; then
68 IUSE="test"
69 DEPEND+="${DEPEND:+ }test? ( dev-python/py )"
70 # trial requires an argument, which is usually equal to "${PN}".
71 elif [[ "${DISTUTILS_SRC_TEST}" =~ ^trial(\ .*)?$ ]]; then
72 IUSE="test"
73 DEPEND+="${DEPEND:+ }test? ( dev-python/twisted )"
35fi 74 fi
75fi
36 76
77if [[ -n "${DISTUTILS_SRC_TEST}" ]]; then
78 EXPORT_FUNCTIONS src_test
79fi
80
81# @ECLASS-VARIABLE: DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS
82# @DESCRIPTION:
83# Set this to disable renaming of Python scripts containing versioned shebangs
84# and generation of wrapper scripts.
85
86# @ECLASS-VARIABLE: DOCS
87# @DESCRIPTION:
88# Additional documentation files installed by distutils_src_install().
89
90_distutils_get_build_dir() {
91 if [[ -n "${SUPPORT_PYTHON_ABIS}" && -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
92 echo "build-${PYTHON_ABI}"
93 else
94 echo "build"
95 fi
96}
97
98_distutils_get_PYTHONPATH() {
99 if [[ -n "${SUPPORT_PYTHON_ABIS}" && -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
100 ls -d build-${PYTHON_ABI}/lib* 2> /dev/null
101 else
102 ls -d build/lib* 2> /dev/null
103 fi
104}
105
106_distutils_hook() {
107 if [[ "$#" -ne 1 ]]; then
108 die "${FUNCNAME}() requires 1 argument"
109 fi
110 if [[ "$(type -t "distutils_src_${EBUILD_PHASE}_$1_hook")" == "function" ]]; then
111 "distutils_src_${EBUILD_PHASE}_$1_hook"
112 fi
113}
114
115# @FUNCTION: distutils_src_unpack
116# @DESCRIPTION:
117# The distutils src_unpack function. This function is exported.
118distutils_src_unpack() {
119 if [[ "${EBUILD_PHASE}" != "unpack" ]]; then
120 die "${FUNCNAME}() can be used only in src_unpack() phase"
121 fi
122
123 unpack ${A}
124 cd "${S}"
125
126 has "${EAPI:-0}" 0 1 && distutils_src_prepare
127}
128
129# @FUNCTION: distutils_src_prepare
130# @DESCRIPTION:
131# The distutils src_prepare function. This function is exported.
132distutils_src_prepare() {
133 if ! has "${EAPI:-0}" 0 1 && [[ "${EBUILD_PHASE}" != "prepare" ]]; then
134 die "${FUNCNAME}() can be used only in src_prepare() phase"
135 fi
136
137 # Delete ez_setup files to prevent packages from installing Setuptools on their own.
138 local ez_setup_existence="0"
139 [[ -d ez_setup || -f ez_setup.py ]] && ez_setup_existence="1"
140 rm -fr ez_setup*
141 if [[ "${ez_setup_existence}" == "1" ]]; then
142 echo "def use_setuptools(*args, **kwargs): pass" > ez_setup.py
143 fi
144
145 # Delete distribute_setup files to prevent packages from installing Distribute on their own.
146 local distribute_setup_existence="0"
147 [[ -d distribute_setup || -f distribute_setup.py ]] && distribute_setup_existence="1"
148 rm -fr distribute_setup*
149 if [[ "${distribute_setup_existence}" == "1" ]]; then
150 echo "def use_setuptools(*args, **kwargs): pass" > distribute_setup.py
151 fi
152
153 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
154 python_copy_sources
155 fi
156}
157
158# @FUNCTION: distutils_src_compile
159# @DESCRIPTION:
160# The distutils src_compile function. This function is exported.
161# In ebuilds of packages supporting installation for multiple versions of Python, this function
162# calls distutils_src_compile_pre_hook() and distutils_src_compile_post_hook(), if they are defined.
37distutils_src_compile() { 163distutils_src_compile() {
38 ${python} setup.py build "$@" || die "compilation failed" 164 if [[ "${EBUILD_PHASE}" != "compile" ]]; then
39} 165 die "${FUNCNAME}() can be used only in src_compile() phase"
166 fi
40 167
168 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
169 distutils_building() {
170 _distutils_hook pre
171
172 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "$(_distutils_get_build_dir)" "$@"
173 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "$(_distutils_get_build_dir)" "$@" || return "$?"
174
175 _distutils_hook post
176 }
177 python_execute_function ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} distutils_building "$@"
178 else
179 echo "$(PYTHON -A)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@"
180 "$(PYTHON -A)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || die "Building failed"
181 fi
182}
183
184# @FUNCTION: distutils_src_test
185# @DESCRIPTION:
186# The distutils src_test function. This function is exported, when DISTUTILS_SRC_TEST variable is set.
187distutils_src_test() {
188 if [[ "${DISTUTILS_SRC_TEST}" == "setup.py" ]]; then
189 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
190 distutils_testing() {
191 echo PYTHONPATH="$(_distutils_get_PYTHONPATH)" "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" $([[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]] && echo build -b "$(_distutils_get_build_dir)") test "$@"
192 PYTHONPATH="$(_distutils_get_PYTHONPATH)" "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" $([[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]] && echo build -b "$(_distutils_get_build_dir)") test "$@"
193 }
194 python_execute_function ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} distutils_testing "$@"
195 else
196 echo PYTHONPATH="$(_distutils_get_PYTHONPATH)" "$(PYTHON -A)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" test "$@" || die "Testing failed"
197 PYTHONPATH="$(_distutils_get_PYTHONPATH)" "$(PYTHON -A)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" test "$@" || die "Testing failed"
198 fi
199 elif [[ "${DISTUTILS_SRC_TEST}" == "nosetests" ]]; then
200 python_execute_nosetests -P '$(_distutils_get_PYTHONPATH)' ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} -- "$@"
201 elif [[ "${DISTUTILS_SRC_TEST}" == "py.test" ]]; then
202 python_execute_py.test -P '$(_distutils_get_PYTHONPATH)' ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} -- "$@"
203 # trial requires an argument, which is usually equal to "${PN}".
204 elif [[ "${DISTUTILS_SRC_TEST}" =~ ^trial(\ .*)?$ ]]; then
205 local trial_arguments
206 if [[ "${DISTUTILS_SRC_TEST}" == "trial "* ]]; then
207 trial_arguments="${DISTUTILS_SRC_TEST#trial }"
208 else
209 trial_arguments="${PN}"
210 fi
211
212 python_execute_trial -P '$(_distutils_get_PYTHONPATH)' ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} -- ${trial_arguments} "$@"
213 else
214 die "'DISTUTILS_SRC_TEST' variable has unsupported value '${DISTUTILS_SRC_TEST}'"
215 fi
216}
217
218# @FUNCTION: distutils_src_install
219# @DESCRIPTION:
220# The distutils src_install function. This function is exported.
221# In ebuilds of packages supporting installation for multiple versions of Python, this function
222# calls distutils_src_install_pre_hook() and distutils_src_install_post_hook(), if they are defined.
223# It also installs some standard documentation files (AUTHORS, Change*, CHANGELOG, CONTRIBUTORS,
224# KNOWN_BUGS, MAINTAINERS, MANIFEST*, NEWS, PKG-INFO, README*, TODO).
41distutils_src_install() { 225distutils_src_install() {
42 if has_version ">=dev-lang/python-2.3"; then 226 if [[ "${EBUILD_PHASE}" != "install" ]]; then
43 ${python} setup.py install --root=${D} --no-compile "$@" || die 227 die "${FUNCNAME}() can be used only in src_install() phase"
44 else 228 fi
45 ${python} setup.py install --root=${D} "$@" || die 229
230 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
231 if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${BASH_VERSINFO[0]}" -ge 4 ]]; then
232 declare -A wrapper_scripts=()
233
234 rename_scripts_with_versioned_shebangs() {
235 if [[ -d "${D}usr/bin" ]]; then
236 cd "${D}usr/bin"
237
238 local file
239 for file in *; do
240 if [[ -f "${file}" && ! "${file}" =~ [[:digit:]]+\.[[:digit:]]+$ && "$(head -n1 "${file}")" =~ ^'#!'.*python[[:digit:]]+\.[[:digit:]]+ ]]; then
241 mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed"
242 wrapper_scripts+=(["${D}usr/bin/${file}"]=)
243 fi
244 done
245 fi
246 }
46 fi 247 fi
47 248
48 DDOCS="CHANGELOG COPYRIGHT KNOWN_BUGS MAINTAINERS PKG-INFO" 249 distutils_installation() {
49 DDOCS="${DDOCS} CONTRIBUTORS TODO" 250 _distutils_hook pre
50 DDOCS="${DDOCS} Change* MANIFEST* README*"
51 251
52 for doc in ${DDOCS}; do 252 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" $([[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]] && echo build -b "$(_distutils_get_build_dir)") install --root="${D}" --no-compile "$@"
253 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" $([[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]] && echo build -b "$(_distutils_get_build_dir)") install --root="${D}" --no-compile "$@" || return "$?"
254
255 if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${BASH_VERSINFO[0]}" -ge 4 ]]; then
256 rename_scripts_with_versioned_shebangs
257 fi
258
259 _distutils_hook post
260 }
261 python_execute_function ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} distutils_installation "$@"
262
263 if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${#wrapper_scripts[@]}" -ne 0 && "${BASH_VERSINFO[0]}" -ge 4 ]]; then
264 python_generate_wrapper_scripts "${!wrapper_scripts[@]}"
265 fi
266 unset wrapper_scripts
267 else
268 # Mark the package to be rebuilt after a Python upgrade.
269 python_need_rebuild
270
271 echo "$(PYTHON -A)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@"
272 "$(PYTHON -A)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || die "Installation failed"
273 fi
274
275 if [[ -e "${D}usr/local" ]]; then
276 die "Illegal installation into /usr/local"
277 fi
278
279 local default_docs
280 default_docs="AUTHORS Change* CHANGELOG CONTRIBUTORS KNOWN_BUGS MAINTAINERS MANIFEST* NEWS PKG-INFO README* TODO"
281
282 local doc
283 for doc in ${default_docs}; do
53 [ -s "$doc" ] && dodoc $doc 284 [[ -s "${doc}" ]] && dodoc "${doc}"
54 done 285 done
55 286
56 [ -n "${DOCS}" ] && dodoc ${DOCS} 287 if [[ -n "${DOCS}" ]]; then
57 288 dodoc ${DOCS} || die "dodoc failed"
58 # deprecated! please use DOCS instead. 289 fi
59 [ -n "${mydoc}" ] && dodoc ${mydoc}
60} 290}
61 291
62# generic pyc/pyo cleanup script. 292# @FUNCTION: distutils_pkg_postinst
293# @DESCRIPTION:
294# The distutils pkg_postinst function. This function is exported.
295# When PYTHON_MODNAME variable is set, then this function calls python_mod_optimize() with modules
296# specified in PYTHON_MODNAME variable. Otherwise it calls python_mod_optimize() with module, whose
297# name is equal to name of current package, if this module exists.
298distutils_pkg_postinst() {
299 if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
300 die "${FUNCNAME}() can be used only in pkg_postinst() phase"
301 fi
63 302
303 local pylibdir pymod
304 if [[ -z "${PYTHON_MODNAME}" ]]; then
305 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
306 if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
307 PYTHON_MODNAME="${PN}"
308 fi
309 done
310 fi
311
312 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
313 python_mod_optimize ${PYTHON_MODNAME}
314 else
315 for pymod in ${PYTHON_MODNAME}; do
316 python_mod_optimize "$(python_get_sitedir)/${pymod}"
317 done
318 fi
319}
320
321# @FUNCTION: distutils_pkg_postrm
322# @DESCRIPTION:
323# The distutils pkg_postrm function. This function is exported.
324# When PYTHON_MODNAME variable is set, then this function calls python_mod_cleanup() with modules
325# specified in PYTHON_MODNAME variable. Otherwise it calls python_mod_cleanup() with module, whose
326# name is equal to name of current package, if this module exists.
64distutils_pkg_postrm() { 327distutils_pkg_postrm() {
65 PYTHON_MODNAME=${PYTHON_MODNAME:-${PN}} 328 if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
329 die "${FUNCNAME}() can be used only in pkg_postrm() phase"
330 fi
66 331
67 if has_version ">=dev-lang/python-2.3"; then 332 local pylibdir pymod
68 ebegin "Performing Python Module Cleanup .." 333 if [[ -z "${PYTHON_MODNAME}" ]]; then
334 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
335 if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
336 PYTHON_MODNAME="${PN}"
337 fi
338 done
339 fi
340
69 if [ -n "${PYTHON_MODNAME}" ]; then 341 if [[ -n "${PYTHON_MODNAME}" ]]; then
342 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
343 python_mod_cleanup ${PYTHON_MODNAME}
344 else
70 for pymod in ${PYTHON_MODNAME}; do 345 for pymod in ${PYTHON_MODNAME}; do
71 for moddir in "`ls -d --color=none -1 ${ROOT}usr/$(get_libdir)/python*/site-packages/${pymod} 2> /dev/null`"; do 346 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
72 python_mod_cleanup ${moddir} 347 if [[ -d "${pylibdir}/site-packages/${pymod}" ]]; then
348 python_mod_cleanup "${pylibdir#${ROOT}}/site-packages/${pymod}"
349 fi
73 done 350 done
74 done 351 done
352 fi
75 else 353 else
76 python_mod_cleanup 354 python_mod_cleanup
77 fi 355 fi
78 eend 0
79 fi
80} 356}
81 357
82# this is a generic optimization, you should override it if your package 358# @FUNCTION: distutils_python_version
83# installs things in another directory 359# @DESCRIPTION:
84 360# Deprecated wrapper function for deprecated python_version().
85distutils_pkg_postinst() {
86 PYTHON_MODNAME=${PYTHON_MODNAME:-${PN}}
87
88 if has_version ">=dev-lang/python-2.3"; then
89 python_version
90 for pymod in ${PYTHON_MODNAME}; do
91 if [ -d "${ROOT}usr/$(get_libdir)/python${PYVER}/site-packages/${pymod}" ]; then
92 python_mod_optimize ${ROOT}usr/$(get_libdir)/python${PYVER}/site-packages/${pymod}
93 fi
94 done
95 fi
96}
97
98# e.g. insinto ${ROOT}/usr/include/python${PYVER}
99
100distutils_python_version() { 361distutils_python_version() {
101 local tmpstr="$(${python} -V 2>&1 )" 362 if ! has "${EAPI:-0}" 0 1 2; then
102 export PYVER_ALL="${tmpstr#Python }" 363 eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()."
364 die "${FUNCNAME}() cannot be used in this EAPI"
365 fi
103 366
104 export PYVER_MAJOR=$(echo ${PYVER_ALL} | cut -d. -f1) 367 python_version
105 export PYVER_MINOR=$(echo ${PYVER_ALL} | cut -d. -f2)
106 export PYVER_MICRO=$(echo ${PYVER_ALL} | cut -d. -f3-)
107 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}"
108} 368}
109 369
110# checks for if tkinter support is compiled into python 370# @FUNCTION: distutils_python_tkinter
371# @DESCRIPTION:
372# Deprecated wrapper function for python_tkinter_exists().
111distutils_python_tkinter() { 373distutils_python_tkinter() {
112 if ! python -c "import Tkinter" >/dev/null 2>&1; then 374 if ! has "${EAPI:-0}" 0 1 2; then
113 eerror "You need to recompile python with Tkinter support." 375 eerror "Use python_tkinter_exists() instead of ${FUNCNAME}()."
114 eerror "Try adding 'dev-lang/python X tk' to:" 376 die "${FUNCNAME}() cannot be used in this EAPI"
115 eerror "/etc/portage/package.use"
116 echo
117 die "missing tkinter support with installed python"
118 fi 377 fi
119}
120 378
121EXPORT_FUNCTIONS src_compile src_install pkg_postinst pkg_postrm 379 python_tkinter_exists
380}

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.72

  ViewVC Help
Powered by ViewVC 1.1.20