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

Diff of /eclass/distutils.eclass

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

Revision 1.64 Revision 1.69
1# Copyright 1999-2009 Gentoo Foundation 1# Copyright 1999-2009 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/distutils.eclass,v 1.64 2009/09/11 20:03:51 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/distutils.eclass,v 1.69 2010/01/10 17:24:32 arfrever Exp $
4 4
5# @ECLASS: distutils.eclass 5# @ECLASS: distutils.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# <python@gentoo.org> 7# <python@gentoo.org>
8# 8#
26 26
27if [[ -z "${DISTUTILS_DISABLE_PYTHON_DEPENDENCY}" ]]; then 27if [[ -z "${DISTUTILS_DISABLE_PYTHON_DEPENDENCY}" ]]; then
28 DEPEND="virtual/python" 28 DEPEND="virtual/python"
29 RDEPEND="${DEPEND}" 29 RDEPEND="${DEPEND}"
30fi 30fi
31
32if has "${EAPI:-0}" 0 1 2; then
31python="python" 33 python="python"
34else
35 python="die"
36fi
32 37
33# @ECLASS-VARIABLE: DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES 38# @ECLASS-VARIABLE: DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES
34# @DESCRIPTION: 39# @DESCRIPTION:
35# Set this to use separate source directories for each enabled version of Python. 40# Set this to use separate source directories for each enabled version of Python.
36 41
37# @ECLASS-VARIABLE: DISTUTILS_GLOBAL_OPTIONS 42# @ECLASS-VARIABLE: DISTUTILS_GLOBAL_OPTIONS
38# @DESCRIPTION: 43# @DESCRIPTION:
39# Global options passed to setup.py. 44# Global options passed to setup.py.
40 45
46# @ECLASS-VARIABLE: DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS
47# @DESCRIPTION:
48# Set this to disable renaming of Python scripts containing versioned shebangs
49# and generation of wrapper scripts.
50
41# @ECLASS-VARIABLE: DOCS 51# @ECLASS-VARIABLE: DOCS
42# @DESCRIPTION: 52# @DESCRIPTION:
43# Additional DOCS 53# Additional DOCS
44 54
55_distutils_hook() {
56 if [[ "$#" -ne 1 ]]; then
57 die "${FUNCNAME}() requires 1 argument"
58 fi
59 if [[ "$(type -t "distutils_src_${EBUILD_PHASE}_$1_hook")" == "function" ]]; then
60 "distutils_src_${EBUILD_PHASE}_$1_hook"
61 fi
62}
63
45# @FUNCTION: distutils_src_unpack 64# @FUNCTION: distutils_src_unpack
46# @DESCRIPTION: 65# @DESCRIPTION:
47# The distutils src_unpack function, this function is exported 66# The distutils src_unpack function, this function is exported.
48distutils_src_unpack() { 67distutils_src_unpack() {
49 if [[ "${EBUILD_PHASE}" != "unpack" ]]; then 68 if [[ "${EBUILD_PHASE}" != "unpack" ]]; then
50 die "${FUNCNAME}() can be used only in src_unpack() phase" 69 die "${FUNCNAME}() can be used only in src_unpack() phase"
51 fi 70 fi
52 71
56 has "${EAPI:-0}" 0 1 && distutils_src_prepare 75 has "${EAPI:-0}" 0 1 && distutils_src_prepare
57} 76}
58 77
59# @FUNCTION: distutils_src_prepare 78# @FUNCTION: distutils_src_prepare
60# @DESCRIPTION: 79# @DESCRIPTION:
61# The distutils src_prepare function, this function is exported 80# The distutils src_prepare function, this function is exported.
62distutils_src_prepare() { 81distutils_src_prepare() {
63 if ! has "${EAPI:-0}" 0 1 && [[ "${EBUILD_PHASE}" != "prepare" ]]; then 82 if ! has "${EAPI:-0}" 0 1 && [[ "${EBUILD_PHASE}" != "prepare" ]]; then
64 die "${FUNCNAME}() can be used only in src_prepare() phase" 83 die "${FUNCNAME}() can be used only in src_prepare() phase"
65 fi 84 fi
66 85
67 # Delete ez_setup files to prevent packages from installing 86 # Delete ez_setup files to prevent packages from installing
68 # setuptools on their own. 87 # Setuptools on their own.
69 local ez_setup_existence 88 local ez_setup_existence="0"
70 [[ -d ez_setup || -f ez_setup.py ]] && ez_setup_existence="1" 89 [[ -d ez_setup || -f ez_setup.py ]] && ez_setup_existence="1"
71 rm -fr ez_setup* 90 rm -fr ez_setup*
72 if [[ "${ez_setup_existence}" == "1" ]]; then 91 if [[ "${ez_setup_existence}" == "1" ]]; then
73 echo "def use_setuptools(*args, **kwargs): pass" > ez_setup.py 92 echo "def use_setuptools(*args, **kwargs): pass" > ez_setup.py
74 fi 93 fi
75 94
95 # Delete distribute_setup files to prevent packages from installing
96 # Distribute on their own.
97 local distribute_setup_existence="0"
98 [[ -d distribute_setup || -f distribute_setup.py ]] && distribute_setup_existence="1"
99 rm -fr distribute_setup*
100 if [[ "${distribute_setup_existence}" == "1" ]]; then
101 echo "def use_setuptools(*args, **kwargs): pass" > distribute_setup.py
102 fi
103
76 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then 104 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
77 python_copy_sources 105 python_copy_sources
78 fi 106 fi
79} 107}
80 108
81# @FUNCTION: distutils_src_compile 109# @FUNCTION: distutils_src_compile
82# @DESCRIPTION: 110# @DESCRIPTION:
83# The distutils src_compile function, this function is exported 111# The distutils src_compile function, this function is exported.
112# In newer EAPIs this function calls distutils_src_compile_pre_hook() and
113# distutils_src_compile_post_hook(), if they are defined.
84distutils_src_compile() { 114distutils_src_compile() {
85 if [[ "${EBUILD_PHASE}" != "compile" ]]; then 115 if [[ "${EBUILD_PHASE}" != "compile" ]]; then
86 die "${FUNCNAME}() can be used only in src_compile() phase" 116 die "${FUNCNAME}() can be used only in src_compile() phase"
87 fi 117 fi
88 118
89 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 119 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
90 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then 120 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
91 building() { 121 building() {
122 _distutils_hook pre
123
92 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" 124 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@"
93 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" 125 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || return "$?"
126
127 _distutils_hook post
94 } 128 }
95 python_execute_function -s building "$@" 129 python_execute_function -s building "$@"
96 else 130 else
97 building() { 131 building() {
132 _distutils_hook pre
133
98 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" "$@" 134 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" "$@"
99 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" "$@" 135 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" "$@" || return "$?"
136
137 _distutils_hook post
100 } 138 }
101 python_execute_function building "$@" 139 python_execute_function building "$@"
102 fi 140 fi
103 else 141 else
104 echo ${python} setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" 142 echo "$(PYTHON -A)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@"
105 ${python} setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || die "Building failed" 143 "$(PYTHON -A)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || die "Building failed"
106 fi 144 fi
107} 145}
108 146
109# @FUNCTION: distutils_src_install 147# @FUNCTION: distutils_src_install
110# @DESCRIPTION: 148# @DESCRIPTION:
111# The distutils src_install function, this function is exported. 149# The distutils src_install function, this function is exported.
150# In newer EAPIs this function calls distutils_src_install_pre_hook() and
151# distutils_src_install_post_hook(), if they are defined.
112# It also installs the "standard docs" (CHANGELOG, Change*, KNOWN_BUGS, MAINTAINERS, 152# It also installs the "standard docs" (CHANGELOG, Change*, KNOWN_BUGS, MAINTAINERS,
113# PKG-INFO, CONTRIBUTORS, TODO, NEWS, MANIFEST*, README*, and AUTHORS) 153# PKG-INFO, CONTRIBUTORS, TODO, NEWS, MANIFEST*, README*, and AUTHORS)
114distutils_src_install() { 154distutils_src_install() {
115 if [[ "${EBUILD_PHASE}" != "install" ]]; then 155 if [[ "${EBUILD_PHASE}" != "install" ]]; then
116 die "${FUNCNAME}() can be used only in src_install() phase" 156 die "${FUNCNAME}() can be used only in src_install() phase"
117 fi 157 fi
118 158
119 local pylibdir 159 local pylibdir
120 160
121 # Mark the package to be rebuilt after a python upgrade.
122 python_need_rebuild
123
124 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 161 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
162 if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${BASH_VERSINFO[0]}" -ge "4" ]]; then
163 declare -A wrapper_scripts=()
164
165 rename_scripts_with_versioned_shebangs() {
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
125 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then 180 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
126 installation() { 181 installation() {
182 _distutils_hook pre
183
127 # need this for python-2.5 + setuptools in cases where 184 # need this for python-2.5 + setuptools in cases where
128 # a package uses distutils but does not install anything 185 # a package uses distutils but does not install anything
129 # in site-packages. (eg. dev-java/java-config-2.x) 186 # in site-packages. (eg. dev-java/java-config-2.x)
130 # - liquidx (14/08/2006) 187 # - liquidx (14/08/2006)
131 pylibdir="$("$(PYTHON)" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')" 188 pylibdir="$("$(PYTHON)" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
132 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}" 189 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
133 190
134 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" 191 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@"
135 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" 192 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || return "$?"
193
194 if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${BASH_VERSINFO[0]}" -ge "4" ]]; then
195 rename_scripts_with_versioned_shebangs
196 fi
197
198 _distutils_hook post
136 } 199 }
137 python_execute_function -s installation "$@" 200 python_execute_function -s installation "$@"
138 else 201 else
139 installation() { 202 installation() {
203 _distutils_hook pre
204
140 # need this for python-2.5 + setuptools in cases where 205 # need this for python-2.5 + setuptools in cases where
141 # a package uses distutils but does not install anything 206 # a package uses distutils but does not install anything
142 # in site-packages. (eg. dev-java/java-config-2.x) 207 # in site-packages. (eg. dev-java/java-config-2.x)
143 # - liquidx (14/08/2006) 208 # - liquidx (14/08/2006)
144 pylibdir="$("$(PYTHON)" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')" 209 pylibdir="$("$(PYTHON)" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
145 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}" 210 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
146 211
147 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@" 212 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@"
148 "$(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
149 } 220 }
150 python_execute_function installation "$@" 221 python_execute_function installation "$@"
151 fi 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
152 else 228 else
229 # Mark the package to be rebuilt after a Python upgrade.
230 python_need_rebuild
231
153 # need this for python-2.5 + setuptools in cases where 232 # need this for python-2.5 + setuptools in cases where
154 # a package uses distutils but does not install anything 233 # a package uses distutils but does not install anything
155 # in site-packages. (eg. dev-java/java-config-2.x) 234 # in site-packages. (eg. dev-java/java-config-2.x)
156 # - liquidx (14/08/2006) 235 # - liquidx (14/08/2006)
157 pylibdir="$(${python} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')" 236 pylibdir="$("$(PYTHON -A)" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
158 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}" 237 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
159 238
160 echo ${python} setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" 239 echo "$(PYTHON -A)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@"
161 ${python} setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || die "Installation failed" 240 "$(PYTHON -A)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || die "Installation failed"
162 fi 241 fi
163 242
164 if [[ -e "${D}usr/local" ]]; then 243 if [[ -e "${D}usr/local" ]]; then
165 die "Illegal installation into /usr/local" 244 die "Illegal installation into /usr/local"
166 fi 245 fi
195 fi 274 fi
196 done 275 done
197 fi 276 fi
198 277
199 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 278 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
200 for pymod in ${PYTHON_MODNAME}; do 279 python_mod_optimize ${PYTHON_MODNAME}
201 python_mod_optimize "${pymod}"
202 done
203 else 280 else
204 for pymod in ${PYTHON_MODNAME}; do 281 for pymod in ${PYTHON_MODNAME}; do
205 python_mod_optimize "$(python_get_sitedir)/${pymod}" 282 python_mod_optimize "$(python_get_sitedir)/${pymod}"
206 done 283 done
207 fi 284 fi
223 fi 300 fi
224 done 301 done
225 fi 302 fi
226 303
227 if [[ -n "${PYTHON_MODNAME}" ]]; then 304 if [[ -n "${PYTHON_MODNAME}" ]]; then
228 for pymod in ${PYTHON_MODNAME}; do
229 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 305 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
230 python_mod_cleanup "${pymod}" 306 python_mod_cleanup ${PYTHON_MODNAME}
231 else 307 else
308 for pymod in ${PYTHON_MODNAME}; do
232 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do 309 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
233 if [[ -d "${pylibdir}/site-packages/${pymod}" ]]; then 310 if [[ -d "${pylibdir}/site-packages/${pymod}" ]]; then
234 python_mod_cleanup "${pylibdir#${ROOT}}/site-packages/${pymod}" 311 python_mod_cleanup "${pylibdir#${ROOT}}/site-packages/${pymod}"
235 fi 312 fi
236 done 313 done
237 fi
238 done 314 done
315 fi
239 else 316 else
240 python_mod_cleanup 317 python_mod_cleanup
241 fi 318 fi
242} 319}
243 320
244# @FUNCTION: distutils_python_version 321# @FUNCTION: distutils_python_version
245# @DESCRIPTION: 322# @DESCRIPTION:
246# Calls python_version, so that you can use something like 323# Calls python_version, so that you can use something like
247# e.g. insinto ${ROOT}/usr/include/python${PYVER} 324# e.g. insinto $(python_get_includedir)
248distutils_python_version() { 325distutils_python_version() {
326 if ! has "${EAPI:-0}" 0 1 2; then
327 die "${FUNCNAME}() cannot be used in this EAPI"
328 fi
329
249 python_version 330 python_version
250} 331}
251 332
252# @FUNCTION: distutils_python_tkinter 333# @FUNCTION: distutils_python_tkinter
253# @DESCRIPTION: 334# @DESCRIPTION:
254# Checks for if tkinter support is compiled into python 335# Checks for if tkinter support is compiled into python
255distutils_python_tkinter() { 336distutils_python_tkinter() {
337 if ! has "${EAPI:-0}" 0 1 2; then
338 die "${FUNCNAME}() cannot be used in this EAPI"
339 fi
340
256 python_tkinter_exists 341 python_tkinter_exists
257} 342}

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

  ViewVC Help
Powered by ViewVC 1.1.20