| 1 | # Copyright 1999-2003 Gentoo Technologies, Inc. |
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.13 2003/09/09 17:18:27 liquidx Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/distutils.eclass,v 1.67 2009/11/28 18:39:27 arfrever Exp $ |
|
|
4 | |
|
|
5 | # @ECLASS: distutils.eclass |
|
|
6 | # @MAINTAINER: |
|
|
7 | # <python@gentoo.org> |
| 4 | # |
8 | # |
| 5 | # Author: Jon Nelson <jnelson@gentoo.org> |
9 | # Original author: Jon Nelson <jnelson@gentoo.org> |
| 6 | # Current Maintainer: Alastair Tse <liquidx@gentoo.org> |
10 | # @BLURB: This eclass allows easier installation of distutils-based python modules |
| 7 | # |
11 | # @DESCRIPTION: |
| 8 | # The distutils eclass is designed to allow easier installation of |
12 | # The distutils eclass is designed to allow easier installation of |
| 9 | # distutils-based python modules and their incorporation into |
13 | # distutils-based python modules and their incorporation into |
| 10 | # the Gentoo Linux system. |
14 | # the Gentoo Linux system. |
| 11 | # |
|
|
| 12 | # - Features: |
|
|
| 13 | # distutils_src_compile() - does python setup.py build |
|
|
| 14 | # distutils_src_install() - does python setup.py install and install docs |
|
|
| 15 | # distutils_python_version() - sets PYVER/PYVER_MAJOR/PYVER_MINOR |
|
|
| 16 | # distutils_python_tkinter() - checks for tkinter support in python |
|
|
| 17 | # |
|
|
| 18 | # - Variables: |
|
|
| 19 | # PYTHON_SLOT_VERSION - for Zope support |
|
|
| 20 | # DOCS - additional DOCS |
|
|
| 21 | |
15 | |
| 22 | ECLASS=distutils |
16 | inherit eutils multilib python |
| 23 | INHERITED="$INHERITED $ECLASS" |
|
|
| 24 | |
17 | |
| 25 | # This helps make it possible to add extensions to python slots. |
18 | case "${EAPI:-0}" in |
| 26 | # Normally only a -py21- ebuild would set PYTHON_SLOT_VERSION. |
19 | 0|1) |
| 27 | if [ "${PYTHON_SLOT_VERSION}" = 2.1 ] ; then |
20 | EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_postinst pkg_postrm |
| 28 | newdepend "=dev-lang/python-2.1*" |
21 | ;; |
| 29 | python="python2.1" |
22 | *) |
| 30 | else |
23 | EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install pkg_postinst pkg_postrm |
| 31 | newdepend "virtual/python" |
24 | ;; |
| 32 | python="python" |
25 | esac |
|
|
26 | |
|
|
27 | if [[ -z "${DISTUTILS_DISABLE_PYTHON_DEPENDENCY}" ]]; then |
|
|
28 | DEPEND="virtual/python" |
|
|
29 | RDEPEND="${DEPEND}" |
| 33 | fi |
30 | fi |
|
|
31 | python="python" |
| 34 | |
32 | |
|
|
33 | # @ECLASS-VARIABLE: DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES |
|
|
34 | # @DESCRIPTION: |
|
|
35 | # Set this to use separate source directories for each enabled version of Python. |
|
|
36 | |
|
|
37 | # @ECLASS-VARIABLE: DISTUTILS_GLOBAL_OPTIONS |
|
|
38 | # @DESCRIPTION: |
|
|
39 | # Global options passed to setup.py. |
|
|
40 | |
|
|
41 | # @ECLASS-VARIABLE: DOCS |
|
|
42 | # @DESCRIPTION: |
|
|
43 | # Additional DOCS |
|
|
44 | |
|
|
45 | _distutils_hook() { |
|
|
46 | if [[ "$#" -ne 1 ]]; then |
|
|
47 | die "${FUNCNAME}() requires 1 argument" |
|
|
48 | fi |
|
|
49 | if [[ "$(type -t "distutils_src_${EBUILD_PHASE}_$1_hook")" == "function" ]]; then |
|
|
50 | "distutils_src_${EBUILD_PHASE}_$1_hook" |
|
|
51 | fi |
|
|
52 | } |
|
|
53 | |
|
|
54 | # @FUNCTION: distutils_src_unpack |
|
|
55 | # @DESCRIPTION: |
|
|
56 | # The distutils src_unpack function, this function is exported. |
|
|
57 | distutils_src_unpack() { |
|
|
58 | if [[ "${EBUILD_PHASE}" != "unpack" ]]; then |
|
|
59 | die "${FUNCNAME}() can be used only in src_unpack() phase" |
|
|
60 | fi |
|
|
61 | |
|
|
62 | unpack ${A} |
|
|
63 | cd "${S}" |
|
|
64 | |
|
|
65 | has "${EAPI:-0}" 0 1 && distutils_src_prepare |
|
|
66 | } |
|
|
67 | |
|
|
68 | # @FUNCTION: distutils_src_prepare |
|
|
69 | # @DESCRIPTION: |
|
|
70 | # The distutils src_prepare function, this function is exported. |
|
|
71 | distutils_src_prepare() { |
|
|
72 | if ! has "${EAPI:-0}" 0 1 && [[ "${EBUILD_PHASE}" != "prepare" ]]; then |
|
|
73 | die "${FUNCNAME}() can be used only in src_prepare() phase" |
|
|
74 | fi |
|
|
75 | |
|
|
76 | # Delete ez_setup files to prevent packages from installing |
|
|
77 | # Setuptools on their own. |
|
|
78 | local ez_setup_existence="0" |
|
|
79 | [[ -d ez_setup || -f ez_setup.py ]] && ez_setup_existence="1" |
|
|
80 | rm -fr ez_setup* |
|
|
81 | if [[ "${ez_setup_existence}" == "1" ]]; then |
|
|
82 | echo "def use_setuptools(*args, **kwargs): pass" > ez_setup.py |
|
|
83 | fi |
|
|
84 | |
|
|
85 | # Delete distribute_setup files to prevent packages from installing |
|
|
86 | # Distribute on their own. |
|
|
87 | local distribute_setup_existence="0" |
|
|
88 | [[ -d distribute_setup || -f distribute_setup.py ]] && distribute_setup_existence="1" |
|
|
89 | rm -fr distribute_setup* |
|
|
90 | if [[ "${distribute_setup_existence}" == "1" ]]; then |
|
|
91 | echo "def use_setuptools(*args, **kwargs): pass" > distribute_setup.py |
|
|
92 | fi |
|
|
93 | |
|
|
94 | if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then |
|
|
95 | python_copy_sources |
|
|
96 | fi |
|
|
97 | } |
|
|
98 | |
|
|
99 | # @FUNCTION: distutils_src_compile |
|
|
100 | # @DESCRIPTION: |
|
|
101 | # The distutils src_compile function, this function is exported. |
|
|
102 | # In newer EAPIs this function calls distutils_src_compile_pre_hook() and |
|
|
103 | # distutils_src_compile_post_hook(), if they are defined. |
| 35 | distutils_src_compile() { |
104 | distutils_src_compile() { |
| 36 | ${python} setup.py build ${@} || die "compilation failed" |
105 | if [[ "${EBUILD_PHASE}" != "compile" ]]; then |
| 37 | } |
106 | die "${FUNCNAME}() can be used only in src_compile() phase" |
|
|
107 | fi |
| 38 | |
108 | |
|
|
109 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
110 | if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then |
|
|
111 | building() { |
|
|
112 | _distutils_hook pre |
|
|
113 | |
|
|
114 | echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" |
|
|
115 | "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || return "$?" |
|
|
116 | |
|
|
117 | _distutils_hook post |
|
|
118 | } |
|
|
119 | python_execute_function -s building "$@" |
|
|
120 | else |
|
|
121 | building() { |
|
|
122 | _distutils_hook pre |
|
|
123 | |
|
|
124 | echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" "$@" |
|
|
125 | "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" "$@" || return "$?" |
|
|
126 | |
|
|
127 | _distutils_hook post |
|
|
128 | } |
|
|
129 | python_execute_function building "$@" |
|
|
130 | fi |
|
|
131 | else |
|
|
132 | python_version |
|
|
133 | echo "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" |
|
|
134 | "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || die "Building failed" |
|
|
135 | fi |
|
|
136 | } |
|
|
137 | |
|
|
138 | # @FUNCTION: distutils_src_install |
|
|
139 | # @DESCRIPTION: |
|
|
140 | # The distutils src_install function, this function is exported. |
|
|
141 | # In newer EAPIs this function calls distutils_src_install_pre_hook() and |
|
|
142 | # distutils_src_install_post_hook(), if they are defined. |
|
|
143 | # It also installs the "standard docs" (CHANGELOG, Change*, KNOWN_BUGS, MAINTAINERS, |
|
|
144 | # PKG-INFO, CONTRIBUTORS, TODO, NEWS, MANIFEST*, README*, and AUTHORS) |
| 39 | distutils_src_install() { |
145 | distutils_src_install() { |
| 40 | ${python} setup.py install --root=${D} ${@} || die |
146 | if [[ "${EBUILD_PHASE}" != "install" ]]; then |
| 41 | |
147 | die "${FUNCNAME}() can be used only in src_install() phase" |
| 42 | dodoc CHANGELOG COPYRIGHT KNOWN_BUGS MAINTAINERS |
148 | fi |
| 43 | dodoc CONTRIBUTORS LICENSE COPYING* |
149 | |
| 44 | dodoc Change* MANIFEST* README* |
150 | local pylibdir |
| 45 | |
151 | |
| 46 | [ -n "${DOCS}" ] && dodoc ${DOCS} |
152 | # Mark the package to be rebuilt after a python upgrade. |
| 47 | |
153 | python_need_rebuild |
| 48 | # deprecated! please use DOCS instead. |
154 | |
|
|
155 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
156 | if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then |
|
|
157 | installation() { |
|
|
158 | _distutils_hook pre |
|
|
159 | |
|
|
160 | # need this for python-2.5 + setuptools in cases where |
|
|
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 | |
|
|
167 | echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" |
|
|
168 | "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || return "$?" |
|
|
169 | |
|
|
170 | _distutils_hook post |
|
|
171 | } |
|
|
172 | python_execute_function -s installation "$@" |
|
|
173 | else |
|
|
174 | installation() { |
|
|
175 | _distutils_hook pre |
|
|
176 | |
|
|
177 | # need this for python-2.5 + setuptools in cases where |
|
|
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 | |
|
|
184 | echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@" |
|
|
185 | "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@" || return "$?" |
|
|
186 | |
|
|
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 "$@" |
|
|
200 | "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || die "Installation failed" |
|
|
201 | fi |
|
|
202 | |
|
|
203 | if [[ -e "${D}usr/local" ]]; then |
|
|
204 | die "Illegal installation into /usr/local" |
|
|
205 | fi |
|
|
206 | |
|
|
207 | local default_docs |
|
|
208 | default_docs="AUTHORS Change* CHANGELOG CONTRIBUTORS KNOWN_BUGS MAINTAINERS MANIFEST* NEWS PKG-INFO README* TODO" |
|
|
209 | |
|
|
210 | local doc |
|
|
211 | for doc in ${default_docs}; do |
| 49 | [ -n "${mydoc}" ] && dodoc ${mydoc} |
212 | [[ -s "${doc}" ]] && dodoc "${doc}" |
| 50 | } |
213 | done |
| 51 | |
214 | |
|
|
215 | if [[ -n "${DOCS}" ]]; then |
|
|
216 | dodoc ${DOCS} || die "dodoc failed" |
|
|
217 | fi |
|
|
218 | } |
|
|
219 | |
|
|
220 | # @FUNCTION: distutils_pkg_postinst |
|
|
221 | # @DESCRIPTION: |
|
|
222 | # This is a generic optimization, you should override it if your package |
|
|
223 | # installs modules in another directory. This function is exported. |
|
|
224 | distutils_pkg_postinst() { |
|
|
225 | if [[ "${EBUILD_PHASE}" != "postinst" ]]; then |
|
|
226 | die "${FUNCNAME}() can be used only in pkg_postinst() phase" |
|
|
227 | fi |
|
|
228 | |
|
|
229 | local pylibdir pymod |
|
|
230 | if [[ -z "${PYTHON_MODNAME}" ]]; then |
|
|
231 | for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do |
|
|
232 | if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then |
|
|
233 | PYTHON_MODNAME="${PN}" |
|
|
234 | fi |
|
|
235 | done |
|
|
236 | fi |
|
|
237 | |
|
|
238 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
239 | python_mod_optimize ${PYTHON_MODNAME} |
|
|
240 | else |
|
|
241 | for pymod in ${PYTHON_MODNAME}; do |
|
|
242 | python_mod_optimize "$(python_get_sitedir)/${pymod}" |
|
|
243 | done |
|
|
244 | fi |
|
|
245 | } |
|
|
246 | |
|
|
247 | # @FUNCTION: distutils_pkg_postrm |
|
|
248 | # @DESCRIPTION: |
|
|
249 | # Generic pyc/pyo cleanup script. This function is exported. |
|
|
250 | distutils_pkg_postrm() { |
|
|
251 | if [[ "${EBUILD_PHASE}" != "postrm" ]]; then |
|
|
252 | die "${FUNCNAME}() can be used only in pkg_postrm() phase" |
|
|
253 | fi |
|
|
254 | |
|
|
255 | local pylibdir pymod |
|
|
256 | if [[ -z "${PYTHON_MODNAME}" ]]; then |
|
|
257 | for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do |
|
|
258 | if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then |
|
|
259 | PYTHON_MODNAME="${PN}" |
|
|
260 | fi |
|
|
261 | done |
|
|
262 | fi |
|
|
263 | |
|
|
264 | if [[ -n "${PYTHON_MODNAME}" ]]; then |
|
|
265 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
266 | python_mod_cleanup ${PYTHON_MODNAME} |
|
|
267 | else |
|
|
268 | for pymod in ${PYTHON_MODNAME}; do |
|
|
269 | for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do |
|
|
270 | if [[ -d "${pylibdir}/site-packages/${pymod}" ]]; then |
|
|
271 | python_mod_cleanup "${pylibdir#${ROOT}}/site-packages/${pymod}" |
|
|
272 | fi |
|
|
273 | done |
|
|
274 | done |
|
|
275 | fi |
|
|
276 | else |
|
|
277 | python_mod_cleanup |
|
|
278 | fi |
|
|
279 | } |
|
|
280 | |
|
|
281 | # @FUNCTION: distutils_python_version |
|
|
282 | # @DESCRIPTION: |
|
|
283 | # Calls python_version, so that you can use something like |
| 52 | # e.g. insinto ${ROOT}/usr/include/python${PYVER} |
284 | # e.g. insinto ${ROOT}/usr/include/python${PYVER} |
| 53 | |
|
|
| 54 | distutils_python_version() { |
285 | distutils_python_version() { |
| 55 | local tmpstr="$(${python} -V 2>&1 )" |
286 | python_version |
| 56 | export PYVER_ALL="${tmpstr#Python }" |
|
|
| 57 | |
|
|
| 58 | export PYVER_MAJOR=$(echo ${PYVER_ALL} | cut -d. -f1) |
|
|
| 59 | export PYVER_MINOR=$(echo ${PYVER_ALL} | cut -d. -f2) |
|
|
| 60 | export PYVER_MICRO=$(echo ${PYVER_ALL} | cut -d. -f3-) |
|
|
| 61 | export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}" |
|
|
| 62 | } |
287 | } |
| 63 | |
288 | |
|
|
289 | # @FUNCTION: distutils_python_tkinter |
|
|
290 | # @DESCRIPTION: |
| 64 | # checks for if tkinter support is compiled into python |
291 | # Checks for if tkinter support is compiled into python |
| 65 | distutils_python_tkinter() { |
292 | distutils_python_tkinter() { |
| 66 | if ! python -c "import Tkinter" >/dev/null 2>&1; then |
293 | python_tkinter_exists |
| 67 | eerror "You need to recompile python with Tkinter support." |
|
|
| 68 | eerror "That means: USE='tcltk' emerge python" |
|
|
| 69 | echo |
|
|
| 70 | die "missing tkinter support with installed python" |
|
|
| 71 | fi |
|
|
| 72 | } |
294 | } |
| 73 | |
|
|
| 74 | # export PYVER as well |
|
|
| 75 | distutils_python_version |
|
|
| 76 | |
|
|
| 77 | EXPORT_FUNCTIONS src_compile src_install |
|
|
| 78 | |
|
|