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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Sat Dec 1 09:29:24 2012 UTC (2 years ago) by mgorny
Branch: MAIN
Introduce python-any-r1, to handle packages satisfied by any Python implementation installed (e.g. strictly build-time dependent).

1 mgorny 1.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.4 2012/11/26 10:05:11 mgorny Exp $
4    
5     # @ECLASS: python-any-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 packages having build-time dependency on Python.
13     # @DESCRIPTION:
14     # A minimal eclass for packages which need any Python interpreter
15     # installed without a need for explicit choice and invariability.
16     # This usually involves packages requiring Python at build-time
17     # but having no other relevance to it.
18     #
19     # This eclass provides a minimal PYTHON_DEPS variable with a dependency
20     # string on any of the supported Python implementations. It also exports
21     # pkg_setup() which finds the best supported implementation and sets it
22     # as the active one.
23     #
24     # Please note that python-any-r1 will always inherit python-utils-r1
25     # as well. Thus, all the functions defined there can be used in the
26     # packages using python-any-r1, and there is no need ever to inherit
27     # both.
28     #
29     # For more information, please see the python-r1 Developer's Guide:
30     # http://www.gentoo.org/proj/en/Python/python-r1/dev-guide.xml
31    
32     case "${EAPI:-0}" in
33     0|1|2|3|4|5)
34     # EAPI=4 needed by python-r1
35     ;;
36     *)
37     die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
38     ;;
39     esac
40    
41     if [[ ! ${_PYTHON_ANY_R1} ]]; then
42    
43     if [[ ${_PYTHON_R1} ]]; then
44     die 'python-any-r1.eclass can not be used with python-r1.eclass.'
45     elif [[ ${_PYTHON_SINGLE_R1} ]]; then
46     die 'python-any-r1.eclass can not be used with python-single-r1.eclass.'
47     fi
48    
49     inherit python-utils-r1
50    
51     fi
52    
53     EXPORT_FUNCTIONS pkg_setup
54    
55     if [[ ! ${_PYTHON_ANY_R1} ]]; then
56    
57     # @ECLASS-VARIABLE: PYTHON_COMPAT
58     # @REQUIRED
59     # @DESCRIPTION:
60     # This variable contains a list of Python implementations the package
61     # supports. It must be set before the `inherit' call. It has to be
62     # an array.
63     #
64     # Example:
65     # @CODE
66     # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
67     # @CODE
68     if ! declare -p PYTHON_COMPAT &>/dev/null; then
69     die 'PYTHON_COMPAT not declared.'
70     fi
71    
72     # @ECLASS-VARIABLE: PYTHON_REQ_USE
73     # @DEFAULT_UNSET
74     # @DESCRIPTION:
75     # The list of USEflags required to be enabled on the Python
76     # implementations, formed as a USE-dependency string. It should be valid
77     # for all implementations in PYTHON_COMPAT, so it may be necessary to
78     # use USE defaults.
79     #
80     # Example:
81     # @CODE
82     # PYTHON_REQ_USE="gdbm,ncurses(-)?"
83     # @CODE
84     #
85     # It will cause the Python dependencies to look like:
86     # @CODE
87     # || ( dev-lang/python:X.Y[gdbm,ncurses(-)?] ... )
88     # @CODE
89    
90     # @ECLASS-VARIABLE: PYTHON_DEPS
91     # @DESCRIPTION:
92     # This is an eclass-generated Python dependency string for all
93     # implementations listed in PYTHON_COMPAT.
94     #
95     # Any of the supported interpreters will satisfy the dependency.
96     #
97     # Example use:
98     # @CODE
99     # DEPEND="${RDEPEND}
100     # ${PYTHON_DEPS}"
101     # @CODE
102     #
103     # Example value:
104     # @CODE
105     # || ( dev-lang/python:2.7[gdbm]
106     # dev-lang/python:2.6[gdbm] )
107     # @CODE
108    
109     _python_build_set_globals() {
110     local usestr
111     [[ ${PYTHON_REQ_USE} ]] && usestr="[${PYTHON_REQ_USE}]"
112    
113     PYTHON_DEPS=
114     local i
115     for i in "${_PYTHON_ALL_IMPLS[@]}"; do
116     if has "${i}" "${PYTHON_COMPAT[@]}"
117     then
118     local d
119     case ${i} in
120     python*)
121     d='dev-lang/python';;
122     jython*)
123     d='dev-java/jython';;
124     pypy*)
125     d='dev-python/pypy';;
126     *)
127     die "Invalid implementation: ${i}"
128     esac
129    
130     local v=${i##*[a-z]}
131     PYTHON_DEPS="${d}:${v/_/.}${usestr} ${PYTHON_DEPS}"
132     fi
133     done
134     PYTHON_DEPS="|| ( ${PYTHON_DEPS})"
135     }
136     _python_build_set_globals
137    
138     # @FUNCTION: python-any-r1_pkg_setup
139     # @DESCRIPTION:
140     # Determine what the best installed (and supported) Python
141     # implementation is and set EPYTHON and PYTHON accordingly.
142     python-any-r1_pkg_setup() {
143     debug-print-function ${FUNCNAME} "${@}"
144    
145     local i rev_impls=()
146     for i in "${_PYTHON_ALL_IMPLS[@]}"; do
147     if has "${i}" "${PYTHON_COMPAT[@]}"; then
148     rev_impls=( "${i}" "${rev_impls[@]}" )
149     fi
150     done
151    
152     for i in "${rev_impls[@]}"; do
153     local d
154     case "${i}" in
155     python*)
156     d='dev-lang/python';;
157     jython*)
158     d='dev-java/jython';;
159     pypy*)
160     d='dev-python/pypy';;
161     *)
162     die "Invalid implementation: ${i}"
163     esac
164     local v=${i##*[a-z]}
165    
166     if has_version "${d}:${v/_/.}${usestr}"; then
167     python_export "${i}" EPYTHON PYTHON
168     break
169     fi
170     done
171     }
172    
173     _PYTHON_ANY_R1=1
174     fi

  ViewVC Help
Powered by ViewVC 1.1.20