python-exec-9999.ebuild 4.5 KB

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