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

Contents of /eclass/python-distutils-ng.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.32 - (hide annotations) (download)
Mon Nov 11 21:56:27 2013 UTC (8 months, 1 week ago) by mgorny
Branch: MAIN
CVS Tags: HEAD
Changes since 1.31: +1 -1 lines
FILE REMOVED
Remove the last rited eclass.

1 mgorny 1.30 # Copyright 1999-2013 Gentoo Foundation
2 nelchael 1.1 # Distributed under the terms of the GNU General Public License v2
3 mgorny 1.32 # $Header: /var/cvsroot/gentoo-x86/eclass/python-distutils-ng.eclass,v 1.31 2013/09/29 15:04:51 mgorny Exp $
4 mgorny 1.31
5     # @DEAD
6     # Michał Górny <mgorny@gentoo.org> (29 Sep 2013)
7     # This eclass has been superseded by distutils-r1 and python-r1 eclasses
8     # and will be removed on 2013-10-29. Please modify your ebuilds to use
9     # the new eclasses instead. Bug #450770.
10 nelchael 1.1
11     # @ECLASS: python-distutils-ng
12     # @MAINTAINER:
13     # Python herd <python@gentoo.org>
14     # @AUTHOR:
15     # Author: Krzysztof Pawlik <nelchael@gentoo.org>
16 floppym 1.19 # @BLURB: Install Python packages using distutils.
17 nelchael 1.1 # @DESCRIPTION:
18     # The Python eclass is designed to allow an easier installation of Python
19     # packages and their incorporation into the Gentoo Linux system.
20     #
21     # This eclass provides functions for following phases:
22     # - src_prepare - you can define python_prepare_all function that will be run
23     # before creating implementation-specific directory and python_prepare
24     # function that will be run for each implementation
25     # - src_configure - you can define python_configure function that will be run
26     # for each implementation
27     # - src_compile - you can define python_compile function that will be run for
28     # each implementation, default function will run `setup.py build'
29     # - src_test - you can define python_test function that will be run for each
30     # implementation
31     # - src_install - you can define python_install function that will be run for
32     # each implementation and python_install_all that will be run in original
33 nelchael 1.9 # directory (so it will not contain any implementation-specific files)
34 nelchael 1.1
35     # @ECLASS-VARIABLE: PYTHON_COMPAT
36 floppym 1.19 # @DEFAULT_UNSET
37 nelchael 1.1 # @DESCRIPTION:
38     # This variable contains a space separated list of implementations (see above) a
39     # package is compatible to. It must be set before the `inherit' call. The
40     # default is to enable all implementations.
41    
42     if [[ -z "${PYTHON_COMPAT}" ]]; then
43     # Default: pure python, support all implementations
44     PYTHON_COMPAT=" python2_5 python2_6 python2_7"
45     PYTHON_COMPAT+=" python3_1 python3_2"
46     PYTHON_COMPAT+=" jython2_5"
47 floppym 1.26 PYTHON_COMPAT+=" pypy1_8 pypy1_9"
48 nelchael 1.1 fi
49    
50     # @ECLASS-VARIABLE: PYTHON_OPTIONAL
51 floppym 1.19 # @DEFAULT_UNSET
52 nelchael 1.1 # @DESCRIPTION:
53     # Set the value to "yes" to make the dependency on a Python interpreter
54     # optional.
55    
56     # @ECLASS-VARIABLE: PYTHON_DISABLE_COMPILATION
57 floppym 1.19 # @DEFAULT_UNSET
58 nelchael 1.1 # @DESCRIPTION:
59     # Set the value to "yes" to skip compilation and/or optimization of Python
60     # modules.
61    
62 nelchael 1.22 # @ECLASS-VARIABLE: PYTHON_DISABLE_SCRIPT_REDOS
63     # @DEFAULT_UNSET
64     # @DESCRIPTION:
65     # Set to any value to disable automatic reinstallation of scripts in bin
66     # directories. See python-distutils-ng_src_install function.
67    
68 hasufell 1.27 # @ECLASS-VARIABLE: PYTHON_USE
69     # @DEFAULT_UNSET
70     # @DESCRIPTION:
71     # Comma-separated list of useflags needed for all(!) allowed
72     # implementations. This is directly substituted into one or more of
73     # dev-lang/python[${PYTHON_USE}], dev-python/pypy[${PYTHON_USE}] and
74     # dev-java/jython[${PYTHON_USE}].
75     # @CODE
76     # example 1: PYTHON_USE="xml,sqlite"
77     # example 2: PYTHON_USE="xml?,threads?,-foo"
78     # @CODE
79    
80 floppym 1.24 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
81 nelchael 1.1
82     case "${EAPI}" in
83     0|1|2|3)
84     die "Unsupported EAPI=${EAPI} (too old) for python-distutils-ng.eclass" ;;
85 axs 1.28 4|5)
86 nelchael 1.1 # EAPI=4 needed for REQUIRED_USE
87     S="${S:-${WORKDIR}/${P}}"
88     ;;
89     *)
90     die "Unsupported EAPI=${EAPI} (unknown) for python-distutils-ng.eclass" ;;
91     esac
92    
93 nelchael 1.20 DEPEND="${DEPEND} !<sys-apps/portage-2.1.10.58"
94    
95 nelchael 1.1 # @FUNCTION: _python-distutils-ng_get_binary_for_implementation
96     # @USAGE: implementation
97     # @RETURN: Full path to Python binary for given implementation.
98     # @DESCRIPTION:
99     # This function returns full path for Python binary for given implementation.
100     #
101     # Binary returned by this function should be used instead of simply calling
102     # `python'.
103     _python-distutils-ng_get_binary_for_implementation() {
104     local impl="${1/_/.}"
105     case "${impl}" in
106     python?.?|jython?.?)
107 mgorny 1.29 echo "${EPREFIX}/usr/bin/${impl}" ;;
108 nelchael 1.1 pypy?.?)
109 mgorny 1.29 echo "${EPREFIX}/usr/bin/pypy-c${impl: -3}" ;;
110 nelchael 1.1 *)
111     die "Unsupported implementation: ${1}" ;;
112     esac
113     }
114    
115 nelchael 1.3 required_use_str=""
116     for impl in ${PYTHON_COMPAT}; do
117 nelchael 1.4 required_use_str+=" python_targets_${impl}"
118 nelchael 1.3 done
119     required_use_str=" || ( ${required_use_str} )"
120 nelchael 1.1 if [[ "${PYTHON_OPTIONAL}" = "yes" ]]; then
121 nelchael 1.4 IUSE+=" python"
122 nelchael 1.1 REQUIRED_USE+=" python? ( ${required_use_str} )"
123     else
124 jlec 1.2 REQUIRED_USE+=" ${required_use_str}"
125 nelchael 1.1 fi
126 nelchael 1.4 unset required_use_str
127 nelchael 1.1
128 hasufell 1.27 # avoid empty use deps
129     _PYTHON_USE="${PYTHON_USE:+[${PYTHON_USE}]}"
130    
131     # set python DEPEND and RDEPEND
132 nelchael 1.1 for impl in ${PYTHON_COMPAT}; do
133 nelchael 1.4 IUSE+=" python_targets_${impl}"
134 nelchael 1.6 dep_str="${impl/_/.}"
135     case "${dep_str}" in
136     python?.?)
137 hasufell 1.27 dep_str="dev-lang/python:${dep_str: -3}${_PYTHON_USE}" ;;
138 nelchael 1.6 jython?.?)
139 hasufell 1.27 dep_str="dev-java/jython:${dep_str: -3}${_PYTHON_USE}" ;;
140 nelchael 1.6 pypy?.?)
141 mgorny 1.30 dep_str="virtual/pypy:${dep_str: -3}${_PYTHON_USE}" ;;
142 nelchael 1.6 *)
143     die "Unsupported implementation: ${impl}" ;;
144     esac
145     dep_str="python_targets_${impl}? ( ${dep_str} )"
146 nelchael 1.1
147     if [[ "${PYTHON_OPTIONAL}" = "yes" ]]; then
148     RDEPEND="${RDEPEND} python? ( ${dep_str} )"
149     DEPEND="${DEPEND} python? ( ${dep_str} )"
150     else
151     RDEPEND="${RDEPEND} ${dep_str}"
152     DEPEND="${DEPEND} ${dep_str}"
153     fi
154 nelchael 1.4 unset dep_str
155 nelchael 1.1 done
156    
157     _PACKAGE_SPECIFIC_S="${S#${WORKDIR}/}"
158    
159     # @FUNCTION: _python-distutils-ng_run_for_impl
160     # @USAGE: implementation command_to_run
161     # @DESCRIPTION:
162     # Run command_to_run using specified Python implementation.
163     #
164     # This will run the command_to_run in implementation-specific working directory.
165     _python-distutils-ng_run_for_impl() {
166     local impl="${1}"
167     local command="${2}"
168    
169 floppym 1.15 local S="${WORKDIR}/impl_${impl}/${_PACKAGE_SPECIFIC_S}"
170 nelchael 1.1 PYTHON="$(_python-distutils-ng_get_binary_for_implementation "${impl}")"
171     EPYTHON="${impl/_/.}"
172    
173     einfo "Running ${command} in ${S} for ${impl}"
174    
175     pushd "${S}" &> /dev/null
176     "${command}" "${impl}" "${PYTHON}"
177     popd &> /dev/null
178     }
179    
180     # @FUNCTION: _python-distutils-ng_run_for_each_impl
181     # @USAGE: command_to_run
182     # @DESCRIPTION:
183     # Run command_to_run for all enabled Python implementations.
184     #
185     # See also _python-distutils-ng_run_for_impl
186     _python-distutils-ng_run_for_each_impl() {
187     local command="${1}"
188    
189     for impl in ${PYTHON_COMPAT}; do
190     use "python_targets_${impl}" ${PYTHON_COMPAT} || continue
191     _python-distutils-ng_run_for_impl "${impl}" "${command}"
192     done
193     }
194    
195     # @FUNCTION: _python-distutils-ng_default_distutils_compile
196     # @DESCRIPTION:
197     # Default src_compile for distutils-based packages.
198     _python-distutils-ng_default_distutils_compile() {
199     "${PYTHON}" setup.py build || die
200     }
201    
202     # @FUNCTION: _python-distutils-ng_default_distutils_install
203     # @DESCRIPTION:
204     # Default src_install for distutils-based packages.
205     _python-distutils-ng_default_distutils_install() {
206 nelchael 1.16 local compile_flags="--compile -O2"
207 nelchael 1.1
208     case "${1}" in
209 nelchael 1.16 jython*)
210     # Jython does not support optimizations
211     compile_flags="--compile" ;;
212 nelchael 1.1 esac
213    
214 nelchael 1.16 unset PYTHONDONTWRITEBYTECODE
215     [[ -n "${PYTHON_DISABLE_COMPILATION}" ]] && compile_flags="--no-compile"
216 floppym 1.17 "${PYTHON}" setup.py install ${compile_flags} --root="${D}" || die
217 nelchael 1.1 }
218    
219 mgorny 1.25 # @FUNCTION: python-distutils-ng_rewrite_hashbang
220     # @USAGE: script_file_name implementation
221     # @DESCRIPTION:
222     # Rewrite #! line in named script, dies if #! line is not for Python or missing.
223     python-distutils-ng_rewrite_hashbang() {
224     [[ -n "${1}" ]] || die "Missing file name"
225     [[ -n "${2}" ]] || die "Missing implementation"
226     local file_name="${1}"
227     local binary="$(_python-distutils-ng_get_binary_for_implementation "${2}")"
228     [[ $(head -n 1 "${file_name}") == '#!'*(python|jython|pypy-c)* ]] || \
229     die "Missing or invalid #! line in ${file_name}"
230     sed -i -e "1c#!${binary}" "${file_name}" || die
231     }
232    
233 nelchael 1.11 # @FUNCTION: python-distutils-ng_redoscript
234     # @USAGE: script_file_path [destination_directory]
235     # @DESCRIPTION:
236     # Reinstall script installed already by setup.py. This works by first moving the
237     # script to ${T} directory and later running python-distutils-ng_doscript on it.
238     # script_file_path has to be a full path relative to ${D}.
239 nelchael 1.23 # Warning: this function can be run automatically by the eclass in src_install,
240     # see python-distutils-ng_src_install and PYTHON_DISABLE_SCRIPT_REDOS variable.
241 nelchael 1.11 python-distutils-ng_redoscript() {
242     local sbn="$(basename "${1}")"
243     mkdir -p "${T}/_${sbn}/" || die "failed to create directory"
244 floppym 1.18 mv "${D}${1}" "${T}/_${sbn}/${sbn}" || die "failed to move file"
245 nelchael 1.11 python-distutils-ng_doscript "${T}/_${sbn}/${sbn}" "${2}"
246     }
247    
248 nelchael 1.1 # @FUNCTION: python-distutils-ng_doscript
249     # @USAGE: script_file_name [destination_directory]
250     # @DESCRIPTION:
251     # Install given script file in destination directory (for default value check
252     # python-distutils-ng_newscript) for all enabled implementations using original
253     # script name as a base name.
254     #
255     # See also python-distutils-ng_newscript for more details.
256     python-distutils-ng_doscript() {
257     python-distutils-ng_newscript "${1}" "$(basename "${1}")" "${2}"
258     }
259    
260     # @FUNCTION: python-distutils-ng_newscript
261     # @USAGE: script_file_name new_file_name [destination_directory]
262     # @DESCRIPTION:
263     # Install given script file in destination directory for all enabled
264     # implementations using new_file_name as a base name.
265     #
266     # Destination directory defaults to /usr/bin.
267     #
268     # If only one Python implementation is enabled the script will be installed
269     # as-is. Otherwise each script copy will have the name mangled to
270     # "new_file_name-IMPLEMENTATION". For every installed script new hash-bang line
271     # will be inserted to reference specific Python interpreter.
272     #
273     # In case of multiple implementations there will be also a symlink with name
274     # equal to new_file_name that will be a symlink to default implementation, which
275     # defaults to value of PYTHON_DEFAULT_IMPLEMENTATION, if not specified the
276     # function will pick default implementation: it will the be first enabled one
277     # from the following list:
278     # python2_7, python2_6, python2_5, python3_2, python3_1, pypy1_8, pypy1_7, jython2_5
279     python-distutils-ng_newscript() {
280     [[ -n "${1}" ]] || die "Missing source file name"
281     [[ -n "${2}" ]] || die "Missing destination file name"
282     local source_file="${1}"
283     local destination_file="${2}"
284     local default_impl="${PYTHON_DEFAULT_IMPLEMENTATION}"
285     local enabled_impls=0
286     local destination_directory="/usr/bin"
287     [[ -n "${3}" ]] && destination_directory="${3}"
288    
289     for impl in ${PYTHON_COMPAT}; do
290     use "python_targets_${impl}" || continue
291     enabled_impls=$((enabled_impls + 1))
292     done
293    
294     if [[ -z "${default_impl}" ]]; then
295 floppym 1.26 for impl in python{2_7,2_6,2_5,3_2,3_1} pypy{1_9,1_8,1_7} jython2_5; do
296 nelchael 1.1 use "python_targets_${impl}" || continue
297     default_impl="${impl}"
298     break
299     done
300     else
301 nelchael 1.9 use "python_targets_${default_impl}" || \
302 nelchael 1.1 die "default implementation ${default_impl} not enabled"
303     fi
304    
305     [[ -n "${default_impl}" ]] || die "Could not select default implementation"
306    
307     dodir "${destination_directory}"
308     insinto "${destination_directory}"
309     if [[ "${enabled_impls}" = "1" ]]; then
310     einfo "Installing ${source_file} for single implementation (${default_impl}) in ${destination_directory}"
311     newins "${source_file}" "${destination_file}"
312     fperms 755 "${destination_directory}/${destination_file}"
313 mgorny 1.25 python-distutils-ng_rewrite_hashbang "${D}${destination_directory}/${destination_file}" "${default_impl}"
314 nelchael 1.1 else
315     einfo "Installing ${source_file} for multiple implementations (default: ${default_impl}) in ${destination_directory}"
316     for impl in ${PYTHON_COMPAT}; do
317     use "python_targets_${impl}" ${PYTHON_COMPAT} || continue
318    
319     newins "${source_file}" "${destination_file}-${impl}"
320     fperms 755 "${destination_directory}/${destination_file}-${impl}"
321 mgorny 1.25 python-distutils-ng_rewrite_hashbang "${D}${destination_directory}/${destination_file}-${impl}" "${impl}"
322 nelchael 1.1 done
323    
324     dosym "${destination_file}-${default_impl}" "${destination_directory}/${destination_file}"
325     fi
326     }
327    
328     # Phase function: src_prepare
329     python-distutils-ng_src_prepare() {
330     [[ "${PYTHON_OPTIONAL}" = "yes" ]] && { use python || return; }
331    
332     # Try to run binary for each implementation:
333     for impl in ${PYTHON_COMPAT}; do
334     use "python_targets_${impl}" ${PYTHON_COMPAT} || continue
335     $(_python-distutils-ng_get_binary_for_implementation "${impl}") \
336     -c "import sys" || die
337     done
338    
339     # Run prepare shared by all implementations:
340     if type python_prepare_all &> /dev/null; then
341     einfo "Running python_prepare_all in ${S} for all"
342     python_prepare_all
343     fi
344    
345     # Create a copy of S for each implementation:
346     for impl in ${PYTHON_COMPAT}; do
347     use "python_targets_${impl}" ${PYTHON_COMPAT} || continue
348    
349     einfo "Creating copy for ${impl} in ${WORKDIR}/impl_${impl}"
350     mkdir -p "${WORKDIR}/impl_${impl}" || die
351     cp -pr "${S}" "${WORKDIR}/impl_${impl}/${_PACKAGE_SPECIFIC_S}" || die
352     done
353    
354     # Run python_prepare for each implementation:
355     if type python_prepare &> /dev/null; then
356     _python-distutils-ng_run_for_each_impl python_prepare
357     fi
358     }
359    
360     # Phase function: src_configure
361     python-distutils-ng_src_configure() {
362     [[ "${PYTHON_OPTIONAL}" = "yes" ]] && { use python || return; }
363    
364     if type python_configure &> /dev/null; then
365     _python-distutils-ng_run_for_each_impl python_configure
366     fi
367     }
368    
369     # Phase function: src_compile
370     python-distutils-ng_src_compile() {
371     [[ "${PYTHON_OPTIONAL}" = "yes" ]] && { use python || return; }
372    
373     if type python_compile &> /dev/null; then
374     _python-distutils-ng_run_for_each_impl python_compile
375     else
376     _python-distutils-ng_run_for_each_impl \
377     _python-distutils-ng_default_distutils_compile
378     fi
379     }
380    
381     # Phase function: src_test
382     python-distutils-ng_src_test() {
383     [[ "${PYTHON_OPTIONAL}" = "yes" ]] && { use python || return; }
384    
385     if type python_test &> /dev/null; then
386     _python-distutils-ng_run_for_each_impl python_test
387     fi
388     }
389    
390     # Phase function: src_install
391     python-distutils-ng_src_install() {
392     [[ "${PYTHON_OPTIONAL}" = "yes" ]] && { use python || return; }
393    
394     if type python_install &> /dev/null; then
395     _python-distutils-ng_run_for_each_impl python_install
396     else
397     _python-distutils-ng_run_for_each_impl \
398     _python-distutils-ng_default_distutils_install
399     fi
400    
401     if type python_install_all &> /dev/null; then
402     einfo "Running python_install_all in ${S} for all"
403 nelchael 1.12 pushd "${S}" &> /dev/null
404 nelchael 1.1 python_install_all
405 nelchael 1.12 popd &> /dev/null
406 nelchael 1.1 fi
407 nelchael 1.21
408     if [[ -z "${PYTHON_DISABLE_SCRIPT_REDOS}" ]]; then
409 mgorny 1.29 for script_file in $(find "${ED}"{,usr/}{,s}bin/ -type f -executable 2> /dev/null); do
410 nelchael 1.21 python-distutils-ng_redoscript "/${script_file#${D}}"
411     done
412     fi
413 nelchael 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.20