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

Diff of /eclass/distutils.eclass

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

Revision 1.67 Revision 1.82
1# Copyright 1999-2009 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/distutils.eclass,v 1.67 2009/11/28 18:39:27 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/distutils.eclass,v 1.82 2012/03/15 16:51:54 patrick Exp $
4 4
5# @ECLASS: distutils.eclass 5# @ECLASS: distutils.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# <python@gentoo.org> 7# Gentoo Python Project <python@gentoo.org>
8# 8# @BLURB: Eclass for packages with build systems using Distutils
9# Original author: Jon Nelson <jnelson@gentoo.org>
10# @BLURB: This eclass allows easier installation of distutils-based python modules
11# @DESCRIPTION: 9# @DESCRIPTION:
12# The distutils eclass is designed to allow easier installation of 10# The distutils eclass defines phase functions for packages with build systems using Distutils.
13# distutils-based python modules and their incorporation into
14# the Gentoo Linux system.
15 11
16inherit eutils multilib python 12if [[ -z "${_PYTHON_ECLASS_INHERITED}" ]]; then
13 inherit python
14fi
15
16inherit multilib
17 17
18case "${EAPI:-0}" in 18case "${EAPI:-0}" in
19 0|1) 19 0|1)
20 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
21 ;; 21 ;;
22 *) 22 *)
23 EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install pkg_postinst pkg_postrm 23 EXPORT_FUNCTIONS src_prepare src_compile src_install pkg_postinst pkg_postrm
24 ;; 24 ;;
25esac 25esac
26 26
27if [[ -z "${DISTUTILS_DISABLE_PYTHON_DEPENDENCY}" ]]; then 27if [[ -z "$(declare -p PYTHON_DEPEND 2> /dev/null)" ]]; then
28 DEPEND="virtual/python" 28 DEPEND="dev-lang/python"
29 RDEPEND="${DEPEND}" 29 RDEPEND="${DEPEND}"
30fi 30fi
31
32 if has "${EAPI:-0}" 0 1 && [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
33 ewarn
34 ewarn "\"${EBUILD}\":"
35 ewarn "Deprecation Warning: Usage of distutils.eclass in packages supporting installation"
36 ewarn "for multiple Python ABIs in EAPI <=1 is deprecated and will be banned on 2011-06-01."
37 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
38 ewarn
39 elif has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
40 ewarn
41 ewarn "\"${EBUILD}\":"
42 ewarn "Deprecation Warning: Usage of distutils.eclass in packages not supporting installation"
43 ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be banned on 2011-06-01."
44 ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported."
45 ewarn
46 fi
47
48# 'python' variable is deprecated. Use PYTHON() instead.
49if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
31python="python" 50 python="python"
51else
52 python="die"
53fi
32 54
33# @ECLASS-VARIABLE: DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES 55# @ECLASS-VARIABLE: DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES
34# @DESCRIPTION: 56# @DESCRIPTION:
35# Set this to use separate source directories for each enabled version of Python. 57# Set this to use separate source directories for each enabled version of Python.
36 58
59# @ECLASS-VARIABLE: DISTUTILS_SETUP_FILES
60# @DESCRIPTION:
61# Array of paths to setup files.
62# Syntax:
63# [current_working_directory|]path_to_setup_file
64
37# @ECLASS-VARIABLE: DISTUTILS_GLOBAL_OPTIONS 65# @ECLASS-VARIABLE: DISTUTILS_GLOBAL_OPTIONS
38# @DESCRIPTION: 66# @DESCRIPTION:
39# Global options passed to setup.py. 67# Array of global options passed to setup files.
68# Syntax in EAPI <4:
69# global_option
70# Syntax in EAPI >=4:
71# Python_ABI_pattern global_option
72
73# @ECLASS-VARIABLE: DISTUTILS_SRC_TEST
74# @DESCRIPTION:
75# Type of test command used by distutils_src_test().
76# IUSE and DEPEND are automatically adjusted, unless DISTUTILS_DISABLE_TEST_DEPENDENCY is set.
77# Valid values:
78# setup.py
79# nosetests
80# py.test
81# trial [arguments]
82
83# @ECLASS-VARIABLE: DISTUTILS_DISABLE_TEST_DEPENDENCY
84# @DESCRIPTION:
85# Disable modification of IUSE and DEPEND caused by setting of DISTUTILS_SRC_TEST.
86
87if [[ -n "${DISTUTILS_SRC_TEST}" && ! "${DISTUTILS_SRC_TEST}" =~ ^(setup\.py|nosetests|py\.test|trial(\ .*)?)$ ]]; then
88 die "'DISTUTILS_SRC_TEST' variable has unsupported value '${DISTUTILS_SRC_TEST}'"
89fi
90
91if [[ -z "${DISTUTILS_DISABLE_TEST_DEPENDENCY}" ]]; then
92 if [[ "${DISTUTILS_SRC_TEST}" == "nosetests" ]]; then
93 IUSE="test"
94 DEPEND+="${DEPEND:+ }test? ( dev-python/nose )"
95 elif [[ "${DISTUTILS_SRC_TEST}" == "py.test" ]]; then
96 IUSE="test"
97 DEPEND+="${DEPEND:+ }test? ( dev-python/pytest )"
98 # trial requires an argument, which is usually equal to "${PN}".
99 elif [[ "${DISTUTILS_SRC_TEST}" =~ ^trial(\ .*)?$ ]]; then
100 IUSE="test"
101 DEPEND+="${DEPEND:+ }test? ( dev-python/twisted )"
102 fi
103fi
104
105if [[ -n "${DISTUTILS_SRC_TEST}" ]]; then
106 EXPORT_FUNCTIONS src_test
107fi
108
109# Scheduled for deletion on 2011-06-01.
110if [[ -n "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" ]]; then
111 eerror "Use PYTHON_NONVERSIONED_EXECUTABLES=(\".*\") instead of DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS variable."
112 die "DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS variable is banned"
113fi
40 114
41# @ECLASS-VARIABLE: DOCS 115# @ECLASS-VARIABLE: DOCS
42# @DESCRIPTION: 116# @DESCRIPTION:
43# Additional DOCS 117# Additional documentation files installed by distutils_src_install().
118
119_distutils_get_build_dir() {
120 if _python_package_supporting_installation_for_multiple_python_abis && [[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
121 echo "build-${PYTHON_ABI}"
122 else
123 echo "build"
124 fi
125}
126
127_distutils_get_PYTHONPATH() {
128 if _python_package_supporting_installation_for_multiple_python_abis && [[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
129 ls -d build-${PYTHON_ABI}/lib* 2> /dev/null
130 else
131 ls -d build/lib* 2> /dev/null
132 fi
133}
44 134
45_distutils_hook() { 135_distutils_hook() {
46 if [[ "$#" -ne 1 ]]; then 136 if [[ "$#" -ne 1 ]]; then
47 die "${FUNCNAME}() requires 1 argument" 137 die "${FUNCNAME}() requires 1 argument"
48 fi 138 fi
49 if [[ "$(type -t "distutils_src_${EBUILD_PHASE}_$1_hook")" == "function" ]]; then 139 if [[ "$(type -t "distutils_src_${EBUILD_PHASE}_$1_hook")" == "function" ]]; then
50 "distutils_src_${EBUILD_PHASE}_$1_hook" 140 "distutils_src_${EBUILD_PHASE}_$1_hook"
51 fi 141 fi
52} 142}
53 143
144_distutils_prepare_global_options() {
145 local element option pattern
146
147 if [[ -n "$(declare -p DISTUTILS_GLOBAL_OPTIONS 2> /dev/null)" && "$(declare -p DISTUTILS_GLOBAL_OPTIONS)" != "declare -a DISTUTILS_GLOBAL_OPTIONS="* ]]; then
148 die "DISTUTILS_GLOBAL_OPTIONS should be indexed array"
149 fi
150
151 if has "${EAPI:-0}" 0 1 2 3; then
152 _DISTUTILS_GLOBAL_OPTIONS=("${DISTUTILS_GLOBAL_OPTIONS[@]}")
153 else
154 _DISTUTILS_GLOBAL_OPTIONS=()
155
156 for element in "${DISTUTILS_GLOBAL_OPTIONS[@]}"; do
157 if [[ ! "${element}" =~ ^[^[:space:]]+\ . ]]; then
158 die "Element '${element}' of DISTUTILS_GLOBAL_OPTIONS array has invalid syntax"
159 fi
160 pattern="${element%% *}"
161 option="${element#* }"
162 if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
163 _DISTUTILS_GLOBAL_OPTIONS+=("${option}")
164 fi
165 done
166 fi
167}
168
169_distutils_prepare_current_working_directory() {
170 if [[ "$1" == *"|"*"|"* ]]; then
171 die "Element '$1' of DISTUTILS_SETUP_FILES array has invalid syntax"
172 fi
173
174 if [[ "$1" == *"|"* ]]; then
175 echo "${_BOLD}[${1%|*}]${_NORMAL}"
176 pushd "${1%|*}" > /dev/null || die "Entering directory '${1%|*}' failed"
177 fi
178}
179
180_distutils_restore_current_working_directory() {
181 if [[ "$1" == *"|"* ]]; then
182 popd > /dev/null || die "Leaving directory '${1%|*}' failed"
183 fi
184}
185
54# @FUNCTION: distutils_src_unpack 186# @FUNCTION: distutils_src_unpack
55# @DESCRIPTION: 187# @DESCRIPTION:
56# The distutils src_unpack function, this function is exported. 188# The distutils src_unpack function. This function is exported.
57distutils_src_unpack() { 189distutils_src_unpack() {
190 if ! has "${EAPI:-0}" 0 1; then
191 die "${FUNCNAME}() cannot be used in this EAPI"
192 fi
193
58 if [[ "${EBUILD_PHASE}" != "unpack" ]]; then 194 if [[ "${EBUILD_PHASE}" != "unpack" ]]; then
59 die "${FUNCNAME}() can be used only in src_unpack() phase" 195 die "${FUNCNAME}() can be used only in src_unpack() phase"
60 fi 196 fi
61 197
62 unpack ${A} 198 unpack ${A}
63 cd "${S}" 199 cd "${S}"
64 200
65 has "${EAPI:-0}" 0 1 && distutils_src_prepare 201 distutils_src_prepare
66} 202}
67 203
68# @FUNCTION: distutils_src_prepare 204# @FUNCTION: distutils_src_prepare
69# @DESCRIPTION: 205# @DESCRIPTION:
70# The distutils src_prepare function, this function is exported. 206# The distutils src_prepare function. This function is exported.
71distutils_src_prepare() { 207distutils_src_prepare() {
72 if ! has "${EAPI:-0}" 0 1 && [[ "${EBUILD_PHASE}" != "prepare" ]]; then 208 if ! has "${EAPI:-0}" 0 1 && [[ "${EBUILD_PHASE}" != "prepare" ]]; then
73 die "${FUNCNAME}() can be used only in src_prepare() phase" 209 die "${FUNCNAME}() can be used only in src_prepare() phase"
74 fi 210 fi
75 211
212 _python_check_python_pkg_setup_execution
213
214 local distribute_setup_existence="0" ez_setup_existence="0"
215
216 if [[ "$#" -ne 0 ]]; then
217 die "${FUNCNAME}() does not accept arguments"
218 fi
219
76 # Delete ez_setup files to prevent packages from installing 220 # Delete ez_setup files to prevent packages from installing Setuptools on their own.
77 # Setuptools on their own.
78 local ez_setup_existence="0"
79 [[ -d ez_setup || -f ez_setup.py ]] && ez_setup_existence="1" 221 [[ -d ez_setup || -f ez_setup.py ]] && ez_setup_existence="1"
80 rm -fr ez_setup* 222 rm -fr ez_setup*
81 if [[ "${ez_setup_existence}" == "1" ]]; then 223 if [[ "${ez_setup_existence}" == "1" ]]; then
82 echo "def use_setuptools(*args, **kwargs): pass" > ez_setup.py 224 echo "def use_setuptools(*args, **kwargs): pass" > ez_setup.py
83 fi 225 fi
84 226
85 # Delete distribute_setup files to prevent packages from installing 227 # Delete distribute_setup files to prevent packages from installing Distribute on their own.
86 # Distribute on their own.
87 local distribute_setup_existence="0"
88 [[ -d distribute_setup || -f distribute_setup.py ]] && distribute_setup_existence="1" 228 [[ -d distribute_setup || -f distribute_setup.py ]] && distribute_setup_existence="1"
89 rm -fr distribute_setup* 229 rm -fr distribute_setup*
90 if [[ "${distribute_setup_existence}" == "1" ]]; then 230 if [[ "${distribute_setup_existence}" == "1" ]]; then
91 echo "def use_setuptools(*args, **kwargs): pass" > distribute_setup.py 231 echo "def use_setuptools(*args, **kwargs): pass" > distribute_setup.py
92 fi 232 fi
96 fi 236 fi
97} 237}
98 238
99# @FUNCTION: distutils_src_compile 239# @FUNCTION: distutils_src_compile
100# @DESCRIPTION: 240# @DESCRIPTION:
101# The distutils src_compile function, this function is exported. 241# The distutils src_compile function. This function is exported.
102# In newer EAPIs this function calls distutils_src_compile_pre_hook() and 242# In ebuilds of packages supporting installation for multiple versions of Python, this function
103# distutils_src_compile_post_hook(), if they are defined. 243# calls distutils_src_compile_pre_hook() and distutils_src_compile_post_hook(), if they are defined.
104distutils_src_compile() { 244distutils_src_compile() {
105 if [[ "${EBUILD_PHASE}" != "compile" ]]; then 245 if [[ "${EBUILD_PHASE}" != "compile" ]]; then
106 die "${FUNCNAME}() can be used only in src_compile() phase" 246 die "${FUNCNAME}() can be used only in src_compile() phase"
107 fi 247 fi
108 248
109 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 249 _python_check_python_pkg_setup_execution
110 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then 250 _python_set_color_variables
111 building() { 251
252 local setup_file
253
254 if _python_package_supporting_installation_for_multiple_python_abis; then
255 distutils_building() {
256 _distutils_hook pre
257
258 _distutils_prepare_global_options
259
260 for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
261 _distutils_prepare_current_working_directory "${setup_file}"
262
263 echo ${_BOLD}"$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "$(_distutils_get_build_dir)" "$@"${_NORMAL}
264 "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "$(_distutils_get_build_dir)" "$@" || return "$?"
265
266 _distutils_restore_current_working_directory "${setup_file}"
267 done
268
269 _distutils_hook post
270 }
271 python_execute_function ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} distutils_building "$@"
272 unset -f distutils_building
273 else
274 _distutils_prepare_global_options
275
276 for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
277 _distutils_prepare_current_working_directory "${setup_file}"
278
279 echo ${_BOLD}"$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@"${_NORMAL}
280 "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || die "Building failed"
281
282 _distutils_restore_current_working_directory "${setup_file}"
283 done
284 fi
285}
286
287_distutils_src_test_hook() {
288 if [[ "$#" -ne 1 ]]; then
289 die "${FUNCNAME}() requires 1 arguments"
290 fi
291
292 if ! _python_package_supporting_installation_for_multiple_python_abis; then
293 return
294 fi
295
296 if [[ "$(type -t "distutils_src_test_pre_hook")" == "function" ]]; then
297 eval "python_execute_$1_pre_hook() {
298 distutils_src_test_pre_hook
299 }"
300 fi
301
302 if [[ "$(type -t "distutils_src_test_post_hook")" == "function" ]]; then
303 eval "python_execute_$1_post_hook() {
304 distutils_src_test_post_hook
305 }"
306 fi
307}
308
309# @FUNCTION: distutils_src_test
310# @DESCRIPTION:
311# The distutils src_test function. This function is exported, when DISTUTILS_SRC_TEST variable is set.
312# In ebuilds of packages supporting installation for multiple versions of Python, this function
313# calls distutils_src_test_pre_hook() and distutils_src_test_post_hook(), if they are defined.
314distutils_src_test() {
315 if [[ "${EBUILD_PHASE}" != "test" ]]; then
316 die "${FUNCNAME}() can be used only in src_test() phase"
317 fi
318
319 _python_check_python_pkg_setup_execution
320 _python_set_color_variables
321
322 local arguments setup_file
323
324 if [[ "${DISTUTILS_SRC_TEST}" == "setup.py" ]]; then
325 if _python_package_supporting_installation_for_multiple_python_abis; then
326 distutils_testing() {
112 _distutils_hook pre 327 _distutils_hook pre
113 328
114 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" 329 _distutils_prepare_global_options
115 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || return "$?" 330
331 for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
332 _distutils_prepare_current_working_directory "${setup_file}"
333
334 echo ${_BOLD}PYTHONPATH="$(_distutils_get_PYTHONPATH)" "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" $([[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]] && echo build -b "$(_distutils_get_build_dir)") test "$@"${_NORMAL}
335 PYTHONPATH="$(_distutils_get_PYTHONPATH)" "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" $([[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]] && echo build -b "$(_distutils_get_build_dir)") test "$@" || return "$?"
336
337 _distutils_restore_current_working_directory "${setup_file}"
338 done
116 339
117 _distutils_hook post 340 _distutils_hook post
118 } 341 }
119 python_execute_function -s building "$@" 342 python_execute_function ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} distutils_testing "$@"
343 unset -f distutils_testing
120 else 344 else
121 building() { 345 _distutils_prepare_global_options
122 _distutils_hook pre
123 346
124 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" "$@" 347 for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
125 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" "$@" || return "$?" 348 _distutils_prepare_current_working_directory "${setup_file}"
126 349
127 _distutils_hook post 350 echo ${_BOLD}PYTHONPATH="$(_distutils_get_PYTHONPATH)" "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" test "$@"${_NORMAL}
128 } 351 PYTHONPATH="$(_distutils_get_PYTHONPATH)" "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" test "$@" || die "Testing failed"
129 python_execute_function building "$@" 352
353 _distutils_restore_current_working_directory "${setup_file}"
354 done
130 fi 355 fi
356 elif [[ "${DISTUTILS_SRC_TEST}" == "nosetests" ]]; then
357 _distutils_src_test_hook nosetests
358
359 python_execute_nosetests -P '$(_distutils_get_PYTHONPATH)' ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} -- "$@"
360 elif [[ "${DISTUTILS_SRC_TEST}" == "py.test" ]]; then
361 _distutils_src_test_hook py.test
362
363 python_execute_py.test -P '$(_distutils_get_PYTHONPATH)' ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} -- "$@"
364 # trial requires an argument, which is usually equal to "${PN}".
365 elif [[ "${DISTUTILS_SRC_TEST}" =~ ^trial(\ .*)?$ ]]; then
366 if [[ "${DISTUTILS_SRC_TEST}" == "trial "* ]]; then
367 arguments="${DISTUTILS_SRC_TEST#trial }"
131 else 368 else
132 python_version 369 arguments="${PN}"
133 echo "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" 370 fi
134 "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || die "Building failed" 371
372 _distutils_src_test_hook trial
373
374 python_execute_trial -P '$(_distutils_get_PYTHONPATH)' ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} -- ${arguments} "$@"
375 else
376 die "'DISTUTILS_SRC_TEST' variable has unsupported value '${DISTUTILS_SRC_TEST}'"
135 fi 377 fi
136} 378}
137 379
138# @FUNCTION: distutils_src_install 380# @FUNCTION: distutils_src_install
139# @DESCRIPTION: 381# @DESCRIPTION:
140# The distutils src_install function, this function is exported. 382# The distutils src_install function. This function is exported.
141# In newer EAPIs this function calls distutils_src_install_pre_hook() and 383# In ebuilds of packages supporting installation for multiple versions of Python, this function
142# distutils_src_install_post_hook(), if they are defined. 384# calls distutils_src_install_pre_hook() and distutils_src_install_post_hook(), if they are defined.
143# It also installs the "standard docs" (CHANGELOG, Change*, KNOWN_BUGS, MAINTAINERS, 385# It also installs some standard documentation files (AUTHORS, Change*, CHANGELOG, CONTRIBUTORS,
144# PKG-INFO, CONTRIBUTORS, TODO, NEWS, MANIFEST*, README*, and AUTHORS) 386# KNOWN_BUGS, MAINTAINERS, NEWS, README*, TODO).
145distutils_src_install() { 387distutils_src_install() {
146 if [[ "${EBUILD_PHASE}" != "install" ]]; then 388 if [[ "${EBUILD_PHASE}" != "install" ]]; then
147 die "${FUNCNAME}() can be used only in src_install() phase" 389 die "${FUNCNAME}() can be used only in src_install() phase"
148 fi 390 fi
149 391
150 local pylibdir 392 _python_check_python_pkg_setup_execution
393 _python_initialize_prefix_variables
394 _python_set_color_variables
151 395
152 # Mark the package to be rebuilt after a python upgrade. 396 local default_docs doc line nspkg_pth_file nspkg_pth_files=() setup_file
153 python_need_rebuild
154 397
155 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 398 if _python_package_supporting_installation_for_multiple_python_abis; then
156 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
157 installation() { 399 distutils_installation() {
158 _distutils_hook pre 400 _distutils_hook pre
159 401
160 # need this for python-2.5 + setuptools in cases where 402 _distutils_prepare_global_options
161 # a package uses distutils but does not install anything
162 # in site-packages. (eg. dev-java/java-config-2.x)
163 # - liquidx (14/08/2006)
164 pylibdir="$("$(PYTHON)" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
165 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
166 403
167 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" 404 for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
168 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || return "$?" 405 _distutils_prepare_current_working_directory "${setup_file}"
169 406
407 echo ${_BOLD}"$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" $([[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]] && echo build -b "$(_distutils_get_build_dir)") install --no-compile --root="${T}/images/${PYTHON_ABI}" "$@"${_NORMAL}
408 "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" $([[ -z "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]] && echo build -b "$(_distutils_get_build_dir)") install --no-compile --root="${T}/images/${PYTHON_ABI}" "$@" || return "$?"
409
410 _distutils_restore_current_working_directory "${setup_file}"
411 done
412
170 _distutils_hook post 413 _distutils_hook post
171 } 414 }
172 python_execute_function -s installation "$@" 415 python_execute_function ${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES:+-s} distutils_installation "$@"
416 unset -f distutils_installation
417
418 python_merge_intermediate_installation_images "${T}/images"
173 else 419 else
174 installation() { 420 # Mark the package to be rebuilt after a Python upgrade.
175 _distutils_hook pre 421 python_need_rebuild
176 422
177 # need this for python-2.5 + setuptools in cases where 423 _distutils_prepare_global_options
178 # a package uses distutils but does not install anything
179 # in site-packages. (eg. dev-java/java-config-2.x)
180 # - liquidx (14/08/2006)
181 pylibdir="$("$(PYTHON)" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
182 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
183 424
184 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@" 425 for setup_file in "${DISTUTILS_SETUP_FILES[@]-setup.py}"; do
185 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@" || return "$?" 426 _distutils_prepare_current_working_directory "${setup_file}"
186 427
187 _distutils_hook post
188 }
189 python_execute_function installation "$@"
190 fi
191 else
192 # need this for python-2.5 + setuptools in cases where
193 # a package uses distutils but does not install anything
194 # in site-packages. (eg. dev-java/java-config-2.x)
195 # - liquidx (14/08/2006)
196 pylibdir="$("$(PYTHON "${PYVER}")" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
197 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
198
199 echo "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" 428 echo ${_BOLD}"$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@"${_NORMAL}
200 "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || die "Installation failed" 429 "$(PYTHON)" "${setup_file#*|}" "${_DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || die "Installation failed"
201 fi
202 430
431 _distutils_restore_current_working_directory "${setup_file}"
432 done
433 fi
434
435 while read -d $'\0' -r nspkg_pth_file; do
436 nspkg_pth_files+=("${nspkg_pth_file}")
437 done < <(find "${ED}" -name "*-nspkg.pth" -type f -print0)
438
439 if [[ "${#nspkg_pth_files[@]}" -gt 0 ]]; then
440 einfo
441 einfo "Python namespaces:"
442 for nspkg_pth_file in "${nspkg_pth_files[@]}"; do
443 einfo " '${nspkg_pth_file#${ED%/}}':"
444 while read -r line; do
445 einfo " $(echo "${line}" | sed -e "s/.*types\.ModuleType('\([^']\+\)').*/\1/")"
446 done < "${nspkg_pth_file}"
447 #if ! has "${EAPI:-0}" 0 1 2 3; then
448 # rm -f "${nspkg_pth_file}" || die "Deletion of '${nspkg_pth_file}' failed"
449 #fi
450 done
451 einfo
452 fi
453
203 if [[ -e "${D}usr/local" ]]; then 454 if [[ -e "${ED}usr/local" ]]; then
204 die "Illegal installation into /usr/local" 455 die "Illegal installation into /usr/local"
205 fi 456 fi
206 457
207 local default_docs
208 default_docs="AUTHORS Change* CHANGELOG CONTRIBUTORS KNOWN_BUGS MAINTAINERS MANIFEST* NEWS PKG-INFO README* TODO" 458 default_docs="AUTHORS Change* CHANGELOG CONTRIBUTORS KNOWN_BUGS MAINTAINERS NEWS README* TODO"
209 459
210 local doc
211 for doc in ${default_docs}; do 460 for doc in ${default_docs}; do
212 [[ -s "${doc}" ]] && dodoc "${doc}" 461 [[ -s "${doc}" ]] && dodoc "${doc}"
213 done 462 done
214 463
464 if has "${EAPI:-0}" 0 1 2 3; then
215 if [[ -n "${DOCS}" ]]; then 465 if [[ -n "${DOCS}" ]]; then
216 dodoc ${DOCS} || die "dodoc failed" 466 dodoc ${DOCS} || die "dodoc failed"
217 fi 467 fi
468 else
469 if [[ -n "${DOCS}" ]]; then
470 dodoc -r ${DOCS} || die "dodoc failed"
471 fi
472 fi
473
474 DISTUTILS_SRC_INSTALL_EXECUTED="1"
218} 475}
219 476
220# @FUNCTION: distutils_pkg_postinst 477# @FUNCTION: distutils_pkg_postinst
221# @DESCRIPTION: 478# @DESCRIPTION:
222# This is a generic optimization, you should override it if your package 479# The distutils pkg_postinst function. This function is exported.
223# installs modules in another directory. This function is exported. 480# When PYTHON_MODNAME variable is set, then this function calls python_mod_optimize() with modules
481# specified in PYTHON_MODNAME variable. Otherwise it calls python_mod_optimize() with module, whose
482# name is equal to name of current package, if this module exists.
224distutils_pkg_postinst() { 483distutils_pkg_postinst() {
225 if [[ "${EBUILD_PHASE}" != "postinst" ]]; then 484 if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
226 die "${FUNCNAME}() can be used only in pkg_postinst() phase" 485 die "${FUNCNAME}() can be used only in pkg_postinst() phase"
227 fi 486 fi
228 487
488 _python_check_python_pkg_setup_execution
489 _python_initialize_prefix_variables
490
491 if [[ -z "${DISTUTILS_SRC_INSTALL_EXECUTED}" ]]; then
492 die "${FUNCNAME}() called illegally"
493 fi
494
229 local pylibdir pymod 495 local pylibdir pymod
230 if [[ -z "${PYTHON_MODNAME}" ]]; then 496
497 if [[ "$#" -ne 0 ]]; then
498 die "${FUNCNAME}() does not accept arguments"
499 fi
500
501 if [[ -z "$(declare -p PYTHON_MODNAME 2> /dev/null)" ]]; then
231 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do 502 for pylibdir in "${EROOT}"usr/$(get_libdir)/python* "${EROOT}"usr/share/jython-*/Lib; do
232 if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then 503 if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
233 PYTHON_MODNAME="${PN}" 504 PYTHON_MODNAME="${PN}"
234 fi 505 fi
235 done 506 done
236 fi 507 fi
237 508
238 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 509 if [[ -n "${PYTHON_MODNAME}" ]]; then
510 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
239 python_mod_optimize ${PYTHON_MODNAME} 511 python_mod_optimize ${PYTHON_MODNAME}
240 else 512 else
241 for pymod in ${PYTHON_MODNAME}; do 513 for pymod in ${PYTHON_MODNAME}; do
242 python_mod_optimize "$(python_get_sitedir)/${pymod}" 514 python_mod_optimize "$(python_get_sitedir)/${pymod}"
243 done 515 done
516 fi
244 fi 517 fi
245} 518}
246 519
247# @FUNCTION: distutils_pkg_postrm 520# @FUNCTION: distutils_pkg_postrm
248# @DESCRIPTION: 521# @DESCRIPTION:
249# Generic pyc/pyo cleanup script. This function is exported. 522# The distutils pkg_postrm function. This function is exported.
523# When PYTHON_MODNAME variable is set, then this function calls python_mod_cleanup() with modules
524# specified in PYTHON_MODNAME variable. Otherwise it calls python_mod_cleanup() with module, whose
525# name is equal to name of current package, if this module exists.
250distutils_pkg_postrm() { 526distutils_pkg_postrm() {
251 if [[ "${EBUILD_PHASE}" != "postrm" ]]; then 527 if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
252 die "${FUNCNAME}() can be used only in pkg_postrm() phase" 528 die "${FUNCNAME}() can be used only in pkg_postrm() phase"
253 fi 529 fi
254 530
531 _python_check_python_pkg_setup_execution
532 _python_initialize_prefix_variables
533
534 if [[ -z "${DISTUTILS_SRC_INSTALL_EXECUTED}" ]]; then
535 die "${FUNCNAME}() called illegally"
536 fi
537
255 local pylibdir pymod 538 local pylibdir pymod
256 if [[ -z "${PYTHON_MODNAME}" ]]; then 539
540 if [[ "$#" -ne 0 ]]; then
541 die "${FUNCNAME}() does not accept arguments"
542 fi
543
544 if [[ -z "$(declare -p PYTHON_MODNAME 2> /dev/null)" ]]; then
257 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do 545 for pylibdir in "${EROOT}"usr/$(get_libdir)/python* "${EROOT}"usr/share/jython-*/Lib; do
258 if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then 546 if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
259 PYTHON_MODNAME="${PN}" 547 PYTHON_MODNAME="${PN}"
260 fi 548 fi
261 done 549 done
262 fi 550 fi
263 551
264 if [[ -n "${PYTHON_MODNAME}" ]]; then 552 if [[ -n "${PYTHON_MODNAME}" ]]; then
265 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 553 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
266 python_mod_cleanup ${PYTHON_MODNAME} 554 python_mod_cleanup ${PYTHON_MODNAME}
267 else 555 else
268 for pymod in ${PYTHON_MODNAME}; do 556 for pymod in ${PYTHON_MODNAME}; do
269 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do 557 for pylibdir in "${EROOT}"usr/$(get_libdir)/python*; do
270 if [[ -d "${pylibdir}/site-packages/${pymod}" ]]; then 558 if [[ -d "${pylibdir}/site-packages/${pymod}" ]]; then
271 python_mod_cleanup "${pylibdir#${ROOT}}/site-packages/${pymod}" 559 python_mod_cleanup "${pylibdir#${EROOT%/}}/site-packages/${pymod}"
272 fi 560 fi
273 done 561 done
274 done 562 done
275 fi 563 fi
276 else
277 python_mod_cleanup
278 fi 564 fi
279} 565}
280 566
281# @FUNCTION: distutils_python_version 567# @FUNCTION: distutils_get_intermediate_installation_image
282# @DESCRIPTION: 568# @DESCRIPTION:
283# Calls python_version, so that you can use something like 569# Print path to intermediate installation image.
284# e.g. insinto ${ROOT}/usr/include/python${PYVER} 570#
285distutils_python_version() { 571# This function can be used only in distutils_src_install_pre_hook() and distutils_src_install_post_hook().
286 python_version 572distutils_get_intermediate_installation_image() {
287} 573 if [[ "${EBUILD_PHASE}" != "install" ]]; then
574 die "${FUNCNAME}() can be used only in src_install() phase"
575 fi
288 576
289# @FUNCTION: distutils_python_tkinter 577 if ! _python_package_supporting_installation_for_multiple_python_abis; then
290# @DESCRIPTION: 578 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
291# Checks for if tkinter support is compiled into python 579 fi
292distutils_python_tkinter() { 580
293 python_tkinter_exists 581 _python_check_python_pkg_setup_execution
582
583 if [[ ! "${FUNCNAME[1]}" =~ ^distutils_src_install_(pre|post)_hook$ ]]; then
584 die "${FUNCNAME}() can be used only in distutils_src_install_pre_hook() and distutils_src_install_post_hook()"
585 fi
586
587 if [[ "$#" -ne 0 ]]; then
588 die "${FUNCNAME}() does not accept arguments"
589 fi
590
591 echo "${T}/images/${PYTHON_ABI}"
294} 592}

Legend:
Removed from v.1.67  
changed lines
  Added in v.1.82

  ViewVC Help
Powered by ViewVC 1.1.20