python-exec-2.4.4.ebuild 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=5
  4. # Kids, don't do this at home!
  5. inherit python-utils-r1
  6. PYTHON_COMPAT=( "${_PYTHON_ALL_IMPLS[@]}" )
  7. # Inherited purely to have PYTHON_TARGET flags which will satisfy USE
  8. # dependencies and trigger necessary rebuilds.
  9. inherit python-r1
  10. DESCRIPTION="Python script wrapper"
  11. HOMEPAGE="https://github.com/mgorny/python-exec/"
  12. SRC_URI="https://github.com/mgorny/${PN}/releases/download/${P}/${P}.tar.bz2"
  13. LICENSE="BSD-2"
  14. SLOT="2"
  15. KEYWORDS="alpha amd64 arm arm64 hppa ia64 m68k ~mips ppc ppc64 s390 sh sparc x86 ~ppc-aix ~amd64-fbsd ~x86-fbsd ~amd64-linux ~arm-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
  16. IUSE=""
  17. # eselect-python because of /usr/bin/python* collisions and new config
  18. # python versions because of missing $scriptdir/python* symlinks
  19. RDEPEND="
  20. !<app-eselect/eselect-python-20160206
  21. !<dev-lang/python-2.7.10-r4:2.7
  22. !<dev-lang/python-3.3.5-r4:3.3
  23. !<dev-lang/python-3.4.3-r4:3.4
  24. !<dev-lang/python-3.5.0-r3:3.5"
  25. src_configure() {
  26. local pyimpls=() i EPYTHON
  27. for i in "${PYTHON_COMPAT[@]}"; do
  28. python_export "${i}" EPYTHON
  29. pyimpls+=( "${EPYTHON}" )
  30. done
  31. local myconf=(
  32. --with-python-impls="${pyimpls[*]}"
  33. )
  34. econf "${myconf[@]}"
  35. }
  36. src_install() {
  37. default
  38. # Prepare and own the template
  39. sed -n -e '/^#/p' config/python-exec.conf.example \
  40. > "${T}"/python-exec.conf || die
  41. insinto /etc/python-exec
  42. doins "${T}"/python-exec.conf
  43. local f
  44. for f in python{,2,3}; do
  45. # symlink the C wrapper for python to avoid shebang recursion
  46. # bug #568974
  47. dosym python-exec2c /usr/bin/"${f}"
  48. done
  49. for f in python{,2,3}-config 2to3 idle pydoc pyvenv; do
  50. # those are python scripts (except for new python-configs)
  51. # so symlink them via the python wrapper
  52. dosym ../lib/python-exec/python-exec2 /usr/bin/"${f}"
  53. done
  54. }
  55. pkg_preinst() {
  56. if [[ -e ${EROOT}etc/python-exec/python-exec.conf ]]; then
  57. # preserve current configuration
  58. cp "${EROOT}"etc/python-exec/python-exec.conf \
  59. "${ED}"etc/python-exec/python-exec.conf || die
  60. else
  61. # preserve previous Python version preference
  62. local py old_pythons=()
  63. local config_base=${EROOT}etc/env.d/python
  64. # start with the 'global' preference (2 vs 3)
  65. if [[ -f ${config_base}/config ]]; then
  66. old_pythons+=( "$(<${config_base}/config)" )
  67. fi
  68. # then try specific py3 selection
  69. for py in 3; do
  70. local target=
  71. if [[ -f ${config_base}/python${py} ]]; then
  72. # try the newer config files
  73. target=$(<${config_base}/python${py})
  74. elif [[ -L ${EROOT}/usr/bin/python${py} ]]; then
  75. # check the older symlink format
  76. target=$(readlink "${EROOT}/usr/bin/python${py}")
  77. # check if it's actually old eselect symlink
  78. [[ ${target} == python?.? ]] || target=
  79. fi
  80. # add the extra target if found and != global
  81. if [[ ${target} && ${old_pythons[0]} != ${target} ]]; then
  82. old_pythons+=( "${target}" )
  83. fi
  84. done
  85. if [[ ${old_pythons[@]} ]]; then
  86. elog "You seem to have just upgraded into the new version of python-exec"
  87. elog "that uses python-exec.conf for configuration. The ebuild has attempted"
  88. elog "to convert your previous configuration to the new format, resulting"
  89. elog "in the following preferences (most preferred version first):"
  90. elog
  91. for py in "${old_pythons[@]}"; do
  92. elog " ${py}"
  93. done
  94. elog
  95. elog "Those interpreters will be preferred when running Python scripts or"
  96. elog "calling wrapped Python executables (python, python2, pydoc...)."
  97. elog "If none of the preferred interpreters are supported, python-exec will"
  98. elog "fall back to the newest supported Python version."
  99. elog
  100. elog "Please note that due to the ambiguous character of the old settings,"
  101. elog "you may want to modify the preference list yourself. In order to do so,"
  102. elog "open the following file in your favorite editor:"
  103. elog
  104. elog " ${EROOT}etc/python-exec/python-exec.conf"
  105. elog
  106. elog "For more information on the new configuration format, please read"
  107. elog "the comment on top of the installed configuration file."
  108. local IFS=$'\n'
  109. echo "${old_pythons[*]}" \
  110. >> "${ED}"etc/python-exec/python-exec.conf || die
  111. fi
  112. fi
  113. }