Gentoo Archives: gentoo-python

From: "Michał Górny" <mgorny@g.o>
To: gentoo-python@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-python] [PATCH] Create a temporary links for Python execs and pkg-config.
Date: Fri, 29 Mar 2013 22:38:43
Message-Id: 1364596770-17336-1-git-send-email-mgorny@gentoo.org
In Reply to: Re: [gentoo-python] Alternate solution for 'python', 'python2' and 'pkg-config python' in ebuilds by "Michał Górny"
1 With this patch, all apps which call 'python', 'python2', 'python3',
2 '2to3', 'python-config' or 'pkg-config ... python' start to work
3 properly without any kind of wrapper.
4
5 The wrappers are set up in python_foreach_impl, python_export_best
6 and pkg_setup phases of python-any-r1 and python-single-r1.
7
8 python_foreach_impl uses ${T}/${EPYTHON} subdirs for the wrappers.
9 The remaining functions set them 'globally' in ${T}.
10 ---
11 gx86/eclass/python-any-r1.eclass | 5 +-
12 gx86/eclass/python-r1.eclass | 3 ++
13 gx86/eclass/python-single-r1.eclass | 1 +
14 gx86/eclass/python-utils-r1.eclass | 94 +++++++++++++++++++++++++++++++++++++
15 4 files changed, 102 insertions(+), 1 deletion(-)
16
17 diff --git a/gx86/eclass/python-any-r1.eclass b/gx86/eclass/python-any-r1.eclass
18 index 5d9a3d1..4761221 100644
19 --- a/gx86/eclass/python-any-r1.eclass
20 +++ b/gx86/eclass/python-any-r1.eclass
21 @@ -205,7 +205,10 @@ python-any-r1_pkg_setup() {
22 local PYTHON_PKG_DEP
23 for i in "${rev_impls[@]}"; do
24 python_export "${i}" PYTHON_PKG_DEP EPYTHON PYTHON
25 - ROOT=/ has_version "${PYTHON_PKG_DEP}" && return
26 + if ROOT=/ has_version "${PYTHON_PKG_DEP}"; then
27 + python_wrapper_setup "${T}"
28 + return
29 + fi
30 done
31 }
32
33 diff --git a/gx86/eclass/python-r1.eclass b/gx86/eclass/python-r1.eclass
34 index 4ba80a9..a3fdd0e 100644
35 --- a/gx86/eclass/python-r1.eclass
36 +++ b/gx86/eclass/python-r1.eclass
37 @@ -634,7 +634,9 @@ _python_multibuild_wrapper() {
38 debug-print-function ${FUNCNAME} "${@}"
39
40 local -x EPYTHON PYTHON
41 + local -x PATH=${PATH} PKG_CONFIG_PATH=${PKG_CONFIG_PATH}
42 python_export "${MULTIBUILD_VARIANT}" EPYTHON PYTHON
43 + python_wrapper_setup "${T}/${EPYTHON}"
44
45 "${@}"
46 }
47 @@ -707,6 +709,7 @@ python_export_best() {
48
49 debug-print "${FUNCNAME}: Best implementation is: ${best}"
50 python_export "${best}" "${@}"
51 + python_wrapper_setup "${T}"
52 }
53
54 # @FUNCTION: python_replicate_script
55 diff --git a/gx86/eclass/python-single-r1.eclass b/gx86/eclass/python-single-r1.eclass
56 index 6235b66..950bf52 100644
57 --- a/gx86/eclass/python-single-r1.eclass
58 +++ b/gx86/eclass/python-single-r1.eclass
59 @@ -207,6 +207,7 @@ python-single-r1_pkg_setup() {
60 fi
61
62 python_export "${impl}" EPYTHON PYTHON
63 + python_wrapper_setup "${T}"
64 fi
65 done
66
67 diff --git a/gx86/eclass/python-utils-r1.eclass b/gx86/eclass/python-utils-r1.eclass
68 index a375546..6aa4a64 100644
69 --- a/gx86/eclass/python-utils-r1.eclass
70 +++ b/gx86/eclass/python-utils-r1.eclass
71 @@ -818,5 +818,99 @@ python_doheader() {
72 doins -r "${@}" || die
73 }
74
75 +# @FUNCTION: python_wrapper_setup
76 +# @USAGE: <path> [<impl>]
77 +# @DESCRIPTION:
78 +# Create proper 'python' executable and pkg-config wrappers
79 +# (if available) in the directory named by <path>. Set up PATH
80 +# and PKG_CONFIG_PATH appropriately.
81 +#
82 +# The wrappers will be created for implementation named by <impl>,
83 +# or for one named by ${EPYTHON} if no <impl> passed.
84 +#
85 +# If the named directory contains a python symlink already, it will
86 +# be assumed to contain proper wrappers already and only environment
87 +# setup will be done. If wrapper update is requested, the directory
88 +# shall be removed first.
89 +python_wrapper_setup() {
90 + debug-print-function ${FUNCNAME} "${@}"
91 +
92 + local workdir=${1}
93 + local impl=${2:-${EPYTHON}}
94 +
95 + [[ ${workdir} ]] || die "${FUNCNAME}: no workdir specified."
96 + [[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON specified."
97 +
98 + if [[ ! -x ${workdir}/bin/python ]]; then
99 + mkdir -p "${workdir}"/{bin,pkgconfig} || die
100 +
101 + # Clean up, in case we were supposed to do a cheap update.
102 + rm -f "${workdir}"/bin/python{,2,3,-config}
103 + rm -f "${workdir}"/bin/2to3
104 + rm -f "${workdir}"/pkgconfig/python{,2,3}.pc
105 +
106 + local EPYTHON PYTHON
107 + python_export "${impl}" EPYTHON PYTHON
108 +
109 + local pyver
110 + if [[ ${EPYTHON} == python3* ]]; then
111 + pyver=3
112 + else # includes pypy & jython
113 + pyver=2
114 + fi
115 +
116 + # Python interpreter
117 + ln -s "${PYTHON}" "${workdir}"/bin/python || die
118 + ln -s python "${workdir}"/bin/python${pyver} || die
119 +
120 + local nonsupp=()
121 +
122 + # CPython-specific
123 + if [[ ${EPYTHON} == python* ]]; then
124 + ln -s "${PYTHON}-config" "${workdir}"/bin/python-config || die
125 +
126 + # Python 2.6+.
127 + if [[ ${EPYTHON} != python2.5 ]]; then
128 + ln -s "${PYTHON/python/2to3-}" "${workdir}"/bin/2to3 || die
129 + else
130 + nonsupp+=( 2to3 )
131 + fi
132 +
133 + # Python 2.7+.
134 + if [[ ${EPYTHON} != python2.[56] ]]; then
135 + ln -s "${EPREFIX}"/usr/$(get_libdir)/pkgconfig/${EPYTHON/n/n-}.pc \
136 + "${workdir}"/pkgconfig/python.pc || die
137 + else
138 + # XXX?
139 + ln -s /dev/null "${workdir}"/pkgconfig/python.pc || die
140 + fi
141 + ln -s python.pc "${workdir}"/pkgconfig/python${pyver}.pc || die
142 + else
143 + nonsupp+=( 2to3 python-config )
144 + fi
145 +
146 + local x
147 + for x in "${nonsupp[@]}"; do
148 + echo >"${workdir}"/bin/${x} <<__EOF__ || die
149 +#!/bin/sh
150 +echo "${x} is not supported by ${EPYTHON}" >&2
151 +exit 1
152 +__EOF__
153 + chmod +x "${workdir}"/bin/${x} || die
154 + done
155 +
156 + # Now, set the environment.
157 + # But note that ${workdir} may be shared with something else,
158 + # and thus already on top of PATH.
159 + if [[ ${PATH##:*} != ${workdir}/bin ]]; then
160 + PATH=${workdir}/bin${PATH:+:${PATH}}
161 + fi
162 + if [[ ${PKG_CONFIG_PATH##:*} != ${workdir}/pkgconfig ]]; then
163 + PKG_CONFIG_PATH=${workdir}/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
164 + fi
165 + export PATH PKG_CONFIG_PATH
166 + fi
167 +}
168 +
169 _PYTHON_UTILS_R1=1
170 fi
171 --
172 1.8.1.5

Replies