/[gentoo-x86]/eclass/python-single-r1.eclass
Gentoo

Contents of /eclass/python-single-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Sat Dec 1 09:29:24 2012 UTC (19 months, 4 weeks ago) by mgorny
Branch: MAIN
Changes since 1.6: +3 -1 lines
Introduce python-any-r1, to handle packages satisfied by any Python implementation installed (e.g. strictly build-time dependent).

1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/python-single-r1.eclass,v 1.6 2012/11/30 22:57:26 mgorny Exp $
4
5 # @ECLASS: python-single-r1
6 # @MAINTAINER:
7 # Michał Górny <mgorny@gentoo.org>
8 # Python herd <python@gentoo.org>
9 # @AUTHOR:
10 # Author: Michał Górny <mgorny@gentoo.org>
11 # Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
12 # @BLURB: An eclass for Python packages not installed for multiple implementations.
13 # @DESCRIPTION:
14 # An extension of the python-r1 eclass suite for packages which
15 # don't support being installed for multiple Python implementations.
16 # This mostly includes tools embedding Python.
17 #
18 # This eclass extends the IUSE and REQUIRED_USE set by python-r1
19 # to request correct PYTHON_SINGLE_TARGET. It also replaces
20 # PYTHON_USEDEP and PYTHON_DEPS with a more suitable form.
21 #
22 # Please note that packages support multiple Python implementations
23 # (using python-r1 eclass) can not depend on packages not supporting
24 # them (using this eclass).
25 #
26 # Please note that python-single-r1 will always inherit python-utils-r1
27 # as well. Thus, all the functions defined there can be used
28 # in the packages using python-single-r1, and there is no need ever
29 # to inherit both.
30 #
31 # For more information, please see the python-r1 Developer's Guide:
32 # http://www.gentoo.org/proj/en/Python/python-r1/dev-guide.xml
33
34 case "${EAPI:-0}" in
35 0|1|2|3)
36 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
37 ;;
38 4|5)
39 # EAPI=4 needed by python-r1
40 ;;
41 *)
42 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
43 ;;
44 esac
45
46 if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
47
48 if [[ ${_PYTHON_R1} ]]; then
49 die 'python-single-r1.eclass can not be used with python-r1.eclass.'
50 elif [[ ${_PYTHON_ANY_R1} ]]; then
51 die 'python-single-r1.eclass can not be used with python-any-r1.eclass.'
52 fi
53
54 inherit python-utils-r1
55
56 fi
57
58 EXPORT_FUNCTIONS pkg_setup
59
60 if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
61
62 # @ECLASS-VARIABLE: PYTHON_COMPAT
63 # @REQUIRED
64 # @DESCRIPTION:
65 # This variable contains a list of Python implementations the package
66 # supports. It must be set before the `inherit' call. It has to be
67 # an array.
68 #
69 # Example:
70 # @CODE
71 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
72 # @CODE
73 if ! declare -p PYTHON_COMPAT &>/dev/null; then
74 die 'PYTHON_COMPAT not declared.'
75 fi
76
77 # @ECLASS-VARIABLE: PYTHON_REQ_USE
78 # @DEFAULT_UNSET
79 # @DESCRIPTION:
80 # The list of USEflags required to be enabled on the chosen Python
81 # implementations, formed as a USE-dependency string. It should be valid
82 # for all implementations in PYTHON_COMPAT, so it may be necessary to
83 # use USE defaults.
84 #
85 # Example:
86 # @CODE
87 # PYTHON_REQ_USE="gdbm,ncurses(-)?"
88 # @CODE
89 #
90 # It will cause the Python dependencies to look like:
91 # @CODE
92 # python_single_target_pythonX_Y? ( dev-lang/python:X.Y[gdbm,ncurses(-)?] )
93 # @CODE
94
95 # @ECLASS-VARIABLE: PYTHON_DEPS
96 # @DESCRIPTION:
97 # This is an eclass-generated Python dependency string for all
98 # implementations listed in PYTHON_COMPAT.
99 #
100 # The dependency string is conditional on PYTHON_SINGLE_TARGET.
101 #
102 # Example use:
103 # @CODE
104 # RDEPEND="${PYTHON_DEPS}
105 # dev-foo/mydep"
106 # DEPEND="${RDEPEND}"
107 # @CODE
108 #
109 # Example value:
110 # @CODE
111 # dev-python/python-exec
112 # python_single_target_python2_6? ( dev-lang/python:2.6[gdbm] )
113 # python_single_target_python2_7? ( dev-lang/python:2.7[gdbm] )
114 # @CODE
115
116 # @ECLASS-VARIABLE: PYTHON_USEDEP
117 # @DESCRIPTION:
118 # This is an eclass-generated USE-dependency string which can be used to
119 # depend on another Python package being built for the same Python
120 # implementations.
121 #
122 # The generate USE-flag list is compatible with packages using python-r1,
123 # python-single-r1 and python-distutils-ng eclasses. It must not be used
124 # on packages using python.eclass.
125 #
126 # Example use:
127 # @CODE
128 # RDEPEND="dev-python/foo[${PYTHON_USEDEP}]"
129 # @CODE
130 #
131 # Example value:
132 # @CODE
133 # python_targets_python2_7?,python_single_target_python2_7(+)?
134 # @CODE
135
136 _python_single_set_globals() {
137 local flags_mt=( "${PYTHON_COMPAT[@]/#/python_targets_}" )
138 local flags=( "${PYTHON_COMPAT[@]/#/python_single_target_}" )
139 local optflags=${flags_mt[@]/%/?}
140 optflags+=,${flags[@]/%/(+)?}
141
142 IUSE="${flags_mt[*]} ${flags[*]}"
143 REQUIRED_USE="|| ( ${flags_mt[*]} ) ^^ ( ${flags[*]} )"
144 PYTHON_USEDEP=${optflags// /,}
145
146 local usestr
147 [[ ${PYTHON_REQ_USE} ]] && usestr="[${PYTHON_REQ_USE}]"
148
149 # 1) well, python-exec would suffice as an RDEP
150 # but no point in making this overcomplex, BDEP doesn't hurt anyone
151 # 2) python-exec should be built with all targets forced anyway
152 # but if new targets were added, we may need to force a rebuild
153 PYTHON_DEPS="dev-python/python-exec[${PYTHON_USEDEP}]"
154 local i
155 for i in "${PYTHON_COMPAT[@]}"; do
156 # The chosen targets need to be in PYTHON_TARGETS as well.
157 # This is in order to enforce correct dependencies on packages
158 # supporting multiple implementations.
159 REQUIRED_USE+=" python_single_target_${i}? ( python_targets_${i} )"
160
161 local d
162 case ${i} in
163 python*)
164 d='dev-lang/python';;
165 jython*)
166 d='dev-java/jython';;
167 pypy*)
168 d='dev-python/pypy';;
169 *)
170 die "Invalid implementation: ${i}"
171 esac
172
173 local v=${i##*[a-z]}
174 PYTHON_DEPS+=" python_single_target_${i}? ( ${d}:${v/_/.}${usestr} )"
175 done
176 }
177 _python_single_set_globals
178
179 # @FUNCTION: python-single-r1_pkg_setup
180 # @DESCRIPTION:
181 # Determine what the selected Python implementation is and set EPYTHON
182 # and PYTHON accordingly.
183 python-single-r1_pkg_setup() {
184 debug-print-function ${FUNCNAME} "${@}"
185
186 local impl
187 for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
188 if has "${impl}" "${PYTHON_COMPAT[@]}" \
189 && use "python_single_target_${impl}"
190 then
191 python_export "${impl}" EPYTHON PYTHON
192 break
193 fi
194 done
195 }
196
197 _PYTHON_SINGLE_R1=1
198 fi

  ViewVC Help
Powered by ViewVC 1.1.20