1 |
Moved: python_export, getters, python_domodule, python_doscript |
2 |
and the necessary internal functions. No global-scope variables, |
3 |
no phase functions. |
4 |
--- |
5 |
gx86/eclass/python-r1.eclass | 409 +--------------------------------- |
6 |
gx86/eclass/python-utils-r1.eclass | 434 +++++++++++++++++++++++++++++++++++++ |
7 |
2 files changed, 440 insertions(+), 403 deletions(-) |
8 |
create mode 100644 gx86/eclass/python-utils-r1.eclass |
9 |
|
10 |
diff --git a/gx86/eclass/python-r1.eclass b/gx86/eclass/python-r1.eclass |
11 |
index 84dc50f..6cf4200 100644 |
12 |
--- a/gx86/eclass/python-r1.eclass |
13 |
+++ b/gx86/eclass/python-r1.eclass |
14 |
@@ -23,6 +23,11 @@ |
15 |
# Please note that this eclass is mostly intended to be extended |
16 |
# on-request. If you find something you used in other eclasses missing, |
17 |
# please don't hack it around and request an enhancement instead. |
18 |
+# |
19 |
+# Also, please note that python-r1 will always inherit python-utils-r1 |
20 |
+# as well. Thus, all the functions defined and documented there |
21 |
+# can be used in the packages using python-r1, and there is no need ever |
22 |
+# to inherit both. |
23 |
|
24 |
case "${EAPI}" in |
25 |
0|1|2|3) |
26 |
@@ -36,7 +41,7 @@ case "${EAPI}" in |
27 |
;; |
28 |
esac |
29 |
|
30 |
-inherit multilib |
31 |
+inherit python-utils-r1 |
32 |
|
33 |
# @ECLASS-VARIABLE: _PYTHON_ALL_IMPLS |
34 |
# @INTERNAL |
35 |
@@ -181,160 +186,6 @@ _python_set_globals |
36 |
# ${WORKDIR}/foo-1.3-python2_6 |
37 |
# @CODE |
38 |
|
39 |
-# @ECLASS-VARIABLE: PYTHON |
40 |
-# @DESCRIPTION: |
41 |
-# The absolute path to the current Python interpreter. |
42 |
-# |
43 |
-# Set and exported only in commands run by python_foreach_impl(). |
44 |
-# |
45 |
-# Example value: |
46 |
-# @CODE |
47 |
-# /usr/bin/python2.6 |
48 |
-# @CODE |
49 |
- |
50 |
-# @ECLASS-VARIABLE: EPYTHON |
51 |
-# @DESCRIPTION: |
52 |
-# The executable name of the current Python interpreter. |
53 |
-# |
54 |
-# This variable is used consistently with python.eclass. |
55 |
-# |
56 |
-# Set and exported only in commands run by python_foreach_impl(). |
57 |
-# |
58 |
-# Example value: |
59 |
-# @CODE |
60 |
-# python2.6 |
61 |
-# @CODE |
62 |
- |
63 |
-# @ECLASS-VARIABLE: PYTHON_SITEDIR |
64 |
-# @DESCRIPTION: |
65 |
-# The path to Python site-packages directory. |
66 |
-# |
67 |
-# Set and exported on request using python_export(). |
68 |
-# |
69 |
-# Example value: |
70 |
-# @CODE |
71 |
-# /usr/lib64/python2.6/site-packages |
72 |
-# @CODE |
73 |
- |
74 |
-# @FUNCTION: python_export |
75 |
-# @USAGE: [<impl>] <variables>... |
76 |
-# @DESCRIPTION: |
77 |
-# Set and export the Python implementation-relevant variables passed |
78 |
-# as parameters. |
79 |
-# |
80 |
-# The optional first parameter may specify the requested Python |
81 |
-# implementation (either as PYTHON_TARGETS value, e.g. python2_7, |
82 |
-# or an EPYTHON one, e.g. python2.7). If no implementation passed, |
83 |
-# the current one will be obtained from ${EPYTHON}. |
84 |
-# |
85 |
-# The variables which can be exported are: PYTHON, EPYTHON, |
86 |
-# PYTHON_SITEDIR. They are described more completely in the eclass |
87 |
-# variable documentation. |
88 |
-python_export() { |
89 |
- debug-print-function ${FUNCNAME} "${@}" |
90 |
- |
91 |
- local impl var |
92 |
- |
93 |
- case "${1}" in |
94 |
- python*|jython*) |
95 |
- impl=${1/_/.} |
96 |
- shift |
97 |
- ;; |
98 |
- pypy-c*) |
99 |
- impl=${1} |
100 |
- shift |
101 |
- ;; |
102 |
- pypy*) |
103 |
- local v=${1#pypy} |
104 |
- impl=pypy-c${v/_/.} |
105 |
- shift |
106 |
- ;; |
107 |
- *) |
108 |
- impl=${EPYTHON} |
109 |
- [[ ${impl} ]] || die "python_export: no impl nor EPYTHON" |
110 |
- ;; |
111 |
- esac |
112 |
- debug-print "${FUNCNAME}: implementation: ${impl}" |
113 |
- |
114 |
- for var; do |
115 |
- case "${var}" in |
116 |
- EPYTHON) |
117 |
- export EPYTHON=${impl} |
118 |
- debug-print "${FUNCNAME}: EPYTHON = ${EPYTHON}" |
119 |
- ;; |
120 |
- PYTHON) |
121 |
- export PYTHON=${EPREFIX}/usr/bin/${impl} |
122 |
- debug-print "${FUNCNAME}: PYTHON = ${PYTHON}" |
123 |
- ;; |
124 |
- PYTHON_SITEDIR) |
125 |
- local dir |
126 |
- case "${impl}" in |
127 |
- python*) |
128 |
- dir=/usr/$(get_libdir)/${impl} |
129 |
- ;; |
130 |
- jython*) |
131 |
- dir=/usr/share/${impl}/Lib |
132 |
- ;; |
133 |
- pypy*) |
134 |
- dir=/usr/$(get_libdir)/${impl/-c/} |
135 |
- ;; |
136 |
- esac |
137 |
- |
138 |
- export PYTHON_SITEDIR=${EPREFIX}${dir}/site-packages |
139 |
- debug-print "${FUNCNAME}: PYTHON_SITEDIR = ${PYTHON_SITEDIR}" |
140 |
- ;; |
141 |
- *) |
142 |
- die "python_export: unknown variable ${var}" |
143 |
- esac |
144 |
- done |
145 |
-} |
146 |
- |
147 |
-# @FUNCTION: python_get_PYTHON |
148 |
-# @USAGE: [<impl>] |
149 |
-# @DESCRIPTION: |
150 |
-# Obtain and print the path to the Python interpreter for the given |
151 |
-# implementation. If no implementation is provided, ${EPYTHON} will |
152 |
-# be used. |
153 |
-# |
154 |
-# If you just need to have PYTHON set (and exported), then it is better |
155 |
-# to use python_export() directly instead. |
156 |
-python_get_PYTHON() { |
157 |
- debug-print-function ${FUNCNAME} "${@}" |
158 |
- |
159 |
- python_export "${@}" PYTHON |
160 |
- echo "${PYTHON}" |
161 |
-} |
162 |
- |
163 |
-# @FUNCTION: python_get_EPYTHON |
164 |
-# @USAGE: <impl> |
165 |
-# @DESCRIPTION: |
166 |
-# Obtain and print the EPYTHON value for the given implementation. |
167 |
-# |
168 |
-# If you just need to have EPYTHON set (and exported), then it is better |
169 |
-# to use python_export() directly instead. |
170 |
-python_get_EPYTHON() { |
171 |
- debug-print-function ${FUNCNAME} "${@}" |
172 |
- |
173 |
- python_export "${@}" EPYTHON |
174 |
- echo "${EPYTHON}" |
175 |
-} |
176 |
- |
177 |
-# @FUNCTION: python_get_sitedir |
178 |
-# @USAGE: [<impl>] |
179 |
-# @DESCRIPTION: |
180 |
-# Obtain and print the 'site-packages' path for the given |
181 |
-# implementation. If no implementation is provided, ${EPYTHON} will |
182 |
-# be used. |
183 |
-# |
184 |
-# If you just need to have PYTHON_SITEDIR set (and exported), then it is |
185 |
-# better to use python_export() directly instead. |
186 |
-python_get_sitedir() { |
187 |
- debug-print-function ${FUNCNAME} "${@}" |
188 |
- |
189 |
- python_export "${@}" PYTHON_SITEDIR |
190 |
- echo "${PYTHON_SITEDIR}" |
191 |
-} |
192 |
- |
193 |
# @FUNCTION: python_copy_sources |
194 |
# @DESCRIPTION: |
195 |
# Create a single copy of the package sources (${S}) for each enabled |
196 |
@@ -617,97 +468,6 @@ python_export_best() { |
197 |
python_export "${impl}" "${@}" |
198 |
} |
199 |
|
200 |
-# @FUNCTION: _python_rewrite_shebang |
201 |
-# @INTERNAL |
202 |
-# @USAGE: [<EPYTHON>] <path>... |
203 |
-# @DESCRIPTION: |
204 |
-# Replaces 'python' executable in the shebang with the executable name |
205 |
-# of the specified interpreter. If no EPYTHON value (implementation) is |
206 |
-# used, the current ${EPYTHON} will be used. |
207 |
-# |
208 |
-# All specified files must start with a 'python' shebang. A file not |
209 |
-# having a matching shebang will be refused. The exact shebang style |
210 |
-# will be preserved in order not to break anything. |
211 |
-# |
212 |
-# Example conversions: |
213 |
-# @CODE |
214 |
-# From: #!/usr/bin/python -R |
215 |
-# To: #!/usr/bin/python2.7 -R |
216 |
-# |
217 |
-# From: #!/usr/bin/env FOO=bar python |
218 |
-# To: #!/usr/bin/env FOO=bar python2.7 |
219 |
-# @CODE |
220 |
-_python_rewrite_shebang() { |
221 |
- debug-print-function ${FUNCNAME} "${@}" |
222 |
- |
223 |
- local impl |
224 |
- case "${1}" in |
225 |
- python*|jython*|pypy-c*) |
226 |
- impl=${1} |
227 |
- shift |
228 |
- ;; |
229 |
- *) |
230 |
- impl=${EPYTHON} |
231 |
- [[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON" |
232 |
- ;; |
233 |
- esac |
234 |
- debug-print "${FUNCNAME}: implementation: ${impl}" |
235 |
- |
236 |
- local f |
237 |
- for f; do |
238 |
- local shebang=$(head -n 1 "${f}") |
239 |
- debug-print "${FUNCNAME}: path = ${f}" |
240 |
- debug-print "${FUNCNAME}: shebang = ${shebang}" |
241 |
- |
242 |
- if [[ "${shebang} " != *'python '* ]]; then |
243 |
- eerror "A file does not seem to have a supported shebang:" |
244 |
- eerror " file: ${f}" |
245 |
- eerror " shebang: ${shebang}" |
246 |
- die "${FUNCNAME}: ${f} does not seem to have a valid shebang" |
247 |
- fi |
248 |
- |
249 |
- sed -i -e "1s:python:${impl}:" "${f}" || die |
250 |
- done |
251 |
-} |
252 |
- |
253 |
-# @FUNCTION: _python_ln_rel |
254 |
-# @INTERNAL |
255 |
-# @USAGE: <from> <to> |
256 |
-# @DESCRIPTION: |
257 |
-# Create a relative symlink. |
258 |
-_python_ln_rel() { |
259 |
- debug-print-function ${FUNCNAME} "${@}" |
260 |
- |
261 |
- local from=${1} |
262 |
- local to=${2} |
263 |
- |
264 |
- local frpath=${from%/*}/ |
265 |
- local topath=${to%/*}/ |
266 |
- local rel_path= |
267 |
- |
268 |
- # remove double slashes |
269 |
- frpath=${frpath/\/\///} |
270 |
- topath=${topath/\/\///} |
271 |
- |
272 |
- while [[ ${topath} ]]; do |
273 |
- local frseg=${frpath%%/*} |
274 |
- local toseg=${topath%%/*} |
275 |
- |
276 |
- if [[ ${frseg} != ${toseg} ]]; then |
277 |
- rel_path=../${rel_path}${frseg:+${frseg}/} |
278 |
- fi |
279 |
- |
280 |
- frpath=${frpath#${frseg}/} |
281 |
- topath=${topath#${toseg}/} |
282 |
- done |
283 |
- rel_path+=${frpath}${1##*/} |
284 |
- |
285 |
- debug-print "${FUNCNAME}: ${from} -> ${to}" |
286 |
- debug-print "${FUNCNAME}: rel_path = ${rel_path}" |
287 |
- |
288 |
- ln -fs "${rel_path}" "${to}" |
289 |
-} |
290 |
- |
291 |
# @FUNCTION: python_replicate_script |
292 |
# @USAGE: <path>... |
293 |
# @DESCRIPTION: |
294 |
@@ -743,160 +503,3 @@ python_replicate_script() { |
295 |
_python_ln_rel "${ED}"/usr/bin/python-exec "${f}" || die |
296 |
done |
297 |
} |
298 |
- |
299 |
-# @ECLASS-VARIABLE: python_scriptroot |
300 |
-# @DEFAULT_UNSET |
301 |
-# @DESCRIPTION: |
302 |
-# The current script destination for python_doscript(). The path |
303 |
-# is relative to the installation root (${ED}). |
304 |
-# |
305 |
-# When unset, ${DESTTREE}/bin (/usr/bin by default) will be used. |
306 |
-# |
307 |
-# Can be set indirectly through the python_scriptinto() function. |
308 |
-# |
309 |
-# Example: |
310 |
-# @CODE |
311 |
-# src_install() { |
312 |
-# local python_scriptroot=${GAMES_BINDIR} |
313 |
-# python_foreach_impl python_doscript foo |
314 |
-# } |
315 |
-# @CODE |
316 |
- |
317 |
-# @FUNCTION: python_scriptinto |
318 |
-# @USAGE: <new-path> |
319 |
-# @DESCRIPTION: |
320 |
-# Set the current scriptroot. The new value will be stored |
321 |
-# in the 'python_scriptroot' environment variable. The new value need |
322 |
-# be relative to the installation root (${ED}). |
323 |
-# |
324 |
-# Alternatively, you can set the variable directly. |
325 |
-python_scriptinto() { |
326 |
- debug-print-function ${FUNCNAME} "${@}" |
327 |
- |
328 |
- python_scriptroot=${1} |
329 |
-} |
330 |
- |
331 |
-# @FUNCTION: python_doscript |
332 |
-# @USAGE: <files>... |
333 |
-# @DESCRIPTION: |
334 |
-# Install the given scripts into current python_scriptroot, |
335 |
-# for the current Python implementation (${EPYTHON}). |
336 |
-# |
337 |
-# All specified files must start with a 'python' shebang. The shebang |
338 |
-# will be converted, the file will be renamed to be EPYTHON-suffixed |
339 |
-# and a wrapper will be installed in place of the original name. |
340 |
-# |
341 |
-# Example: |
342 |
-# @CODE |
343 |
-# src_install() { |
344 |
-# python_foreach_impl python_doscript ${PN} |
345 |
-# } |
346 |
-# @CODE |
347 |
-python_doscript() { |
348 |
- debug-print-function ${FUNCNAME} "${@}" |
349 |
- |
350 |
- [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).' |
351 |
- |
352 |
- local d=${python_scriptroot:-${DESTTREE}/bin} |
353 |
- local INSDESTTREE INSOPTIONS |
354 |
- |
355 |
- insinto "${d}" |
356 |
- insopts -m755 |
357 |
- |
358 |
- local f |
359 |
- for f; do |
360 |
- local oldfn=${f##*/} |
361 |
- local newfn=${oldfn}-${EPYTHON} |
362 |
- |
363 |
- debug-print "${FUNCNAME}: ${oldfn} -> ${newfn}" |
364 |
- newins "${f}" "${newfn}" |
365 |
- _python_rewrite_shebang "${D}/${d}/${newfn}" |
366 |
- |
367 |
- # install the wrapper |
368 |
- _python_ln_rel "${ED}"/usr/bin/python-exec "${D}/${d}/${oldfn}" || die |
369 |
- done |
370 |
-} |
371 |
- |
372 |
-# @ECLASS-VARIABLE: python_moduleroot |
373 |
-# @DEFAULT_UNSET |
374 |
-# @DESCRIPTION: |
375 |
-# The current module root for python_domodule(). The path can be either |
376 |
-# an absolute system path (it must start with a slash, and ${D} will be |
377 |
-# prepended to it) or relative to the implementation's site-packages directory |
378 |
-# (then it must start with a non-slash character). |
379 |
-# |
380 |
-# When unset, the modules will be installed in the site-packages root. |
381 |
-# |
382 |
-# Can be set indirectly through the python_moduleinto() function. |
383 |
-# |
384 |
-# Example: |
385 |
-# @CODE |
386 |
-# src_install() { |
387 |
-# local python_moduleroot=bar |
388 |
-# # installs ${PYTHON_SITEDIR}/bar/baz.py |
389 |
-# python_foreach_impl python_domodule baz.py |
390 |
-# } |
391 |
-# @CODE |
392 |
- |
393 |
-# @FUNCTION: python_moduleinto |
394 |
-# @USAGE: <new-path> |
395 |
-# @DESCRIPTION: |
396 |
-# Set the current module root. The new value will be stored |
397 |
-# in the 'python_moduleroot' environment variable. The new value need |
398 |
-# be relative to the site-packages root. |
399 |
-# |
400 |
-# Alternatively, you can set the variable directly. |
401 |
-python_moduleinto() { |
402 |
- debug-print-function ${FUNCNAME} "${@}" |
403 |
- |
404 |
- python_moduleroot=${1} |
405 |
-} |
406 |
- |
407 |
-# @FUNCTION: python_domodule |
408 |
-# @USAGE: <files>... |
409 |
-# @DESCRIPTION: |
410 |
-# Install the given modules (or packages) into the current |
411 |
-# python_moduleroot. The list can mention both modules (files) |
412 |
-# and packages (directories). All listed files will be installed |
413 |
-# for all enabled implementations, and compiled afterwards. |
414 |
-# |
415 |
-# Example: |
416 |
-# @CODE |
417 |
-# src_install() { |
418 |
-# # (${PN} being a directory) |
419 |
-# python_foreach_impl python_domodule ${PN} |
420 |
-# } |
421 |
-# @CODE |
422 |
-python_domodule() { |
423 |
- debug-print-function ${FUNCNAME} "${@}" |
424 |
- |
425 |
- [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).' |
426 |
- |
427 |
- local d |
428 |
- if [[ ${python_moduleroot} == /* ]]; then |
429 |
- # absolute path |
430 |
- d=${python_moduleroot} |
431 |
- else |
432 |
- # relative to site-packages |
433 |
- local PYTHON_SITEDIR=${PYTHON_SITEDIR} |
434 |
- [[ ${PYTHON_SITEDIR} ]] || python_export PYTHON_SITEDIR |
435 |
- |
436 |
- d=${PYTHON_SITEDIR}/${python_moduleroot} |
437 |
- fi |
438 |
- |
439 |
- local INSDESTTREE |
440 |
- |
441 |
- insinto "${d}" |
442 |
- doins -r "${@}" |
443 |
- |
444 |
- # erm, python2.6 can't handle passing files to compileall... |
445 |
- case "${EPYTHON}" in |
446 |
- python*) |
447 |
- "${PYTHON}" -m compileall -q "${D}/${d}" |
448 |
- "${PYTHON}" -OO -m compileall -q -f "${D}/${d}" |
449 |
- ;; |
450 |
- *) |
451 |
- "${PYTHON}" -m compileall -q "${D}/${d}" |
452 |
- ;; |
453 |
- esac |
454 |
-} |
455 |
diff --git a/gx86/eclass/python-utils-r1.eclass b/gx86/eclass/python-utils-r1.eclass |
456 |
new file mode 100644 |
457 |
index 0000000..d80b729 |
458 |
--- /dev/null |
459 |
+++ b/gx86/eclass/python-utils-r1.eclass |
460 |
@@ -0,0 +1,434 @@ |
461 |
+# Copyright 1999-2012 Gentoo Foundation |
462 |
+# Distributed under the terms of the GNU General Public License v2 |
463 |
+# $Header: $ |
464 |
+ |
465 |
+# @ECLASS: python-utils-r1 |
466 |
+# @MAINTAINER: |
467 |
+# Michał Górny <mgorny@g.o> |
468 |
+# Python herd <python@g.o> |
469 |
+# @AUTHOR: |
470 |
+# Author: Michał Górny <mgorny@g.o> |
471 |
+# Based on work of: Krzysztof Pawlik <nelchael@g.o> |
472 |
+# @BLURB: Utility functions for packages with Python parts. |
473 |
+# @DESCRIPTION: |
474 |
+# An utility eclass providing functions to query Python implementations, |
475 |
+# install Python modules and scripts. |
476 |
+# |
477 |
+# This eclass does not set any metadata variables nor export any phase |
478 |
+# functions. It can be inherited safely. |
479 |
+ |
480 |
+case "${EAPI}" in |
481 |
+ 0|1|2|3) |
482 |
+ die "Unsupported EAPI=${EAPI} (too old) for ${ECLASS}" |
483 |
+ ;; |
484 |
+ 4|5) |
485 |
+ # EAPI=4 makes die behavior clear |
486 |
+ ;; |
487 |
+ *) |
488 |
+ die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" |
489 |
+ ;; |
490 |
+esac |
491 |
+ |
492 |
+inherit multilib |
493 |
+ |
494 |
+# @ECLASS-VARIABLE: PYTHON |
495 |
+# @DESCRIPTION: |
496 |
+# The absolute path to the current Python interpreter. |
497 |
+# |
498 |
+# Set and exported only in commands run by python_foreach_impl(). |
499 |
+# |
500 |
+# Example value: |
501 |
+# @CODE |
502 |
+# /usr/bin/python2.6 |
503 |
+# @CODE |
504 |
+ |
505 |
+# @ECLASS-VARIABLE: EPYTHON |
506 |
+# @DESCRIPTION: |
507 |
+# The executable name of the current Python interpreter. |
508 |
+# |
509 |
+# This variable is used consistently with python.eclass. |
510 |
+# |
511 |
+# Set and exported only in commands run by python_foreach_impl(). |
512 |
+# |
513 |
+# Example value: |
514 |
+# @CODE |
515 |
+# python2.6 |
516 |
+# @CODE |
517 |
+ |
518 |
+# @ECLASS-VARIABLE: PYTHON_SITEDIR |
519 |
+# @DESCRIPTION: |
520 |
+# The path to Python site-packages directory. |
521 |
+# |
522 |
+# Set and exported on request using python_export(). |
523 |
+# |
524 |
+# Example value: |
525 |
+# @CODE |
526 |
+# /usr/lib64/python2.6/site-packages |
527 |
+# @CODE |
528 |
+ |
529 |
+# @FUNCTION: python_export |
530 |
+# @USAGE: [<impl>] <variables>... |
531 |
+# @DESCRIPTION: |
532 |
+# Set and export the Python implementation-relevant variables passed |
533 |
+# as parameters. |
534 |
+# |
535 |
+# The optional first parameter may specify the requested Python |
536 |
+# implementation (either as PYTHON_TARGETS value, e.g. python2_7, |
537 |
+# or an EPYTHON one, e.g. python2.7). If no implementation passed, |
538 |
+# the current one will be obtained from ${EPYTHON}. |
539 |
+# |
540 |
+# The variables which can be exported are: PYTHON, EPYTHON, |
541 |
+# PYTHON_SITEDIR. They are described more completely in the eclass |
542 |
+# variable documentation. |
543 |
+python_export() { |
544 |
+ debug-print-function ${FUNCNAME} "${@}" |
545 |
+ |
546 |
+ local impl var |
547 |
+ |
548 |
+ case "${1}" in |
549 |
+ python*|jython*) |
550 |
+ impl=${1/_/.} |
551 |
+ shift |
552 |
+ ;; |
553 |
+ pypy-c*) |
554 |
+ impl=${1} |
555 |
+ shift |
556 |
+ ;; |
557 |
+ pypy*) |
558 |
+ local v=${1#pypy} |
559 |
+ impl=pypy-c${v/_/.} |
560 |
+ shift |
561 |
+ ;; |
562 |
+ *) |
563 |
+ impl=${EPYTHON} |
564 |
+ [[ ${impl} ]] || die "python_export: no impl nor EPYTHON" |
565 |
+ ;; |
566 |
+ esac |
567 |
+ debug-print "${FUNCNAME}: implementation: ${impl}" |
568 |
+ |
569 |
+ for var; do |
570 |
+ case "${var}" in |
571 |
+ EPYTHON) |
572 |
+ export EPYTHON=${impl} |
573 |
+ debug-print "${FUNCNAME}: EPYTHON = ${EPYTHON}" |
574 |
+ ;; |
575 |
+ PYTHON) |
576 |
+ export PYTHON=${EPREFIX}/usr/bin/${impl} |
577 |
+ debug-print "${FUNCNAME}: PYTHON = ${PYTHON}" |
578 |
+ ;; |
579 |
+ PYTHON_SITEDIR) |
580 |
+ local dir |
581 |
+ case "${impl}" in |
582 |
+ python*) |
583 |
+ dir=/usr/$(get_libdir)/${impl} |
584 |
+ ;; |
585 |
+ jython*) |
586 |
+ dir=/usr/share/${impl}/Lib |
587 |
+ ;; |
588 |
+ pypy*) |
589 |
+ dir=/usr/$(get_libdir)/${impl/-c/} |
590 |
+ ;; |
591 |
+ esac |
592 |
+ |
593 |
+ export PYTHON_SITEDIR=${EPREFIX}${dir}/site-packages |
594 |
+ debug-print "${FUNCNAME}: PYTHON_SITEDIR = ${PYTHON_SITEDIR}" |
595 |
+ ;; |
596 |
+ *) |
597 |
+ die "python_export: unknown variable ${var}" |
598 |
+ esac |
599 |
+ done |
600 |
+} |
601 |
+ |
602 |
+# @FUNCTION: python_get_PYTHON |
603 |
+# @USAGE: [<impl>] |
604 |
+# @DESCRIPTION: |
605 |
+# Obtain and print the path to the Python interpreter for the given |
606 |
+# implementation. If no implementation is provided, ${EPYTHON} will |
607 |
+# be used. |
608 |
+# |
609 |
+# If you just need to have PYTHON set (and exported), then it is better |
610 |
+# to use python_export() directly instead. |
611 |
+python_get_PYTHON() { |
612 |
+ debug-print-function ${FUNCNAME} "${@}" |
613 |
+ |
614 |
+ python_export "${@}" PYTHON |
615 |
+ echo "${PYTHON}" |
616 |
+} |
617 |
+ |
618 |
+# @FUNCTION: python_get_EPYTHON |
619 |
+# @USAGE: <impl> |
620 |
+# @DESCRIPTION: |
621 |
+# Obtain and print the EPYTHON value for the given implementation. |
622 |
+# |
623 |
+# If you just need to have EPYTHON set (and exported), then it is better |
624 |
+# to use python_export() directly instead. |
625 |
+python_get_EPYTHON() { |
626 |
+ debug-print-function ${FUNCNAME} "${@}" |
627 |
+ |
628 |
+ python_export "${@}" EPYTHON |
629 |
+ echo "${EPYTHON}" |
630 |
+} |
631 |
+ |
632 |
+# @FUNCTION: python_get_sitedir |
633 |
+# @USAGE: [<impl>] |
634 |
+# @DESCRIPTION: |
635 |
+# Obtain and print the 'site-packages' path for the given |
636 |
+# implementation. If no implementation is provided, ${EPYTHON} will |
637 |
+# be used. |
638 |
+# |
639 |
+# If you just need to have PYTHON_SITEDIR set (and exported), then it is |
640 |
+# better to use python_export() directly instead. |
641 |
+python_get_sitedir() { |
642 |
+ debug-print-function ${FUNCNAME} "${@}" |
643 |
+ |
644 |
+ python_export "${@}" PYTHON_SITEDIR |
645 |
+ echo "${PYTHON_SITEDIR}" |
646 |
+} |
647 |
+ |
648 |
+# @FUNCTION: _python_rewrite_shebang |
649 |
+# @INTERNAL |
650 |
+# @USAGE: [<EPYTHON>] <path>... |
651 |
+# @DESCRIPTION: |
652 |
+# Replaces 'python' executable in the shebang with the executable name |
653 |
+# of the specified interpreter. If no EPYTHON value (implementation) is |
654 |
+# used, the current ${EPYTHON} will be used. |
655 |
+# |
656 |
+# All specified files must start with a 'python' shebang. A file not |
657 |
+# having a matching shebang will be refused. The exact shebang style |
658 |
+# will be preserved in order not to break anything. |
659 |
+# |
660 |
+# Example conversions: |
661 |
+# @CODE |
662 |
+# From: #!/usr/bin/python -R |
663 |
+# To: #!/usr/bin/python2.7 -R |
664 |
+# |
665 |
+# From: #!/usr/bin/env FOO=bar python |
666 |
+# To: #!/usr/bin/env FOO=bar python2.7 |
667 |
+# @CODE |
668 |
+_python_rewrite_shebang() { |
669 |
+ debug-print-function ${FUNCNAME} "${@}" |
670 |
+ |
671 |
+ local impl |
672 |
+ case "${1}" in |
673 |
+ python*|jython*|pypy-c*) |
674 |
+ impl=${1} |
675 |
+ shift |
676 |
+ ;; |
677 |
+ *) |
678 |
+ impl=${EPYTHON} |
679 |
+ [[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON" |
680 |
+ ;; |
681 |
+ esac |
682 |
+ debug-print "${FUNCNAME}: implementation: ${impl}" |
683 |
+ |
684 |
+ local f |
685 |
+ for f; do |
686 |
+ local shebang=$(head -n 1 "${f}") |
687 |
+ debug-print "${FUNCNAME}: path = ${f}" |
688 |
+ debug-print "${FUNCNAME}: shebang = ${shebang}" |
689 |
+ |
690 |
+ if [[ "${shebang} " != *'python '* ]]; then |
691 |
+ eerror "A file does not seem to have a supported shebang:" |
692 |
+ eerror " file: ${f}" |
693 |
+ eerror " shebang: ${shebang}" |
694 |
+ die "${FUNCNAME}: ${f} does not seem to have a valid shebang" |
695 |
+ fi |
696 |
+ |
697 |
+ sed -i -e "1s:python:${impl}:" "${f}" || die |
698 |
+ done |
699 |
+} |
700 |
+ |
701 |
+# @FUNCTION: _python_ln_rel |
702 |
+# @INTERNAL |
703 |
+# @USAGE: <from> <to> |
704 |
+# @DESCRIPTION: |
705 |
+# Create a relative symlink. |
706 |
+_python_ln_rel() { |
707 |
+ debug-print-function ${FUNCNAME} "${@}" |
708 |
+ |
709 |
+ local from=${1} |
710 |
+ local to=${2} |
711 |
+ |
712 |
+ local frpath=${from%/*}/ |
713 |
+ local topath=${to%/*}/ |
714 |
+ local rel_path= |
715 |
+ |
716 |
+ # remove double slashes |
717 |
+ frpath=${frpath/\/\///} |
718 |
+ topath=${topath/\/\///} |
719 |
+ |
720 |
+ while [[ ${topath} ]]; do |
721 |
+ local frseg=${frpath%%/*} |
722 |
+ local toseg=${topath%%/*} |
723 |
+ |
724 |
+ if [[ ${frseg} != ${toseg} ]]; then |
725 |
+ rel_path=../${rel_path}${frseg:+${frseg}/} |
726 |
+ fi |
727 |
+ |
728 |
+ frpath=${frpath#${frseg}/} |
729 |
+ topath=${topath#${toseg}/} |
730 |
+ done |
731 |
+ rel_path+=${frpath}${1##*/} |
732 |
+ |
733 |
+ debug-print "${FUNCNAME}: ${from} -> ${to}" |
734 |
+ debug-print "${FUNCNAME}: rel_path = ${rel_path}" |
735 |
+ |
736 |
+ ln -fs "${rel_path}" "${to}" |
737 |
+} |
738 |
+ |
739 |
+# @ECLASS-VARIABLE: python_scriptroot |
740 |
+# @DEFAULT_UNSET |
741 |
+# @DESCRIPTION: |
742 |
+# The current script destination for python_doscript(). The path |
743 |
+# is relative to the installation root (${ED}). |
744 |
+# |
745 |
+# When unset, ${DESTTREE}/bin (/usr/bin by default) will be used. |
746 |
+# |
747 |
+# Can be set indirectly through the python_scriptinto() function. |
748 |
+# |
749 |
+# Example: |
750 |
+# @CODE |
751 |
+# src_install() { |
752 |
+# local python_scriptroot=${GAMES_BINDIR} |
753 |
+# python_foreach_impl python_doscript foo |
754 |
+# } |
755 |
+# @CODE |
756 |
+ |
757 |
+# @FUNCTION: python_scriptinto |
758 |
+# @USAGE: <new-path> |
759 |
+# @DESCRIPTION: |
760 |
+# Set the current scriptroot. The new value will be stored |
761 |
+# in the 'python_scriptroot' environment variable. The new value need |
762 |
+# be relative to the installation root (${ED}). |
763 |
+# |
764 |
+# Alternatively, you can set the variable directly. |
765 |
+python_scriptinto() { |
766 |
+ debug-print-function ${FUNCNAME} "${@}" |
767 |
+ |
768 |
+ python_scriptroot=${1} |
769 |
+} |
770 |
+ |
771 |
+# @FUNCTION: python_doscript |
772 |
+# @USAGE: <files>... |
773 |
+# @DESCRIPTION: |
774 |
+# Install the given scripts into current python_scriptroot, |
775 |
+# for the current Python implementation (${EPYTHON}). |
776 |
+# |
777 |
+# All specified files must start with a 'python' shebang. The shebang |
778 |
+# will be converted, the file will be renamed to be EPYTHON-suffixed |
779 |
+# and a wrapper will be installed in place of the original name. |
780 |
+# |
781 |
+# Example: |
782 |
+# @CODE |
783 |
+# src_install() { |
784 |
+# python_foreach_impl python_doscript ${PN} |
785 |
+# } |
786 |
+# @CODE |
787 |
+python_doscript() { |
788 |
+ debug-print-function ${FUNCNAME} "${@}" |
789 |
+ |
790 |
+ [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).' |
791 |
+ |
792 |
+ local d=${python_scriptroot:-${DESTTREE}/bin} |
793 |
+ local INSDESTTREE INSOPTIONS |
794 |
+ |
795 |
+ insinto "${d}" |
796 |
+ insopts -m755 |
797 |
+ |
798 |
+ local f |
799 |
+ for f; do |
800 |
+ local oldfn=${f##*/} |
801 |
+ local newfn=${oldfn}-${EPYTHON} |
802 |
+ |
803 |
+ debug-print "${FUNCNAME}: ${oldfn} -> ${newfn}" |
804 |
+ newins "${f}" "${newfn}" |
805 |
+ _python_rewrite_shebang "${D}/${d}/${newfn}" |
806 |
+ |
807 |
+ # install the wrapper |
808 |
+ _python_ln_rel "${ED}"/usr/bin/python-exec "${D}/${d}/${oldfn}" || die |
809 |
+ done |
810 |
+} |
811 |
+ |
812 |
+# @ECLASS-VARIABLE: python_moduleroot |
813 |
+# @DEFAULT_UNSET |
814 |
+# @DESCRIPTION: |
815 |
+# The current module root for python_domodule(). The path can be either |
816 |
+# an absolute system path (it must start with a slash, and ${D} will be |
817 |
+# prepended to it) or relative to the implementation's site-packages directory |
818 |
+# (then it must start with a non-slash character). |
819 |
+# |
820 |
+# When unset, the modules will be installed in the site-packages root. |
821 |
+# |
822 |
+# Can be set indirectly through the python_moduleinto() function. |
823 |
+# |
824 |
+# Example: |
825 |
+# @CODE |
826 |
+# src_install() { |
827 |
+# local python_moduleroot=bar |
828 |
+# # installs ${PYTHON_SITEDIR}/bar/baz.py |
829 |
+# python_foreach_impl python_domodule baz.py |
830 |
+# } |
831 |
+# @CODE |
832 |
+ |
833 |
+# @FUNCTION: python_moduleinto |
834 |
+# @USAGE: <new-path> |
835 |
+# @DESCRIPTION: |
836 |
+# Set the current module root. The new value will be stored |
837 |
+# in the 'python_moduleroot' environment variable. The new value need |
838 |
+# be relative to the site-packages root. |
839 |
+# |
840 |
+# Alternatively, you can set the variable directly. |
841 |
+python_moduleinto() { |
842 |
+ debug-print-function ${FUNCNAME} "${@}" |
843 |
+ |
844 |
+ python_moduleroot=${1} |
845 |
+} |
846 |
+ |
847 |
+# @FUNCTION: python_domodule |
848 |
+# @USAGE: <files>... |
849 |
+# @DESCRIPTION: |
850 |
+# Install the given modules (or packages) into the current |
851 |
+# python_moduleroot. The list can mention both modules (files) |
852 |
+# and packages (directories). All listed files will be installed |
853 |
+# for all enabled implementations, and compiled afterwards. |
854 |
+# |
855 |
+# Example: |
856 |
+# @CODE |
857 |
+# src_install() { |
858 |
+# # (${PN} being a directory) |
859 |
+# python_foreach_impl python_domodule ${PN} |
860 |
+# } |
861 |
+# @CODE |
862 |
+python_domodule() { |
863 |
+ debug-print-function ${FUNCNAME} "${@}" |
864 |
+ |
865 |
+ [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).' |
866 |
+ |
867 |
+ local d |
868 |
+ if [[ ${python_moduleroot} == /* ]]; then |
869 |
+ # absolute path |
870 |
+ d=${python_moduleroot} |
871 |
+ else |
872 |
+ # relative to site-packages |
873 |
+ local PYTHON_SITEDIR=${PYTHON_SITEDIR} |
874 |
+ [[ ${PYTHON_SITEDIR} ]] || python_export PYTHON_SITEDIR |
875 |
+ |
876 |
+ d=${PYTHON_SITEDIR}/${python_moduleroot} |
877 |
+ fi |
878 |
+ |
879 |
+ local INSDESTTREE |
880 |
+ |
881 |
+ insinto "${d}" |
882 |
+ doins -r "${@}" |
883 |
+ |
884 |
+ # erm, python2.6 can't handle passing files to compileall... |
885 |
+ case "${EPYTHON}" in |
886 |
+ python*) |
887 |
+ "${PYTHON}" -m compileall -q "${D}/${d}" |
888 |
+ "${PYTHON}" -OO -m compileall -q -f "${D}/${d}" |
889 |
+ ;; |
890 |
+ *) |
891 |
+ "${PYTHON}" -m compileall -q "${D}/${d}" |
892 |
+ ;; |
893 |
+ esac |
894 |
+} |
895 |
-- |
896 |
1.8.0 |