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

Diff of /eclass/distutils.eclass

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

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

Legend:
Removed from v.1.69  
changed lines
  Added in v.1.80

  ViewVC Help
Powered by ViewVC 1.1.20