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

Diff of /eclass/distutils.eclass

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

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

Legend:
Removed from v.1.70  
changed lines
  Added in v.1.85

  ViewVC Help
Powered by ViewVC 1.1.20