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

Contents of /eclass/distutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.68 - (hide annotations) (download)
Thu Dec 24 04:21:39 2009 UTC (4 years, 8 months ago) by arfrever
Branch: MAIN
Changes since 1.67: +51 -2 lines
Disallow using of ${python}, distutils_python_version() and distutils_python_tkinter() in EAPI >=3. Add renaming of Python scripts containing versioned shebangs and generation of wrapper scripts.

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.68 # $Header: /var/cvsroot/gentoo-x86/eclass/distutils.eclass,v 1.67 2009/11/28 18:39:27 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.68
32     if has "${EAPI:-0}" 0 1 2; then
33     python="python"
34     else
35     python="die"
36     fi
37 arfrever 1.60
38 arfrever 1.61 # @ECLASS-VARIABLE: DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES
39     # @DESCRIPTION:
40     # Set this to use separate source directories for each enabled version of Python.
41    
42 arfrever 1.60 # @ECLASS-VARIABLE: DISTUTILS_GLOBAL_OPTIONS
43 dev-zero 1.46 # @DESCRIPTION:
44 arfrever 1.60 # Global options passed to setup.py.
45 jnelson 1.1
46 arfrever 1.68 # @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    
51 dev-zero 1.46 # @ECLASS-VARIABLE: DOCS
52     # @DESCRIPTION:
53     # Additional DOCS
54    
55 arfrever 1.67 _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    
64 dev-zero 1.46 # @FUNCTION: distutils_src_unpack
65     # @DESCRIPTION:
66 arfrever 1.67 # The distutils src_unpack function, this function is exported.
67 lucass 1.41 distutils_src_unpack() {
68 arfrever 1.59 if [[ "${EBUILD_PHASE}" != "unpack" ]]; then
69     die "${FUNCNAME}() can be used only in src_unpack() phase"
70     fi
71    
72 lucass 1.41 unpack ${A}
73     cd "${S}"
74    
75 arfrever 1.56 has "${EAPI:-0}" 0 1 && distutils_src_prepare
76 pva 1.55 }
77    
78     # @FUNCTION: distutils_src_prepare
79     # @DESCRIPTION:
80 arfrever 1.67 # The distutils src_prepare function, this function is exported.
81 pva 1.55 distutils_src_prepare() {
82 arfrever 1.59 if ! has "${EAPI:-0}" 0 1 && [[ "${EBUILD_PHASE}" != "prepare" ]]; then
83     die "${FUNCNAME}() can be used only in src_prepare() phase"
84     fi
85    
86 arfrever 1.61 # Delete ez_setup files to prevent packages from installing
87 arfrever 1.66 # Setuptools on their own.
88     local ez_setup_existence="0"
89 arfrever 1.63 [[ -d ez_setup || -f ez_setup.py ]] && ez_setup_existence="1"
90 arfrever 1.61 rm -fr ez_setup*
91 arfrever 1.63 if [[ "${ez_setup_existence}" == "1" ]]; then
92 arfrever 1.61 echo "def use_setuptools(*args, **kwargs): pass" > ez_setup.py
93     fi
94    
95 arfrever 1.66 # 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    
104 arfrever 1.61 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
105     python_copy_sources
106     fi
107 lucass 1.41 }
108    
109 dev-zero 1.46 # @FUNCTION: distutils_src_compile
110     # @DESCRIPTION:
111 arfrever 1.67 # 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.
114 jnelson 1.1 distutils_src_compile() {
115 arfrever 1.59 if [[ "${EBUILD_PHASE}" != "compile" ]]; then
116     die "${FUNCNAME}() can be used only in src_compile() phase"
117     fi
118    
119 arfrever 1.56 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
120 arfrever 1.61 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
121     building() {
122 arfrever 1.67 _distutils_hook pre
123    
124 arfrever 1.61 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@"
125 arfrever 1.67 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || return "$?"
126    
127     _distutils_hook post
128 arfrever 1.61 }
129     python_execute_function -s building "$@"
130     else
131     building() {
132 arfrever 1.67 _distutils_hook pre
133    
134 arfrever 1.61 echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" "$@"
135 arfrever 1.67 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" "$@" || return "$?"
136    
137     _distutils_hook post
138 arfrever 1.61 }
139     python_execute_function building "$@"
140     fi
141 arfrever 1.56 else
142 arfrever 1.67 python_version
143     echo "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@"
144     "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build "$@" || die "Building failed"
145 arfrever 1.56 fi
146 jnelson 1.1 }
147    
148 dev-zero 1.46 # @FUNCTION: distutils_src_install
149     # @DESCRIPTION:
150     # The distutils src_install function, this function is exported.
151 arfrever 1.67 # In newer EAPIs this function calls distutils_src_install_pre_hook() and
152     # distutils_src_install_post_hook(), if they are defined.
153 dev-zero 1.46 # It also installs the "standard docs" (CHANGELOG, Change*, KNOWN_BUGS, MAINTAINERS,
154     # PKG-INFO, CONTRIBUTORS, TODO, NEWS, MANIFEST*, README*, and AUTHORS)
155 jnelson 1.1 distutils_src_install() {
156 arfrever 1.59 if [[ "${EBUILD_PHASE}" != "install" ]]; then
157     die "${FUNCNAME}() can be used only in src_install() phase"
158     fi
159    
160 arfrever 1.58 local pylibdir
161 liquidx 1.33
162 hawking 1.53 # Mark the package to be rebuilt after a python upgrade.
163     python_need_rebuild
164    
165 arfrever 1.56 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
166 arfrever 1.68 if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${BASH_VERSINFO[0]}" -ge "4" ]]; then
167     declare -A wrapper_scripts=()
168    
169     rename_scripts_with_versioned_shebangs() {
170     if [[ -d "${D}usr/bin" ]]; then
171     cd "${D}usr/bin"
172    
173     local file
174     for file in *; do
175     if [[ -f "${file}" && ! "${file}" =~ [[:digit:]]+\.[[:digit:]]+$ && "$(head -n1 "${file}")" =~ ^'#!'.*python[[:digit:]]+\.[[:digit:]]+ ]]; then
176     mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed"
177     wrapper_scripts+=(["${D}usr/bin/${file}"]=)
178     fi
179     done
180     fi
181     }
182     fi
183    
184 arfrever 1.61 if [[ -n "${DISTUTILS_USE_SEPARATE_SOURCE_DIRECTORIES}" ]]; then
185     installation() {
186 arfrever 1.67 _distutils_hook pre
187    
188 arfrever 1.61 # need this for python-2.5 + setuptools in cases where
189     # a package uses distutils but does not install anything
190     # in site-packages. (eg. dev-java/java-config-2.x)
191     # - liquidx (14/08/2006)
192     pylibdir="$("$(PYTHON)" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
193     [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
194    
195     echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@"
196 arfrever 1.67 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || return "$?"
197    
198 arfrever 1.68 if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${BASH_VERSINFO[0]}" -ge "4" ]]; then
199     rename_scripts_with_versioned_shebangs
200     fi
201    
202 arfrever 1.67 _distutils_hook post
203 arfrever 1.61 }
204     python_execute_function -s installation "$@"
205     else
206     installation() {
207 arfrever 1.67 _distutils_hook pre
208    
209 arfrever 1.61 # need this for python-2.5 + setuptools in cases where
210     # a package uses distutils but does not install anything
211     # in site-packages. (eg. dev-java/java-config-2.x)
212     # - liquidx (14/08/2006)
213     pylibdir="$("$(PYTHON)" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
214     [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
215    
216     echo "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@"
217 arfrever 1.67 "$(PYTHON)" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@" || return "$?"
218    
219 arfrever 1.68 if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${BASH_VERSINFO[0]}" -ge "4" ]]; then
220     rename_scripts_with_versioned_shebangs
221     fi
222    
223 arfrever 1.67 _distutils_hook post
224 arfrever 1.61 }
225     python_execute_function installation "$@"
226     fi
227 arfrever 1.68
228     if [[ -z "${DISTUTILS_DISABLE_VERSIONING_OF_PYTHON_SCRIPTS}" && "${#wrapper_scripts[@]}" -ne "0" && "${BASH_VERSINFO[0]}" -ge "4" ]]; then
229     python_generate_wrapper_scripts "${!wrapper_scripts[@]}"
230     fi
231     unset wrapper_scripts
232 liquidx 1.18 else
233 arfrever 1.56 # need this for python-2.5 + setuptools in cases where
234     # a package uses distutils but does not install anything
235     # in site-packages. (eg. dev-java/java-config-2.x)
236     # - liquidx (14/08/2006)
237 arfrever 1.67 pylibdir="$("$(PYTHON "${PYVER}")" -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
238 arfrever 1.56 [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
239    
240 arfrever 1.67 echo "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@"
241     "$(PYTHON "${PYVER}")" setup.py "${DISTUTILS_GLOBAL_OPTIONS[@]}" install --root="${D}" --no-compile "$@" || die "Installation failed"
242 swegener 1.28 fi
243 lanius 1.20
244 arfrever 1.64 if [[ -e "${D}usr/local" ]]; then
245     die "Illegal installation into /usr/local"
246     fi
247    
248 arfrever 1.62 local default_docs
249     default_docs="AUTHORS Change* CHANGELOG CONTRIBUTORS KNOWN_BUGS MAINTAINERS MANIFEST* NEWS PKG-INFO README* TODO"
250 lanius 1.20
251 arfrever 1.56 local doc
252 arfrever 1.62 for doc in ${default_docs}; do
253     [[ -s "${doc}" ]] && dodoc "${doc}"
254 lanius 1.20 done
255    
256 arfrever 1.62 if [[ -n "${DOCS}" ]]; then
257     dodoc ${DOCS} || die "dodoc failed"
258     fi
259 jnelson 1.1 }
260 kutsuya 1.6
261 arfrever 1.63 # @FUNCTION: distutils_pkg_postinst
262 dev-zero 1.46 # @DESCRIPTION:
263 arfrever 1.63 # This is a generic optimization, you should override it if your package
264     # installs modules in another directory. This function is exported.
265     distutils_pkg_postinst() {
266     if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
267     die "${FUNCNAME}() can be used only in pkg_postinst() phase"
268 arfrever 1.59 fi
269    
270 arfrever 1.56 local pylibdir pymod
271 hawking 1.54 if [[ -z "${PYTHON_MODNAME}" ]]; then
272     for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
273 arfrever 1.56 if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
274     PYTHON_MODNAME="${PN}"
275 hawking 1.54 fi
276     done
277 hawking 1.49 fi
278 liquidx 1.19
279 arfrever 1.63 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
280 arfrever 1.65 python_mod_optimize ${PYTHON_MODNAME}
281 arfrever 1.56 else
282 arfrever 1.63 for pymod in ${PYTHON_MODNAME}; do
283     python_mod_optimize "$(python_get_sitedir)/${pymod}"
284     done
285 swegener 1.28 fi
286 liquidx 1.19 }
287    
288 arfrever 1.63 # @FUNCTION: distutils_pkg_postrm
289 dev-zero 1.46 # @DESCRIPTION:
290 arfrever 1.63 # Generic pyc/pyo cleanup script. This function is exported.
291     distutils_pkg_postrm() {
292     if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
293     die "${FUNCNAME}() can be used only in pkg_postrm() phase"
294 arfrever 1.59 fi
295    
296 hawking 1.54 local pylibdir pymod
297     if [[ -z "${PYTHON_MODNAME}" ]]; then
298     for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
299 arfrever 1.56 if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
300     PYTHON_MODNAME="${PN}"
301 hawking 1.54 fi
302     done
303 hawking 1.50 fi
304 swegener 1.28
305 arfrever 1.63 if [[ -n "${PYTHON_MODNAME}" ]]; then
306 arfrever 1.65 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
307     python_mod_cleanup ${PYTHON_MODNAME}
308     else
309     for pymod in ${PYTHON_MODNAME}; do
310 arfrever 1.63 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
311     if [[ -d "${pylibdir}/site-packages/${pymod}" ]]; then
312     python_mod_cleanup "${pylibdir#${ROOT}}/site-packages/${pymod}"
313     fi
314     done
315 arfrever 1.65 done
316     fi
317 arfrever 1.56 else
318 arfrever 1.63 python_mod_cleanup
319 swegener 1.28 fi
320 liquidx 1.19 }
321    
322 dev-zero 1.46 # @FUNCTION: distutils_python_version
323     # @DESCRIPTION:
324     # Calls python_version, so that you can use something like
325 arfrever 1.67 # e.g. insinto ${ROOT}/usr/include/python${PYVER}
326 liquidx 1.13 distutils_python_version() {
327 arfrever 1.68 if ! has "${EAPI:-0}" 0 1 2; then
328     die "${FUNCNAME}() cannot be used in this EAPI"
329     fi
330    
331 liquidx 1.34 python_version
332 liquidx 1.12 }
333    
334 dev-zero 1.46 # @FUNCTION: distutils_python_tkinter
335     # @DESCRIPTION:
336     # Checks for if tkinter support is compiled into python
337 liquidx 1.12 distutils_python_tkinter() {
338 arfrever 1.68 if ! has "${EAPI:-0}" 0 1 2; then
339     die "${FUNCNAME}() cannot be used in this EAPI"
340     fi
341    
342 lucass 1.40 python_tkinter_exists
343 vapier 1.8 }

  ViewVC Help
Powered by ViewVC 1.1.20