1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
diff -ur eselect-python-20111108.orig/python.eselect eselect-python-20111108/python.eselect
--- python.eselect 2011-11-09 07:15:22.000000000 +0800
+++ python.eselect 2012-06-25 21:48:00.142723058 +0800
@@ -1,4 +1,4 @@
-# Copyright 1999-2010 Gentoo Foundation
+7# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: $
@@ -15,9 +15,11 @@
# Find a list of Python versions
find_targets() {
- local interpreter interpreters="python?.?"
+ local interpreter interpreters="python?.?" pypyinterpreters="pypy-c1.?"
- if [[ "${PYTHON_INTERPRETERS_GROUP}" == "2" ]]; then
+ if [[ "${PYTHON_INTERPRETERS_GROUP}" == "1" ]]; then
+ interpreters="pypy-c1.?"
+ elif [[ "${PYTHON_INTERPRETERS_GROUP}" == "2" ]]; then
interpreters="python2.?"
elif [[ "${PYTHON_INTERPRETERS_GROUP}" == "3" ]]; then
interpreters="python3.?"
@@ -25,8 +27,8 @@
# Think twice before adding jython to this list. /usr/bin/jython
# is a bash wrapper that calls java-config, which is a Python
- # script, so you need a valid /usr/bin/python to start jython.
- for interpreter in "${INTERPRETER_PATH}"${interpreters}; do
+ # script, so you need a valid /usr/bin/python to start jython. Adding pypy
+ for interpreter in "${INTERPRETER_PATH}"${interpreters} "${INTERPRETER_PATH}"${pypyinterpreters}; do
if [[ -f "${interpreter}" ]]; then
echo ${interpreter#${INTERPRETER_PATH}}
fi
@@ -40,8 +42,9 @@
}
set_python_config() {
- local script="${INTERPRETER_PATH}python-config" target="${1}"
- cat << EOF > "${script}"
+ local script="${INTERPRETER_PATH}python-config" pyscript=${INTERPRETER_PATH}pypy-config target="${1}"
+ if [[ "${target:0:6}" == "python" ]]; then
+ cat << EOF > "${script}"
#!/usr/bin/env bash
# Gentoo python-config wrapper script
@@ -49,18 +52,31 @@
python_config="\${EPYTHON/python/python-config-}"
"\${0%/*}/\${python_config:-${target}}" "\$@"
EOF
- chmod a+rx "${script}"
+ chmod a+rx "${script}"
+ elif [[ "${target:0:6}" == "pypy-c" ]]; then
+ cat << EOF > "${pyscript}"
+#!/usr/bin/env bash
+# Gentoo python-config wrapper script
+
+[[ "\${EPYTHON}" =~ (/|^python\$) ]] && EPYTHON="${target/-config-/}"
+python_config="\${EPYTHON/python/python-config-}"
+"\${0%/*}/\${python_config:-${target}}" "\$@"
+EOF
+ chmod a+rx "${pyscript}"
+ fi
+ # We always need a "${script}"
+ ln -s "${pyscript}" "${script}"
}
# Try to remove python and python.1 symlinks
remove_symlinks() {
local symlink symlink_target symlink_target_found
if [[ "${SET_MAIN_ACTIVE_PYTHON_INTERPRETER}" == "1" ]]; then
- rm -f "${INTERPRETER_PATH}"{idle,pydoc,python,python-config,pythonw} &> /dev/null || return 1
+ rm -f "${INTERPRETER_PATH}"{idle,pydoc,python,pypy,python-config,pythonw} &> /dev/null || return 1
rm -f "${MAN_PATH}"python.1{,.gz,.bz2,.lzma,.xz} &> /dev/null || return 1
fi
- for symlink in "${INTERPRETER_PATH}python"?; do
+ for symlink in "${INTERPRETER_PATH}python"? "${INTERPRETER_PATH}pypy-c"?; do
[[ ! -L "${symlink}" ]] && continue
symlink_target_found=0
for symlink_target in "${symlink}".?; do
@@ -75,7 +91,7 @@
rm -f "${INTERPRETER_PATH%/bin/}/lib/Python.framework}"/{Headers,Python,Resources}
}
-# Set a man page symlink
+# Set a man page symlink; pypy apparently does not come with man pages
set_man_symlink() {
local target="${1}" x extension
@@ -86,13 +102,15 @@
fi
done
- if [[ -z "${extension}" ]]; then
+ if [[ -z "${extension}" && "${target:0:4}" != "pypy" ]]; then
echo "Couldn't find a man page for ${target}; skipping." 1>&2
return 1
fi
pushd "${MAN_PATH}" 1> /dev/null
- ln -nfs "${target}${extension}" "python${extension}"
+ if [[ "${target:0:4}" != "pypy" ]]; then
+ ln -nfs "${target}${extension}" "python${extension}"
+ fi
popd 1> /dev/null
}
@@ -175,17 +193,22 @@
describe_show_options() {
echo "--ABI : Show Python ABI in format of PYTHON_ABI variable"
+ echo "--pypy-c1 : Show active pypy 1 interpreter"
echo "--python2 : Show active Python 2 interpreter"
echo "--python3 : Show active Python 3 interpreter"
+ echo ""
}
do_show() {
- local ABI="0" interpreter python2="0" python3="0"
+ local ABI="0" interpreter python2="0" python3="0" pypy1="0"
while [[ $# > 0 ]]; do
case "$1" in
--ABI)
ABI="1"
;;
+ --pypy1)
+ pypy1="1"
+ ;;
--python2)
python2="1"
;;
@@ -201,9 +224,15 @@
if [[ "${python2}" == "1" && "${python3}" == "1" ]]; then
die -q "'--python2' and '--python3' options cannot be specified simultaneously"
+ elif [[ "${pypy1}" == "1" && "${python2}" == "1" ]]; then
+ die -q "'--pypy-c1' and '--python2' options cannot be specified simultaneously"
+ elif [[ "${pypy1}" == "1" && "${python3}" == "1" ]]; then
+ die -q "'--pypy-c1' and '--python3' options cannot be specified simultaneously"
fi
- if [[ "${python2}" == "1" ]]; then
+ if [[ "${pypy1}" == "1" ]]; then
+ interpreter="$(readlink "${INTERPRETER_PATH}pypy-c1")"
+ elif [[ "${python2}" == "1" ]]; then
interpreter="$(readlink "${INTERPRETER_PATH}python2")"
elif [[ "${python3}" == "1" ]]; then
interpreter="$(readlink "${INTERPRETER_PATH}python3")"
@@ -211,8 +240,10 @@
interpreter="$(<"${ENV_D_PATH}/python/config")"
fi
- if [[ "${ABI}" == "1" ]]; then
+ if [[ "${ABI}" == "1" && "${interpreter:0:6}" == "python" ]]; then
echo -n "${interpreter#python}"
+ elif [[ "${ABI}" == "1" && "${interpreter:0:6}" == "pypy-c" ]]; then
+ echo -n 2.7-"${interpreter/c/}"
else
echo -n "${interpreter}"
fi
@@ -229,14 +260,23 @@
}
describe_list_options() {
+ echo "--pypy1 : List installed Pypy 1 interpreters"
echo "--python2 : List installed Python 2 interpreters"
echo "--python3 : List installed Python 3 interpreters"
}
do_list() {
- local active i python_descriptive_name="Python" python_version_option= python2="0" python3="0" targets=()
+ local active i python_descriptive_name="Python" python_version_option= python2="0" python3="0"
+ local pypy1="0" targets=() active_version=$(do_show)
+
while [[ $# > 0 ]]; do
case "$1" in
+ --pypy1)
+ pypy1="1"
+ python_descriptive_name="Pypy 1"
+ python_version_option="--pypy1"
+ PYTHON_INTERPRETERS_GROUP="1"
+ ;;
--python2)
python2="1"
python_descriptive_name="Python 2"
@@ -258,19 +298,69 @@
if [[ "${python2}" == "1" && "${python3}" == "1" ]]; then
die -q "'--python2' and '--python3' options cannot be specified simultaneously"
+ elif [[ "${pypy1}" == "1" && "${python2}" == "1" ]]; then
+ die -q "'--pypy-c1' and '--python2' options cannot be specified simultaneously"
+ elif [[ "${pypy1}" == "1" && "${python3}" == "1" ]]; then
+ die -q "'--pypy-c1' and '--python3' options cannot be specified simultaneously"
fi
- targets=($(find_targets))
+ combined_targets=($(find_targets))
+ # $(find_targets) captures pypy entries; need to filter them from the list
+ if [[ $PYTHON_INTERPRETERS_GROUP > "1" ]]; then
+ for (( j=0 ; j < ${#combined_targets[@]} ; j++ ))
+ do
+ if [[ ${combined_targets[$j]:0:4} == "pypy" ]]; then
+ break
+ fi
+ targets[$j]="${combined_targets[$j]}"
+ done
- write_list_start "Available ${python_descriptive_name} interpreters:"
- active="$(do_show ${python_version_option})"
- for ((i = 0; i < ${#targets[@]}; i++)); do
- if [[ ${targets[${i}]} == ${active} ]]; then
- targets[${i}]="$(highlight_marker "${targets[${i}]}")"
- fi
- done
- write_numbered_list -m "(none found)" "${targets[@]}"
+ write_list_start "Available ${python_descriptive_name} interpreters:"
+
+ active="$(do_show ${python_version_option})"
+ for ((i = 0; i < ${#targets[@]}; i++)); do
+ if [[ ${targets[${i}]} == ${active} ]]; then
+ targets[${i}]="$(highlight_marker "${targets[${i}]}")"
+ fi
+ done
+ write_numbered_list -m "(none found)" "${targets[@]}"
+
+ elif [[ $PYTHON_INTERPRETERS_GROUP == "1" ]]; then
+ # pypy entries duplicate, filter to only 1 of each
+ for (( j=0 ; j < ${#combined_targets[@]} ; j++ ))
+ do
+ if [[ $j -gt 0 && "${combined_targets[$j]}" == "${combined_targets[0]}" ]]; then
+ break
+ fi
+ targets[$j]="${combined_targets[$j]}"
+ done
+ write_list_start "Available ${python_descriptive_name} interpreters:"
+
+ if [[ "${active_version:0:4}" == "pypy" ]]; then
+ active="$(do_show ${python_version_option})"
+ for ((i = 0; i < ${#targets[@]}; i++)); do
+ if [[ ${targets[${i}]} == ${active} ]]; then
+ targets[${i}]="$(highlight_marker "${targets[${i}]}")"
+ fi
+ done
+ fi
+ write_numbered_list -m "(none found)" "${targets[@]}"
+
+ else
+ targets=($(find_targets)) active=($(find_targets))
+
+ write_list_start "Available ${python_descriptive_name} interpreters:"
+
+ active="$(do_show ${python_version_option})"
+
+ for ((i = 0; i < ${#targets[@]}; i++)); do
+ if [[ ${targets[${i}]} == ${active} ]]; then
+ targets[${i}]="$(highlight_marker "${targets[${i}]}")"
+ fi
+ done
+ write_numbered_list -m "(none found)" "${targets[@]}"
+ fi
}
### set action ###
@@ -280,6 +370,7 @@
}
describe_set_options() {
+ echo "--pypy-c1 : Set active Pypy-c 1 interpreter without setting of main active Python interpreter if it is not set to Pypy-c 1"
echo "--python2 : Set active Python 2 interpreter without setting of main active Python interpreter if it is not set to Python 2"
echo "--python3 : Set active Python 3 interpreter without setting of main active Python interpreter if it is not set to Python 3"
}
@@ -289,10 +380,14 @@
}
do_set() {
- local main_active_python_interpreter python2="0" python3="0"
+ local main_active_python_interpreter python2="0" python3="0" pypy1="0"
SET_MAIN_ACTIVE_PYTHON_INTERPRETER="1"
while [[ $# > 0 ]]; do
case "$1" in
+ --pypy1)
+ pypy1="1"
+ PYTHON_INTERPRETERS_GROUP="1"
+ ;;
--python2)
python2="1"
PYTHON_INTERPRETERS_GROUP="2"
@@ -310,6 +405,10 @@
if [[ "${python2}" == "1" && "${python3}" == "1" ]]; then
die -q "'--python2' and '--python3' options cannot be specified simultaneously"
+ elif [[ "${pypy1}" == "1" && "${python2}" == "1" ]]; then
+ die -q "'--pypy-c1' and '--python2' options cannot be specified simultaneously"
+ elif [[ "${pypy1}" == "1" && "${python3}" == "1" ]]; then
+ die -q "'--pypy-c1' and '--python3' options cannot be specified simultaneously"
fi
if [[ $# -lt 1 ]]; then
@@ -319,9 +418,11 @@
else
main_active_python_interpreter="$(do_show)"
if [[ "${python2}" == "1" && "${main_active_python_interpreter}" != "python2."* ]]; then
- SET_MAIN_ACTIVE_PYTHON_INTERPRETER="0"
- elif [[ "${python3}" == "1" && "${main_active_python_interpreter}" != "python3."* ]]; then
- SET_MAIN_ACTIVE_PYTHON_INTERPRETER="0"
+ if [[ "${python3}" == "1" && "${main_active_python_interpreter}" != "python3."* ]]; then
+ if [[ "${pypy1}" == "1" && "${main_active_python_interpreter}" != "pypy-c1."* ]]; then
+ SET_MAIN_ACTIVE_PYTHON_INTERPRETER="0"
+ fi
+ fi
fi
if ! set_scripts_and_symlinks "${1}"; then
@@ -343,12 +444,14 @@
describe_update_options() {
echo "--if-unset : Do not override existing implementation"
echo "--ignore SLOT : Ignore SLOT when setting symlinks"
+ echo "--pypy-c1 : Set active Pypy-c 1 interpreter without setting of main active Python interpreter if it is not set to Pypy-c 1"
echo "--python2 : Set active Python 2 interpreter without setting of main active Python interpreter if it is not set to Python 2"
echo "--python3 : Set active Python 3 interpreter without setting of main active Python interpreter if it is not set to Python 3"
}
do_update() {
- local if_unset="0" ignored_slots=() interpreters="python?.?" python2="0" python3="0" python_version_option= slot= target targets=()
+ local if_unset="0" ignored_slots=() interpreters="python?.?" python2="0" python3="0" pypy1="0"
+ local python_version_option= slot= target targets=()
while [[ $# > 0 ]]; do
case "$1" in
--if-unset)
@@ -357,6 +460,10 @@
--ignore)
ignored_slots+=("${2}")
shift;;
+ --pypy1)
+ pypy1="1"
+ python_version_option="--pypy-c1"
+ ;;
--python2)
python2="1"
python_version_option="--python2"
@@ -374,19 +481,28 @@
if [[ "${python2}" == "1" && "${python3}" == "1" ]]; then
die -q "'--python2' and '--python3' options cannot be specified simultaneously"
+ elif [[ "${pypy1}" == "1" && "${python2}" == "1" ]]; then
+ die -q "'--pypy-c1' and '--python2' options cannot be specified simultaneously"
+ elif [[ "${pypy1}" == "1" && "${python3}" == "1" ]]; then
+ die -q "'--pypy-c1' and '--python3' options cannot be specified simultaneously"
fi
+ # This reduceS by 3 lines
if [[ "${if_unset}" == "1" && -f "${INTERPRETER_PATH}python" && -f "${ENV_D_PATH}/python/config" ]]; then
- if [[ "${python2}" == "1" && -f "${INTERPRETER_PATH}python2" ]]; then
- return
- elif [[ "${python3}" == "1" && -f "${INTERPRETER_PATH}python3" ]]; then
- return
- elif [[ "${python2}" == "0" && "${python3}" == "0" ]]; then
- return
+ if [[ "${pypy1}" == "1" && -f "${INTERPRETER_PATH}pypy1" ]]; then
+ if [[ "${python2}" == "1" && -f "${INTERPRETER_PATH}python2" ]]; then
+ if [[ "${python3}" == "1" && -f "${INTERPRETER_PATH}python3" ]]; then
+ if [[ "${python2}" == "0" && "${python3}" == "0" && "${pypy1}" == "0" ]]; then
+ return
+ fi
+ fi
+ fi
fi
fi
- if [[ "${python2}" == "1" ]]; then
+ if [[ "${pypy1}" == "1" ]]; then
+ interpreters="pypy-c1.?"
+ elif [[ "${python2}" == "1" ]]; then
interpreters="python2.?"
elif [[ "${python3}" == "1" ]]; then
interpreters="python3.?"
|