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

Contents of /eclass/distutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.67 - (hide annotations) (download)
Sat Nov 28 18:39:27 2009 UTC (4 years, 4 months ago) by arfrever
Branch: MAIN
Changes since 1.66: +44 -14 lines
Add support for distutils_src_{compile,install}_{pre,post}_hook(). Use $(PYTHON ${PYVER}) instead of ${python} in distutils_src_compile() and distutils_src_install() to support multilib systems in older EAPIs.

1 arfrever 1.56 # Copyright 1999-2009 Gentoo Foundation
2 vapier 1.4 # Distributed under the terms of the GNU General Public License v2
3 arfrever 1.67 # $Header: /var/cvsroot/gentoo-x86/eclass/distutils.eclass,v 1.66 2009/11/06 00:35:30 arfrever Exp $
4 dev-zero 1.46
5     # @ECLASS: distutils.eclass
6     # @MAINTAINER:
7 hawking 1.48 # <python@gentoo.org>
8 vapier 1.5 #
9 dev-zero 1.46 # Original author: Jon Nelson <jnelson@gentoo.org>
10     # @BLURB: This eclass allows easier installation of distutils-based python modules
11     # @DESCRIPTION:
12 jnelson 1.1 # The distutils eclass is designed to allow easier installation of
13 swegener 1.28 # distutils-based python modules and their incorporation into
14 jnelson 1.1 # the Gentoo Linux system.
15    
16 arfrever 1.59 inherit eutils multilib python
17 liquidx 1.16
18 pva 1.55 case "${EAPI:-0}" in
19     0|1)
20     EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_postinst pkg_postrm
21     ;;
22     *)
23     EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install pkg_postinst pkg_postrm
24     ;;
25     esac
26    
27 arfrever 1.62 if [[ -z "${DISTUTILS_DISABLE_PYTHON_DEPENDENCY}" ]]; then
28     DEPEND="virtual/python"
29     RDEPEND="${DEPEND}"
30     fi
31 arfrever 1.60 python="python"
32    
33 arfrever 1.61 # @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 arfrever 1.60 # @ECLASS-VARIABLE: DISTUTILS_GLOBAL_OPTIONS
38 dev-zero 1.46 # @DESCRIPTION:
39 arfrever 1.60 # Global options passed to setup.py.
40 jnelson 1.1
41 dev-zero 1.46 # @ECLASS-VARIABLE: DOCS
42     # @DESCRIPTION:
43     # Additional DOCS
44    
45 arfrever 1.67 _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 dev-zero 1.46 # @FUNCTION: distutils_src_unpack
55     # @DESCRIPTION:
56 arfrever 1.67 # The distutils src_unpack function, this function is exported.
57 lucass 1.41 distutils_src_unpack() {
58 arfrever 1.59 if [[ "${EBUILD_PHASE}" != "unpack" ]]; then
59     die "${FUNCNAME}() can be used only in src_unpack() phase"
60     fi
61    
62 lucass 1.41 unpack ${A}
63     cd "${S}"
64    
65 arfrever 1.56 has "${EAPI:-0}" 0 1 && distutils_src_prepare
66 pva 1.55 }
67    
68     # @FUNCTION: distutils_src_prepare
69     # @DESCRIPTION:
70 arfrever 1.67 # The distutils src_prepare function, this function is exported.
71 pva 1.55 distutils_src_prepare() {
72 arfrever 1.59 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 arfrever 1.61 # Delete ez_setup files to prevent packages from installing
77 arfrever 1.66 # Setuptools on their own.
78     local ez_setup_existence="0"
79 arfrever 1.63 [[ -d ez_setup || -f ez_setup.py ]] && ez_setup_existence="1"
80 arfrever 1.61 rm -fr ez_setup*
81 arfrever 1.63 if [[ "${ez_setup_existence}" == "1" ]]; then
82 arfrever 1.61 echo "def use_setuptools(*args, **kwargs): pass" > ez_setup.py
83     fi
84    
85 arfrever 1.66 # 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 arfrever 1.61 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
95     python_copy_sources
96     fi
97 lucass 1.41 }
98    
99 dev-zero 1.46 # @FUNCTION: distutils_src_compile
100     # @DESCRIPTION:
101 arfrever 1.67 # 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.
104 jnelson 1.1 distutils_src_compile() {
105 arfrever 1.59 if [[ "${EBUILD_PHASE}" != "compile" ]]; then
106     die "${FUNCNAME}() can be used only in src_compile() phase"
107     fi
108    
109 arfrever 1.56 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
110 arfrever 1.61 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
111     building() {
112 arfrever 1.67 _distutils_hook pre
113    
114 arfrever 1.61 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@"
115 arfrever 1.67 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || return "$?"
116    
117     _distutils_hook post
118 arfrever 1.61 }
119     python_execute_function -s building "$@"
120     else
121     building() {
122 arfrever 1.67 _distutils_hook pre
123    
124 arfrever 1.61 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" "$@"
125 arfrever 1.67 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" "$@" || return "$?"
126    
127     _distutils_hook post
128 arfrever 1.61 }
129     python_execute_function building "$@"
130     fi
131 arfrever 1.56 else
132 arfrever 1.67 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 arfrever 1.56 fi
136 jnelson 1.1 }
137    
138 dev-zero 1.46 # @FUNCTION: distutils_src_install
139     # @DESCRIPTION:
140     # The distutils src_install function, this function is exported.
141 arfrever 1.67 # In newer EAPIs this function calls distutils_src_install_pre_hook() and
142     # distutils_src_install_post_hook(), if they are defined.
143 dev-zero 1.46 # It also installs the "standard docs" (CHANGELOG, Change*, KNOWN_BUGS, MAINTAINERS,
144     # PKG-INFO, CONTRIBUTORS, TODO, NEWS, MANIFEST*, README*, and AUTHORS)
145 jnelson 1.1 distutils_src_install() {
146 arfrever 1.59 if [[ "${EBUILD_PHASE}" != "install" ]]; then
147     die "${FUNCNAME}() can be used only in src_install() phase"
148     fi
149    
150 arfrever 1.58 local pylibdir
151 liquidx 1.33
152 hawking 1.53 # Mark the package to be rebuilt after a python upgrade.
153     python_need_rebuild
154    
155 arfrever 1.56 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
156 arfrever 1.61 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
157     installation() {
158 arfrever 1.67 _distutils_hook pre
159    
160 arfrever 1.61 # 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 arfrever 1.67 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || return "$?"
169    
170     _distutils_hook post
171 arfrever 1.61 }
172     python_execute_function -s installation "$@"
173     else
174     installation() {
175 arfrever 1.67 _distutils_hook pre
176    
177 arfrever 1.61 # 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 arfrever 1.67 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@" || return "$?"
186    
187     _distutils_hook post
188 arfrever 1.61 }
189     python_execute_function installation "$@"
190     fi
191 liquidx 1.18 else
192 arfrever 1.56 # 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 arfrever 1.67 pylibdir="$("$(PYTHON "${PYVER}")" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
197 arfrever 1.56 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
198    
199 arfrever 1.67 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 swegener 1.28 fi
202 lanius 1.20
203 arfrever 1.64 if [[ -e "${D}usr/local" ]]; then
204     die "Illegal installation into /usr/local"
205     fi
206    
207 arfrever 1.62 local default_docs
208     default_docs="AUTHORS Change* CHANGELOG CONTRIBUTORS KNOWN_BUGS MAINTAINERS MANIFEST* NEWS PKG-INFO README* TODO"
209 lanius 1.20
210 arfrever 1.56 local doc
211 arfrever 1.62 for doc in ${default_docs}; do
212     [[ -s "${doc}" ]] && dodoc "${doc}"
213 lanius 1.20 done
214    
215 arfrever 1.62 if [[ -n "${DOCS}" ]]; then
216     dodoc ${DOCS} || die "dodoc failed"
217     fi
218 jnelson 1.1 }
219 kutsuya 1.6
220 arfrever 1.63 # @FUNCTION: distutils_pkg_postinst
221 dev-zero 1.46 # @DESCRIPTION:
222 arfrever 1.63 # 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 arfrever 1.59 fi
228    
229 arfrever 1.56 local pylibdir pymod
230 hawking 1.54 if [[ -z "${PYTHON_MODNAME}" ]]; then
231     for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
232 arfrever 1.56 if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
233     PYTHON_MODNAME="${PN}"
234 hawking 1.54 fi
235     done
236 hawking 1.49 fi
237 liquidx 1.19
238 arfrever 1.63 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
239 arfrever 1.65 python_mod_optimize ${PYTHON_MODNAME}
240 arfrever 1.56 else
241 arfrever 1.63 for pymod in ${PYTHON_MODNAME}; do
242     python_mod_optimize "$(python_get_sitedir)/${pymod}"
243     done
244 swegener 1.28 fi
245 liquidx 1.19 }
246    
247 arfrever 1.63 # @FUNCTION: distutils_pkg_postrm
248 dev-zero 1.46 # @DESCRIPTION:
249 arfrever 1.63 # 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 arfrever 1.59 fi
254    
255 hawking 1.54 local pylibdir pymod
256     if [[ -z "${PYTHON_MODNAME}" ]]; then
257     for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
258 arfrever 1.56 if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
259     PYTHON_MODNAME="${PN}"
260 hawking 1.54 fi
261     done
262 hawking 1.50 fi
263 swegener 1.28
264 arfrever 1.63 if [[ -n "${PYTHON_MODNAME}" ]]; then
265 arfrever 1.65 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 arfrever 1.63 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 arfrever 1.65 done
275     fi
276 arfrever 1.56 else
277 arfrever 1.63 python_mod_cleanup
278 swegener 1.28 fi
279 liquidx 1.19 }
280    
281 dev-zero 1.46 # @FUNCTION: distutils_python_version
282     # @DESCRIPTION:
283     # Calls python_version, so that you can use something like
284 arfrever 1.67 # e.g. insinto ${ROOT}/usr/include/python${PYVER}
285 liquidx 1.13 distutils_python_version() {
286 liquidx 1.34 python_version
287 liquidx 1.12 }
288    
289 dev-zero 1.46 # @FUNCTION: distutils_python_tkinter
290     # @DESCRIPTION:
291     # Checks for if tkinter support is compiled into python
292 liquidx 1.12 distutils_python_tkinter() {
293 lucass 1.40 python_tkinter_exists
294 vapier 1.8 }

  ViewVC Help
Powered by ViewVC 1.1.20