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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (show annotations) (download)
Thu Mar 28 12:21:46 2013 UTC (16 months ago) by mgorny
Branch: MAIN
Changes since 1.19: +105 -3 lines
Support obtaining CFLAGS and LIBS for the Python implementation (similarly to pkg-config or python-config).

1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/python-utils-r1.eclass,v 1.19 2013/03/07 20:58:51 radhermit Exp $
4
5 # @ECLASS: python-utils-r1
6 # @MAINTAINER:
7 # Python team <python@gentoo.org>
8 # @AUTHOR:
9 # Author: Michał Górny <mgorny@gentoo.org>
10 # Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
11 # @BLURB: Utility functions for packages with Python parts.
12 # @DESCRIPTION:
13 # An utility eclass providing functions to query Python implementations,
14 # install Python modules and scripts.
15 #
16 # This eclass does not set any metadata variables nor export any phase
17 # functions. It can be inherited safely.
18 #
19 # For more information, please see the python-r1 Developer's Guide:
20 # http://www.gentoo.org/proj/en/Python/python-r1/dev-guide.xml
21
22 case "${EAPI:-0}" in
23 0|1|2|3|4|5)
24 # EAPI=4 makes die behavior clear
25 ;;
26 *)
27 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
28 ;;
29 esac
30
31 if [[ ${_PYTHON_ECLASS_INHERITED} ]]; then
32 die 'python-r1 suite eclasses can not be used with python.eclass.'
33 fi
34
35 if [[ ! ${_PYTHON_UTILS_R1} ]]; then
36
37 inherit multilib toolchain-funcs
38
39 # @ECLASS-VARIABLE: _PYTHON_ALL_IMPLS
40 # @INTERNAL
41 # @DESCRIPTION:
42 # All supported Python implementations, most preferred last.
43 _PYTHON_ALL_IMPLS=(
44 jython2_5 jython2_7
45 pypy1_9 pypy2_0
46 python3_1 python3_2 python3_3
47 python2_5 python2_6 python2_7
48 )
49
50 # @FUNCTION: _python_impl_supported
51 # @USAGE: <impl>
52 # @INTERNAL
53 # @DESCRIPTION:
54 # Check whether the implementation <impl> (PYTHON_COMPAT-form)
55 # is still supported.
56 #
57 # Returns 0 if the implementation is valid and supported. If it is
58 # unsupported, returns 1 -- and the caller should ignore the entry.
59 # If it is invalid, dies with an appopriate error messages.
60 _python_impl_supported() {
61 debug-print-function ${FUNCNAME} "${@}"
62
63 [[ ${#} -eq 1 ]] || die "${FUNCNAME}: takes exactly 1 argument (impl)."
64
65 local impl=${1}
66
67 # keep in sync with _PYTHON_ALL_IMPLS!
68 # (not using that list because inline patterns shall be faster)
69 case "${impl}" in
70 python2_[567]|python3_[123]|pypy1_9|pypy2_0|jython2_[57])
71 return 0
72 ;;
73 pypy1_8)
74 return 1
75 ;;
76 *)
77 die "Invalid implementation in PYTHON_COMPAT: ${impl}"
78 esac
79 }
80
81 # @ECLASS-VARIABLE: PYTHON
82 # @DESCRIPTION:
83 # The absolute path to the current Python interpreter.
84 #
85 # Set and exported only in commands run by python_foreach_impl().
86 #
87 # Example value:
88 # @CODE
89 # /usr/bin/python2.6
90 # @CODE
91
92 # @ECLASS-VARIABLE: EPYTHON
93 # @DESCRIPTION:
94 # The executable name of the current Python interpreter.
95 #
96 # This variable is used consistently with python.eclass.
97 #
98 # Set and exported only in commands run by python_foreach_impl().
99 #
100 # Example value:
101 # @CODE
102 # python2.6
103 # @CODE
104
105 # @ECLASS-VARIABLE: PYTHON_SITEDIR
106 # @DESCRIPTION:
107 # The path to Python site-packages directory.
108 #
109 # Set and exported on request using python_export().
110 #
111 # Example value:
112 # @CODE
113 # /usr/lib64/python2.6/site-packages
114 # @CODE
115
116 # @ECLASS-VARIABLE: PYTHON_INCLUDEDIR
117 # @DESCRIPTION:
118 # The path to Python include directory.
119 #
120 # Set and exported on request using python_export().
121 #
122 # Example value:
123 # @CODE
124 # /usr/include/python2.6
125 # @CODE
126
127 # @ECLASS-VARIABLE: PYTHON_LIBPATH
128 # @DESCRIPTION:
129 # The path to Python library.
130 #
131 # Set and exported on request using python_export().
132 # Valid only for CPython.
133 #
134 # Example value:
135 # @CODE
136 # /usr/lib64/libpython2.6.so
137 # @CODE
138
139 # @ECLASS-VARIABLE: PYTHON_CFLAGS
140 # @DESCRIPTION:
141 # Proper C compiler flags for building against Python. Obtained from
142 # pkg-config or python-config.
143 #
144 # Set and exported on request using python_export().
145 # Valid only for CPython. Requires a proper build-time dependency
146 # on the Python implementation and on pkg-config.
147 #
148 # Example value:
149 # @CODE
150 # -I/usr/include/python2.7
151 # @CODE
152
153 # @ECLASS-VARIABLE: PYTHON_LIBS
154 # @DESCRIPTION:
155 # Proper C compiler flags for linking against Python. Obtained from
156 # pkg-config or python-config.
157 #
158 # Set and exported on request using python_export().
159 # Valid only for CPython. Requires a proper build-time dependency
160 # on the Python implementation and on pkg-config.
161 #
162 # Example value:
163 # @CODE
164 # -lpython2.7
165 # @CODE
166
167 # @ECLASS-VARIABLE: PYTHON_PKG_DEP
168 # @DESCRIPTION:
169 # The complete dependency on a particular Python package as a string.
170 #
171 # Set and exported on request using python_export().
172 #
173 # Example value:
174 # @CODE
175 # dev-lang/python:2.7[xml]
176 # @CODE
177
178 # @FUNCTION: python_export
179 # @USAGE: [<impl>] <variables>...
180 # @DESCRIPTION:
181 # Set and export the Python implementation-relevant variables passed
182 # as parameters.
183 #
184 # The optional first parameter may specify the requested Python
185 # implementation (either as PYTHON_TARGETS value, e.g. python2_7,
186 # or an EPYTHON one, e.g. python2.7). If no implementation passed,
187 # the current one will be obtained from ${EPYTHON}.
188 #
189 # The variables which can be exported are: PYTHON, EPYTHON,
190 # PYTHON_SITEDIR. They are described more completely in the eclass
191 # variable documentation.
192 python_export() {
193 debug-print-function ${FUNCNAME} "${@}"
194
195 local impl var
196
197 case "${1}" in
198 python*|jython*)
199 impl=${1/_/.}
200 shift
201 ;;
202 pypy-c*)
203 impl=${1}
204 shift
205 ;;
206 pypy*)
207 local v=${1#pypy}
208 impl=pypy-c${v/_/.}
209 shift
210 ;;
211 *)
212 impl=${EPYTHON}
213 [[ ${impl} ]] || die "python_export: no impl nor EPYTHON"
214 ;;
215 esac
216 debug-print "${FUNCNAME}: implementation: ${impl}"
217
218 for var; do
219 case "${var}" in
220 EPYTHON)
221 export EPYTHON=${impl}
222 debug-print "${FUNCNAME}: EPYTHON = ${EPYTHON}"
223 ;;
224 PYTHON)
225 export PYTHON=${EPREFIX}/usr/bin/${impl}
226 debug-print "${FUNCNAME}: PYTHON = ${PYTHON}"
227 ;;
228 PYTHON_SITEDIR)
229 local dir
230 case "${impl}" in
231 python*)
232 dir=/usr/$(get_libdir)/${impl}
233 ;;
234 jython*)
235 dir=/usr/share/${impl}/Lib
236 ;;
237 pypy*)
238 dir=/usr/$(get_libdir)/${impl/-c/}
239 ;;
240 esac
241
242 export PYTHON_SITEDIR=${EPREFIX}${dir}/site-packages
243 debug-print "${FUNCNAME}: PYTHON_SITEDIR = ${PYTHON_SITEDIR}"
244 ;;
245 PYTHON_INCLUDEDIR)
246 local dir
247 case "${impl}" in
248 python*)
249 dir=/usr/include/${impl}
250 ;;
251 jython*)
252 dir=/usr/share/${impl}/Include
253 ;;
254 pypy*)
255 dir=/usr/$(get_libdir)/${impl/-c/}/include
256 ;;
257 esac
258
259 export PYTHON_INCLUDEDIR=${EPREFIX}${dir}
260 debug-print "${FUNCNAME}: PYTHON_INCLUDEDIR = ${PYTHON_INCLUDEDIR}"
261 ;;
262 PYTHON_LIBPATH)
263 local libname
264 case "${impl}" in
265 python*)
266 libname=lib${impl}
267 ;;
268 *)
269 die "${impl} lacks a dynamic library"
270 ;;
271 esac
272
273 local path=${EPREFIX}/usr/$(get_libdir)
274
275 export PYTHON_LIBPATH=${path}/${libname}$(get_libname)
276 debug-print "${FUNCNAME}: PYTHON_LIBPATH = ${PYTHON_LIBPATH}"
277 ;;
278 PYTHON_CFLAGS)
279 local val
280
281 case "${impl}" in
282 python2.5|python2.6)
283 # old versions support python-config only
284 val=$("${impl}-config" --includes)
285 ;;
286 python*)
287 # python-2.7, python-3.2, etc.
288 val=$($(tc-getPKG_CONFIG) --cflags ${impl/n/n-})
289 ;;
290 *)
291 die "${impl}: obtaining ${var} not supported"
292 ;;
293 esac
294
295 export PYTHON_CFLAGS=${val}
296 debug-print "${FUNCNAME}: PYTHON_CFLAGS = ${PYTHON_CFLAGS}"
297 ;;
298 PYTHON_LIBS)
299 local val
300
301 case "${impl}" in
302 python2.5|python2.6)
303 # old versions support python-config only
304 val=$("${impl}-config" --libs)
305 ;;
306 python*)
307 # python-2.7, python-3.2, etc.
308 val=$($(tc-getPKG_CONFIG) --libs ${impl/n/n-})
309 ;;
310 *)
311 die "${impl}: obtaining ${var} not supported"
312 ;;
313 esac
314
315 export PYTHON_LIBS=${val}
316 debug-print "${FUNCNAME}: PYTHON_LIBS = ${PYTHON_LIBS}"
317 ;;
318 PYTHON_PKG_DEP)
319 local d
320 case ${impl} in
321 python*)
322 PYTHON_PKG_DEP='dev-lang/python';;
323 jython*)
324 PYTHON_PKG_DEP='dev-java/jython';;
325 pypy*)
326 PYTHON_PKG_DEP='dev-python/pypy';;
327 *)
328 die "Invalid implementation: ${impl}"
329 esac
330
331 # slot
332 PYTHON_PKG_DEP+=:${impl##*[a-z-]}
333
334 # use-dep
335 if [[ ${PYTHON_REQ_USE} ]]; then
336 PYTHON_PKG_DEP+=[${PYTHON_REQ_USE}]
337 fi
338
339 export PYTHON_PKG_DEP
340 debug-print "${FUNCNAME}: PYTHON_PKG_DEP = ${PYTHON_PKG_DEP}"
341 ;;
342 *)
343 die "python_export: unknown variable ${var}"
344 esac
345 done
346 }
347
348 # @FUNCTION: python_get_PYTHON
349 # @USAGE: [<impl>]
350 # @DESCRIPTION:
351 # Obtain and print the path to the Python interpreter for the given
352 # implementation. If no implementation is provided, ${EPYTHON} will
353 # be used.
354 #
355 # If you just need to have PYTHON set (and exported), then it is better
356 # to use python_export() directly instead.
357 python_get_PYTHON() {
358 debug-print-function ${FUNCNAME} "${@}"
359
360 python_export "${@}" PYTHON
361 echo "${PYTHON}"
362 }
363
364 # @FUNCTION: python_get_EPYTHON
365 # @USAGE: <impl>
366 # @DESCRIPTION:
367 # Obtain and print the EPYTHON value for the given implementation.
368 #
369 # If you just need to have EPYTHON set (and exported), then it is better
370 # to use python_export() directly instead.
371 python_get_EPYTHON() {
372 debug-print-function ${FUNCNAME} "${@}"
373
374 python_export "${@}" EPYTHON
375 echo "${EPYTHON}"
376 }
377
378 # @FUNCTION: python_get_sitedir
379 # @USAGE: [<impl>]
380 # @DESCRIPTION:
381 # Obtain and print the 'site-packages' path for the given
382 # implementation. If no implementation is provided, ${EPYTHON} will
383 # be used.
384 #
385 # If you just need to have PYTHON_SITEDIR set (and exported), then it is
386 # better to use python_export() directly instead.
387 python_get_sitedir() {
388 debug-print-function ${FUNCNAME} "${@}"
389
390 python_export "${@}" PYTHON_SITEDIR
391 echo "${PYTHON_SITEDIR}"
392 }
393
394 # @FUNCTION: python_get_includedir
395 # @USAGE: [<impl>]
396 # @DESCRIPTION:
397 # Obtain and print the include path for the given implementation. If no
398 # implementation is provided, ${EPYTHON} will be used.
399 #
400 # If you just need to have PYTHON_INCLUDEDIR set (and exported), then it
401 # is better to use python_export() directly instead.
402 python_get_includedir() {
403 debug-print-function ${FUNCNAME} "${@}"
404
405 python_export "${@}" PYTHON_INCLUDEDIR
406 echo "${PYTHON_INCLUDEDIR}"
407 }
408
409 # @FUNCTION: python_get_library_path
410 # @USAGE: [<impl>]
411 # @DESCRIPTION:
412 # Obtain and print the Python library path for the given implementation.
413 # If no implementation is provided, ${EPYTHON} will be used.
414 #
415 # Please note that this function can be used with CPython only. Use
416 # in another implementation will result in a fatal failure.
417 python_get_library_path() {
418 debug-print-function ${FUNCNAME} "${@}"
419
420 python_export "${@}" PYTHON_LIBPATH
421 echo "${PYTHON_LIBPATH}"
422 }
423
424 # @FUNCTION: python_get_CFLAGS
425 # @USAGE: [<impl>]
426 # @DESCRIPTION:
427 # Obtain and print the compiler flags for building against Python,
428 # for the given implementation. If no implementation is provided,
429 # ${EPYTHON} will be used.
430 #
431 # Please note that this function can be used with CPython only.
432 # It requires Python and pkg-config installed, and therefore proper
433 # build-time dependencies need be added to the ebuild.
434 python_get_CFLAGS() {
435 debug-print-function ${FUNCNAME} "${@}"
436
437 python_export "${@}" PYTHON_CFLAGS
438 echo "${PYTHON_CFLAGS}"
439 }
440
441 # @FUNCTION: python_get_LIBS
442 # @USAGE: [<impl>]
443 # @DESCRIPTION:
444 # Obtain and print the compiler flags for linking against Python,
445 # for the given implementation. If no implementation is provided,
446 # ${EPYTHON} will be used.
447 #
448 # Please note that this function can be used with CPython only.
449 # It requires Python and pkg-config installed, and therefore proper
450 # build-time dependencies need be added to the ebuild.
451 python_get_LIBS() {
452 debug-print-function ${FUNCNAME} "${@}"
453
454 python_export "${@}" PYTHON_LIBS
455 echo "${PYTHON_LIBS}"
456 }
457
458 # @FUNCTION: _python_rewrite_shebang
459 # @INTERNAL
460 # @USAGE: [<EPYTHON>] <path>...
461 # @DESCRIPTION:
462 # Replaces 'python' executable in the shebang with the executable name
463 # of the specified interpreter. If no EPYTHON value (implementation) is
464 # used, the current ${EPYTHON} will be used.
465 #
466 # All specified files must start with a 'python' shebang. A file not
467 # having a matching shebang will be refused. The exact shebang style
468 # will be preserved in order not to break anything.
469 #
470 # Example conversions:
471 # @CODE
472 # From: #!/usr/bin/python -R
473 # To: #!/usr/bin/python2.7 -R
474 #
475 # From: #!/usr/bin/env FOO=bar python
476 # To: #!/usr/bin/env FOO=bar python2.7
477 # @CODE
478 _python_rewrite_shebang() {
479 debug-print-function ${FUNCNAME} "${@}"
480
481 local impl
482 case "${1}" in
483 python*|jython*|pypy-c*)
484 impl=${1}
485 shift
486 ;;
487 *)
488 impl=${EPYTHON}
489 [[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON"
490 ;;
491 esac
492 debug-print "${FUNCNAME}: implementation: ${impl}"
493
494 local f
495 for f; do
496 local shebang=$(head -n 1 "${f}")
497 local from
498 debug-print "${FUNCNAME}: path = ${f}"
499 debug-print "${FUNCNAME}: shebang = ${shebang}"
500
501 if [[ "${shebang} " == *'python '* ]]; then
502 from=python
503 elif [[ "${shebang} " == *'python2 '* ]]; then
504 from=python2
505 elif [[ "${shebang} " == *'python3 '* ]]; then
506 from=python3
507 else
508 eerror "A file does not seem to have a supported shebang:"
509 eerror " file: ${f}"
510 eerror " shebang: ${shebang}"
511 die "${FUNCNAME}: ${f} does not seem to have a valid shebang"
512 fi
513
514 if [[ ${from} == python2 && ${impl} == python3*
515 || ${from} == python3 && ${impl} != python3* ]]; then
516 eerror "A file does have shebang not supporting requested impl:"
517 eerror " file: ${f}"
518 eerror " shebang: ${shebang}"
519 eerror " impl: ${impl}"
520 die "${FUNCNAME}: ${f} does have shebang not supporting ${EPYTHON}"
521 fi
522
523 sed -i -e "1s:${from}:${impl}:" "${f}" || die
524 done
525 }
526
527 # @FUNCTION: _python_ln_rel
528 # @INTERNAL
529 # @USAGE: <from> <to>
530 # @DESCRIPTION:
531 # Create a relative symlink.
532 _python_ln_rel() {
533 debug-print-function ${FUNCNAME} "${@}"
534
535 local from=${1}
536 local to=${2}
537
538 local frpath=${from%/*}/
539 local topath=${to%/*}/
540 local rel_path=
541
542 while [[ ${topath} ]]; do
543 local frseg= toseg=
544
545 while [[ ! ${frseg} && ${frpath} ]]; do
546 frseg=${frpath%%/*}
547 frpath=${frpath#${frseg}/}
548 done
549
550 while [[ ! ${toseg} && ${topath} ]]; do
551 toseg=${topath%%/*}
552 topath=${topath#${toseg}/}
553 done
554
555 if [[ ${frseg} != ${toseg} ]]; then
556 rel_path=../${rel_path}${frseg:+${frseg}/}
557 fi
558 done
559 rel_path+=${frpath}${1##*/}
560
561 debug-print "${FUNCNAME}: ${from} -> ${to}"
562 debug-print "${FUNCNAME}: rel_path = ${rel_path}"
563
564 ln -fs "${rel_path}" "${to}"
565 }
566
567 # @FUNCTION: python_optimize
568 # @USAGE: [<directory>...]
569 # @DESCRIPTION:
570 # Compile and optimize Python modules in specified directories (absolute
571 # paths). If no directories are provided, the default system paths
572 # are used (prepended with ${D}).
573 python_optimize() {
574 debug-print-function ${FUNCNAME} "${@}"
575
576 [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
577
578 local PYTHON=${PYTHON}
579 [[ ${PYTHON} ]] || python_export PYTHON
580
581 # Note: python2.6 can't handle passing files to compileall...
582
583 # default to sys.path
584 if [[ ${#} -eq 0 ]]; then
585 local f
586 while IFS= read -r -d '' f; do
587 # 1) accept only absolute paths
588 # (i.e. skip '', '.' or anything like that)
589 # 2) skip paths which do not exist
590 # (python2.6 complains about them verbosely)
591
592 if [[ ${f} == /* && -d ${D}${f} ]]; then
593 set -- "${D}${f}" "${@}"
594 fi
595 done < <("${PYTHON}" -c 'import sys; print("\0".join(sys.path))')
596
597 debug-print "${FUNCNAME}: using sys.path: ${*/%/;}"
598 fi
599
600 local d
601 for d; do
602 # make sure to get a nice path without //
603 local instpath=${d#${D}}
604 instpath=/${instpath##/}
605
606 case "${EPYTHON}" in
607 python*)
608 "${PYTHON}" -m compileall -q -f -d "${instpath}" "${d}"
609 "${PYTHON}" -OO -m compileall -q -f -d "${instpath}" "${d}"
610 ;;
611 *)
612 "${PYTHON}" -m compileall -q -f -d "${instpath}" "${@}"
613 ;;
614 esac
615 done
616 }
617
618 # @ECLASS-VARIABLE: python_scriptroot
619 # @DEFAULT_UNSET
620 # @DESCRIPTION:
621 # The current script destination for python_doscript(). The path
622 # is relative to the installation root (${ED}).
623 #
624 # When unset, ${DESTTREE}/bin (/usr/bin by default) will be used.
625 #
626 # Can be set indirectly through the python_scriptinto() function.
627 #
628 # Example:
629 # @CODE
630 # src_install() {
631 # local python_scriptroot=${GAMES_BINDIR}
632 # python_foreach_impl python_doscript foo
633 # }
634 # @CODE
635
636 # @FUNCTION: python_scriptinto
637 # @USAGE: <new-path>
638 # @DESCRIPTION:
639 # Set the current scriptroot. The new value will be stored
640 # in the 'python_scriptroot' environment variable. The new value need
641 # be relative to the installation root (${ED}).
642 #
643 # Alternatively, you can set the variable directly.
644 python_scriptinto() {
645 debug-print-function ${FUNCNAME} "${@}"
646
647 python_scriptroot=${1}
648 }
649
650 # @FUNCTION: python_doscript
651 # @USAGE: <files>...
652 # @DESCRIPTION:
653 # Install the given scripts into current python_scriptroot,
654 # for the current Python implementation (${EPYTHON}).
655 #
656 # All specified files must start with a 'python' shebang. The shebang
657 # will be converted, the file will be renamed to be EPYTHON-suffixed
658 # and a wrapper will be installed in place of the original name.
659 #
660 # Example:
661 # @CODE
662 # src_install() {
663 # python_foreach_impl python_doscript ${PN}
664 # }
665 # @CODE
666 python_doscript() {
667 debug-print-function ${FUNCNAME} "${@}"
668
669 local f
670 for f; do
671 python_newscript "${f}" "${f##*/}"
672 done
673 }
674
675 # @FUNCTION: python_newscript
676 # @USAGE: <path> <new-name>
677 # @DESCRIPTION:
678 # Install the given script into current python_scriptroot
679 # for the current Python implementation (${EPYTHON}), and name it
680 # <new-name>.
681 #
682 # The file must start with a 'python' shebang. The shebang will be
683 # converted, the file will be renamed to be EPYTHON-suffixed
684 # and a wrapper will be installed in place of the <new-name>.
685 #
686 # Example:
687 # @CODE
688 # src_install() {
689 # python_foreach_impl python_newscript foo.py foo
690 # }
691 # @CODE
692 python_newscript() {
693 debug-print-function ${FUNCNAME} "${@}"
694
695 [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
696 [[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <path> <new-name>"
697
698 local d=${python_scriptroot:-${DESTTREE}/bin}
699 local INSDESTTREE INSOPTIONS
700
701 insinto "${d}"
702 insopts -m755
703
704 local f=${1}
705 local barefn=${2}
706
707 local newfn=${barefn}-${EPYTHON}
708
709 debug-print "${FUNCNAME}: ${f} -> ${d}/${newfn}"
710 newins "${f}" "${newfn}" || die
711 _python_rewrite_shebang "${ED}/${d}/${newfn}"
712
713 # install the wrapper
714 _python_ln_rel "${ED}"/usr/bin/python-exec "${ED}/${d}/${barefn}" || die
715 }
716
717 # @ECLASS-VARIABLE: python_moduleroot
718 # @DEFAULT_UNSET
719 # @DESCRIPTION:
720 # The current module root for python_domodule(). The path can be either
721 # an absolute system path (it must start with a slash, and ${ED} will be
722 # prepended to it) or relative to the implementation's site-packages directory
723 # (then it must start with a non-slash character).
724 #
725 # When unset, the modules will be installed in the site-packages root.
726 #
727 # Can be set indirectly through the python_moduleinto() function.
728 #
729 # Example:
730 # @CODE
731 # src_install() {
732 # local python_moduleroot=bar
733 # # installs ${PYTHON_SITEDIR}/bar/baz.py
734 # python_foreach_impl python_domodule baz.py
735 # }
736 # @CODE
737
738 # @FUNCTION: python_moduleinto
739 # @USAGE: <new-path>
740 # @DESCRIPTION:
741 # Set the current module root. The new value will be stored
742 # in the 'python_moduleroot' environment variable. The new value need
743 # be relative to the site-packages root.
744 #
745 # Alternatively, you can set the variable directly.
746 python_moduleinto() {
747 debug-print-function ${FUNCNAME} "${@}"
748
749 python_moduleroot=${1}
750 }
751
752 # @FUNCTION: python_domodule
753 # @USAGE: <files>...
754 # @DESCRIPTION:
755 # Install the given modules (or packages) into the current
756 # python_moduleroot. The list can mention both modules (files)
757 # and packages (directories). All listed files will be installed
758 # for all enabled implementations, and compiled afterwards.
759 #
760 # Example:
761 # @CODE
762 # src_install() {
763 # # (${PN} being a directory)
764 # python_foreach_impl python_domodule ${PN}
765 # }
766 # @CODE
767 python_domodule() {
768 debug-print-function ${FUNCNAME} "${@}"
769
770 [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
771
772 local d
773 if [[ ${python_moduleroot} == /* ]]; then
774 # absolute path
775 d=${python_moduleroot}
776 else
777 # relative to site-packages
778 local PYTHON_SITEDIR=${PYTHON_SITEDIR}
779 [[ ${PYTHON_SITEDIR} ]] || python_export PYTHON_SITEDIR
780
781 d=${PYTHON_SITEDIR#${EPREFIX}}/${python_moduleroot}
782 fi
783
784 local INSDESTTREE
785
786 insinto "${d}"
787 doins -r "${@}" || die
788
789 python_optimize "${ED}/${d}"
790 }
791
792 # @FUNCTION: python_doheader
793 # @USAGE: <files>...
794 # @DESCRIPTION:
795 # Install the given headers into the implementation-specific include
796 # directory. This function is unconditionally recursive, i.e. you can
797 # pass directories instead of files.
798 #
799 # Example:
800 # @CODE
801 # src_install() {
802 # python_foreach_impl python_doheader foo.h bar.h
803 # }
804 # @CODE
805 python_doheader() {
806 debug-print-function ${FUNCNAME} "${@}"
807
808 [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
809
810 local d PYTHON_INCLUDEDIR=${PYTHON_INCLUDEDIR}
811 [[ ${PYTHON_INCLUDEDIR} ]] || python_export PYTHON_INCLUDEDIR
812
813 d=${PYTHON_INCLUDEDIR#${EPREFIX}}
814
815 local INSDESTTREE
816
817 insinto "${d}"
818 doins -r "${@}" || die
819 }
820
821 _PYTHON_UTILS_R1=1
822 fi

  ViewVC Help
Powered by ViewVC 1.1.20