python-exec-2.4.5.ebuild 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 ~x64-cygwin ~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-fallback-path="${EPREFIX}/usr/local/sbin:${EPREFIX}/usr/local/bin:${EPREFIX}/usr/sbin:${EPREFIX}/usr/bin:${EPREFIX}/sbin:${EPREFIX}/bin"
  33. --with-python-impls="${pyimpls[*]}"
  34. )
  35. econf "${myconf[@]}"
  36. }
  37. src_install() {
  38. default
  39. # Prepare and own the template
  40. sed -n -e '/^#/p' config/python-exec.conf.example \
  41. > "${T}"/python-exec.conf || die
  42. insinto /etc/python-exec
  43. doins "${T}"/python-exec.conf
  44. local f
  45. for f in python{,2,3}; do
  46. # symlink the C wrapper for python to avoid shebang recursion
  47. # bug #568974
  48. dosym python-exec2c /usr/bin/"${f}"
  49. done
  50. for f in python{,2,3}-config 2to3 idle pydoc pyvenv; do
  51. # those are python scripts (except for new python-configs)
  52. # so symlink them via the python wrapper
  53. dosym ../lib/python-exec/python-exec2 /usr/bin/"${f}"
  54. done
  55. }
  56. pkg_preinst() {
  57. if [[ -e ${EROOT}etc/python-exec/python-exec.conf ]]; then
  58. # preserve current configuration
  59. cp "${EROOT}"etc/python-exec/python-exec.conf \
  60. "${ED}"etc/python-exec/python-exec.conf || die
  61. else
  62. # preserve previous Python version preference
  63. local py old_pythons=()
  64. local config_base=${EROOT}etc/env.d/python
  65. # start with the 'global' preference (2 vs 3)
  66. if [[ -f ${config_base}/config ]]; then
  67. old_pythons+=( "$(<${config_base}/config)" )
  68. fi
  69. # then try specific py3 selection
  70. for py in 3; do
  71. local target=
  72. if [[ -f ${config_base}/python${py} ]]; then
  73. # try the newer config files
  74. target=$(<${config_base}/python${py})
  75. elif [[ -L ${EROOT}/usr/bin/python${py} ]]; then
  76. # check the older symlink format
  77. target=$(readlink "${EROOT}/usr/bin/python${py}")
  78. # check if it's actually old eselect symlink
  79. [[ ${target} == python?.? ]] || target=
  80. fi
  81. # add the extra target if found and != global
  82. if [[ ${target} && ${old_pythons[0]} != ${target} ]]; then
  83. old_pythons+=( "${target}" )
  84. fi
  85. done
  86. if [[ ${old_pythons[@]} ]]; then
  87. elog "You seem to have just upgraded into the new version of python-exec"
  88. elog "that uses python-exec.conf for configuration. The ebuild has attempted"
  89. elog "to convert your previous configuration to the new format, resulting"
  90. elog "in the following preferences (most preferred version first):"
  91. elog
  92. for py in "${old_pythons[@]}"; do
  93. elog " ${py}"
  94. done
  95. elog
  96. elog "Those interpreters will be preferred when running Python scripts or"
  97. elog "calling wrapped Python executables (python, python2, pydoc...)."
  98. elog "If none of the preferred interpreters are supported, python-exec will"
  99. elog "fall back to the newest supported Python version."
  100. elog
  101. elog "Please note that due to the ambiguous character of the old settings,"
  102. elog "you may want to modify the preference list yourself. In order to do so,"
  103. elog "open the following file in your favorite editor:"
  104. elog
  105. elog " ${EROOT}etc/python-exec/python-exec.conf"
  106. elog
  107. elog "For more information on the new configuration format, please read"
  108. elog "the comment on top of the installed configuration file."
  109. local IFS=$'\n'
  110. echo "${old_pythons[*]}" \
  111. >> "${ED}"etc/python-exec/python-exec.conf || die
  112. fi
  113. fi
  114. }