Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 1 | # Copyright 1999-2021 Gentoo Authors |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 4 | EAPI="7" |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 5 | WANT_LIBTOOL="none" |
| 6 | |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 7 | inherit autotools flag-o-matic multiprocessing pax-utils \ |
| 8 | python-utils-r1 toolchain-funcs |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 9 | |
| 10 | MY_P="Python-${PV}" |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 11 | PYVER=$(ver_cut 1-2) |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 12 | PATCHSET="python-gentoo-patches-${PV}-r1" |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 13 | |
| 14 | DESCRIPTION="An interpreted, interactive, object-oriented programming language" |
| 15 | HOMEPAGE="https://www.python.org/" |
| 16 | SRC_URI="https://www.python.org/ftp/python/${PV}/${MY_P}.tar.xz |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 17 | https://dev.gentoo.org/~mgorny/dist/python/${PATCHSET}.tar.xz" |
| 18 | S="${WORKDIR}/${MY_P}" |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 19 | |
| 20 | LICENSE="PSF-2" |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 21 | SLOT="${PYVER}/${PYVER}m" |
Daniel Campello | 7ded4e3 | 2019-02-06 11:03:46 -0700 | [diff] [blame] | 22 | KEYWORDS="*" |
Mike Frysinger | 432f289 | 2021-02-19 15:22:02 -0500 | [diff] [blame] | 23 | IUSE="bluetooth build examples gdbm hardened ipv6 libressl +ncurses +readline sqlite +ssl test +threads tk wininst +xml" |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 24 | RESTRICT="!test? ( test )" |
| 25 | |
| 26 | # Do not add a dependency on dev-lang/python to this ebuild. |
| 27 | # If you need to apply a patch which requires python for bootstrapping, please |
| 28 | # run the bootstrap code on your dev box and include the results in the |
| 29 | # patchset. See bug 447752. |
| 30 | |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 31 | RDEPEND="app-arch/bzip2:= |
| 32 | app-arch/xz-utils:= |
Mike Frysinger | 432f289 | 2021-02-19 15:22:02 -0500 | [diff] [blame] | 33 | dev-libs/libffi:= |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 34 | >=sys-libs/zlib-1.1.3:= |
| 35 | virtual/libcrypt:= |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 36 | virtual/libintl |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 37 | gdbm? ( sys-libs/gdbm:=[berkdb] ) |
| 38 | ncurses? ( >=sys-libs/ncurses-5.2:= ) |
| 39 | readline? ( >=sys-libs/readline-4.1:= ) |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 40 | sqlite? ( >=dev-db/sqlite-3.3.8:3= ) |
| 41 | ssl? ( |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 42 | !libressl? ( dev-libs/openssl:= ) |
| 43 | libressl? ( dev-libs/libressl:= ) |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 44 | ) |
| 45 | tk? ( |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 46 | >=dev-lang/tcl-8.0:= |
| 47 | >=dev-lang/tk-8.0:= |
| 48 | dev-tcltk/blt:= |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 49 | dev-tcltk/tix |
| 50 | ) |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 51 | xml? ( >=dev-libs/expat-2.1:= )" |
Mike Frysinger | 432f289 | 2021-02-19 15:22:02 -0500 | [diff] [blame] | 52 | # bluetooth requires headers from bluez |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 53 | DEPEND="${RDEPEND} |
Mike Frysinger | 432f289 | 2021-02-19 15:22:02 -0500 | [diff] [blame] | 54 | bluetooth? ( net-wireless/bluez ) |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 55 | test? ( app-arch/xz-utils[extra-filters(+)] ) |
| 56 | virtual/pkgconfig |
| 57 | !sys-devel/gcc[libffi(-)]" |
| 58 | RDEPEND+=" !build? ( app-misc/mime-types )" |
| 59 | PDEPEND=">=app-eselect/eselect-python-20140125-r1" |
| 60 | |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 61 | src_prepare() { |
| 62 | # Ensure that internal copies of expat, libffi and zlib are not used. |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 63 | rm -fr Modules/expat || die |
| 64 | rm -fr Modules/_ctypes/libffi* || die |
| 65 | rm -fr Modules/zlib || die |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 66 | |
Mike Frysinger | 95c720e | 2021-02-19 15:09:00 -0500 | [diff] [blame] | 67 | local PATCHES=( |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 68 | "${WORKDIR}/${PATCHSET}" |
Mike Frysinger | 95c720e | 2021-02-19 15:09:00 -0500 | [diff] [blame] | 69 | ) |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 70 | |
Mike Frysinger | 95c720e | 2021-02-19 15:09:00 -0500 | [diff] [blame] | 71 | default |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 72 | |
| 73 | # START: Chromium OS |
Mike Frysinger | ce0b8c0 | 2019-07-11 00:40:18 -0400 | [diff] [blame] | 74 | if tc-is-cross-compiler ; then |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 75 | eapply "${FILESDIR}/python-3.6.5-cross-h2py.patch" |
| 76 | eapply "${FILESDIR}/python-3.6.5-cross-hack-compiler.patch" |
Mike Frysinger | ce0b8c0 | 2019-07-11 00:40:18 -0400 | [diff] [blame] | 77 | fi |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 78 | eapply "${FILESDIR}/python-3.6.5-cross-python-config.patch" |
| 79 | eapply "${FILESDIR}/python-3.6.5-cross-setup-sysroot.patch" |
| 80 | eapply "${FILESDIR}/python-3.6.5-cross-distutils.patch" |
| 81 | eapply "${FILESDIR}/python-3.6.5-cross-sysconfig.patch" |
| 82 | eapply "${FILESDIR}/python-3.6.5-ldshared.patch" |
| 83 | eapply "${FILESDIR}/python-3.6.5-system-libffi.patch" |
| 84 | eapply "${FILESDIR}/python-3.6.5-sigint-handler.patch" |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 85 | |
| 86 | # Undo the @libdir@ change for portage's pym folder as it is always |
| 87 | # installed into /usr/lib/ and not the abi libdir. |
| 88 | sed -i \ |
| 89 | -e '/portage.*pym/s:@@GENTOO_LIBDIR@@:lib:g' \ |
| 90 | Lib/site.py || die |
| 91 | |
| 92 | sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \ |
| 93 | Lib/site.py || die "sed failed to add /usr/local to prefixes" |
| 94 | # END: Chromium OS |
| 95 | |
| 96 | sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \ |
| 97 | Lib/distutils/command/install.py \ |
| 98 | Lib/distutils/sysconfig.py \ |
| 99 | Lib/site.py \ |
| 100 | Lib/sysconfig.py \ |
| 101 | Lib/test/test_site.py \ |
| 102 | Makefile.pre.in \ |
| 103 | Modules/Setup.dist \ |
| 104 | Modules/getpath.c \ |
| 105 | configure.ac \ |
| 106 | setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@" |
| 107 | |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 108 | # force correct number of jobs |
| 109 | # https://bugs.gentoo.org/737660 |
| 110 | local jobs=$(makeopts_jobs "${MAKEOPTS}" "$(get_nproc)") |
| 111 | sed -i -e "/self\.parallel/s:True:${jobs}:" setup.py || die |
| 112 | |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 113 | eautoreconf |
| 114 | } |
| 115 | |
| 116 | src_configure() { |
| 117 | local disable |
Mike Frysinger | 432f289 | 2021-02-19 15:22:02 -0500 | [diff] [blame] | 118 | # disable automagic bluetooth headers detection |
| 119 | use bluetooth || export ac_cv_header_bluetooth_bluetooth_h=no |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 120 | use gdbm || disable+=" gdbm" |
| 121 | use ncurses || disable+=" _curses _curses_panel" |
| 122 | use readline || disable+=" readline" |
| 123 | use sqlite || disable+=" _sqlite3" |
| 124 | use ssl || export PYTHON_DISABLE_SSL="1" |
| 125 | use tk || disable+=" _tkinter" |
| 126 | use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat. |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 127 | export PYTHON_DISABLE_MODULES="${disable}" |
| 128 | |
| 129 | if ! use xml; then |
| 130 | ewarn "You have configured Python without XML support." |
| 131 | ewarn "This is NOT a recommended configuration as you" |
| 132 | ewarn "may face problems parsing any XML documents." |
| 133 | fi |
| 134 | |
| 135 | if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then |
| 136 | einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}" |
| 137 | fi |
| 138 | |
| 139 | if [[ "$(gcc-major-version)" -ge 4 ]]; then |
| 140 | append-flags -fwrapv |
| 141 | fi |
| 142 | |
| 143 | filter-flags -malign-double |
| 144 | |
| 145 | # https://bugs.gentoo.org/show_bug.cgi?id=50309 |
| 146 | if is-flagq -O3; then |
| 147 | is-flagq -fstack-protector-all && replace-flags -O3 -O2 |
| 148 | use hardened && replace-flags -O3 -O2 |
| 149 | fi |
| 150 | |
| 151 | # Export CXX so it ends up in /usr/lib/python3.X/config/Makefile. |
| 152 | tc-export CXX |
| 153 | |
| 154 | # Set LDFLAGS so we link modules with -lpython3.2 correctly. |
| 155 | # Needed on FreeBSD unless Python 3.2 is already installed. |
| 156 | # Please query BSD team before removing this! |
| 157 | append-ldflags "-L." |
| 158 | |
Mike Frysinger | ce0b8c0 | 2019-07-11 00:40:18 -0400 | [diff] [blame] | 159 | tc-export CC |
| 160 | |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 161 | local dbmliborder |
| 162 | if use gdbm; then |
| 163 | dbmliborder+="${dbmliborder:+:}gdbm" |
| 164 | fi |
| 165 | |
| 166 | local myeconfargs=( |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 167 | # glibc-2.30 removes it; since we can't cleanly force-rebuild |
| 168 | # Python on glibc upgrade, remove it proactively to give |
| 169 | # a chance for users rebuilding python before glibc |
| 170 | ac_cv_header_stropts_h=no |
| 171 | |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 172 | --with-fpectl |
| 173 | --enable-shared |
| 174 | $(use_enable ipv6) |
| 175 | $(use_with threads) |
| 176 | --infodir='${prefix}/share/info' |
| 177 | --mandir='${prefix}/share/man' |
| 178 | --with-computed-gotos |
| 179 | --with-dbmliborder="${dbmliborder}" |
| 180 | --with-libc= |
| 181 | --enable-loadable-sqlite-extensions |
| 182 | --without-ensurepip |
| 183 | --with-system-expat |
| 184 | --with-system-ffi |
| 185 | ) |
| 186 | |
| 187 | OPT="" econf "${myeconfargs[@]}" |
| 188 | |
| 189 | if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then |
| 190 | eerror "configure has detected that the sem_open function is broken." |
| 191 | eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777." |
| 192 | die "Broken sem_open function (bug 496328)" |
| 193 | fi |
| 194 | } |
| 195 | |
| 196 | src_compile() { |
| 197 | # Ensure sed works as expected |
| 198 | # https://bugs.gentoo.org/594768 |
| 199 | local -x LC_ALL=C |
| 200 | |
| 201 | emake CPPFLAGS= CFLAGS= LDFLAGS= |
| 202 | |
| 203 | # Work around bug 329499. See also bug 413751 and 457194. |
| 204 | if has_version dev-libs/libffi[pax_kernel]; then |
| 205 | pax-mark E python |
| 206 | else |
| 207 | pax-mark m python |
| 208 | fi |
| 209 | } |
| 210 | |
| 211 | src_test() { |
| 212 | # Tests will not work when cross compiling. |
| 213 | if tc-is-cross-compiler; then |
| 214 | elog "Disabling tests due to crosscompiling." |
| 215 | return |
| 216 | fi |
| 217 | |
| 218 | # Skip failing tests. |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 219 | local skipped_tests="gdb faulthandler" |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 220 | |
| 221 | for test in ${skipped_tests}; do |
| 222 | mv "${S}"/Lib/test/test_${test}.py "${T}" |
| 223 | done |
| 224 | |
Mike Frysinger | 432f289 | 2021-02-19 15:22:02 -0500 | [diff] [blame] | 225 | # bug 660358 |
| 226 | local -x COLUMNS=80 |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 227 | local -x PYTHONDONTWRITEBYTECODE= |
| 228 | |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 229 | local jobs=$(makeopts_jobs "${MAKEOPTS}" "$(get_nproc)") |
| 230 | |
| 231 | emake test EXTRATESTOPTS="-u-network -j${jobs}" \ |
| 232 | CPPFLAGS= CFLAGS= LDFLAGS= < /dev/tty |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 233 | local result=$? |
| 234 | |
| 235 | for test in ${skipped_tests}; do |
| 236 | mv "${T}/test_${test}.py" "${S}"/Lib/test |
| 237 | done |
| 238 | |
| 239 | elog "The following tests have been skipped:" |
| 240 | for test in ${skipped_tests}; do |
| 241 | elog "test_${test}.py" |
| 242 | done |
| 243 | |
| 244 | elog "If you would like to run them, you may:" |
| 245 | elog "cd '${EPREFIX}/usr/$(get_libdir)/python${PYVER}/test'" |
| 246 | elog "and run the tests separately." |
| 247 | |
| 248 | if [[ ${result} -ne 0 ]]; then |
| 249 | die "emake test failed" |
| 250 | fi |
| 251 | } |
| 252 | |
| 253 | src_install() { |
| 254 | local libdir=${ED}/usr/$(get_libdir)/python${PYVER} |
| 255 | |
| 256 | emake DESTDIR="${D}" altinstall |
| 257 | |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 258 | # Remove static library |
| 259 | rm "${ED}"/usr/$(get_libdir)/libpython*.a || die |
| 260 | |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 261 | sed \ |
| 262 | -e "s/\(CONFIGURE_LDFLAGS=\).*/\1/" \ |
| 263 | -e "s/\(PY_LDFLAGS=\).*/\1/" \ |
| 264 | -i "${libdir}/config-${PYVER}"*/Makefile || die "sed failed" |
| 265 | |
| 266 | # Fix collisions between different slots of Python. |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 267 | rm "${ED}/usr/$(get_libdir)/libpython3.so" || die |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 268 | |
| 269 | # Cheap hack to get version with ABIFLAGS |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 270 | local abiver=$(cd "${ED}/usr/include"; echo python*) |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 271 | if [[ ${abiver} != python${PYVER} ]]; then |
| 272 | # Replace python3.X with a symlink to python3.Xm |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 273 | rm "${ED}/usr/bin/python${PYVER}" || die |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 274 | dosym "${abiver}" "/usr/bin/python${PYVER}" |
| 275 | # Create python3.X-config symlink |
| 276 | dosym "${abiver}-config" "/usr/bin/python${PYVER}-config" |
| 277 | # Create python-3.5m.pc symlink |
| 278 | dosym "python-${PYVER}.pc" "/usr/$(get_libdir)/pkgconfig/${abiver/${PYVER}/-${PYVER}}.pc" |
| 279 | fi |
| 280 | |
| 281 | # python seems to get rebuilt in src_install (bug 569908) |
| 282 | # Work around it for now. |
| 283 | if has_version dev-libs/libffi[pax_kernel]; then |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 284 | pax-mark E "${ED}/usr/bin/${abiver}" |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 285 | else |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 286 | pax-mark m "${ED}/usr/bin/${abiver}" |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 287 | fi |
| 288 | |
| 289 | use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 290 | use tk || rm -r "${ED}/usr/bin/idle${PYVER}" "${libdir}/"{idlelib,tkinter,test/test_tk*} || die |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 291 | |
| 292 | use threads || rm -r "${libdir}/multiprocessing" || die |
| 293 | use wininst || rm "${libdir}/distutils/command/"wininst-*.exe || die |
| 294 | |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 295 | dodoc Misc/{ACKS,HISTORY,NEWS} |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 296 | |
| 297 | if use examples; then |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 298 | docinto examples |
| 299 | find Tools -name __pycache__ -exec rm -fr {} + || die |
| 300 | dodoc -r Tools |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 301 | fi |
| 302 | insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510 |
| 303 | local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \ |
| 304 | emake --no-print-directory -s -f - 2>/dev/null) |
| 305 | newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py |
| 306 | |
| 307 | newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER} |
| 308 | newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER} |
| 309 | sed \ |
| 310 | -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${PYVER/./_}_PORT:" \ |
| 311 | -e "s:@PYDOC@:pydoc${PYVER}:" \ |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 312 | -i "${ED}/etc/conf.d/pydoc-${PYVER}" \ |
| 313 | "${ED}/etc/init.d/pydoc-${PYVER}" || die "sed failed" |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 314 | |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 315 | local -x EPYTHON=python${PYVER} |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 316 | # if not using a cross-compiler, use the fresh binary |
| 317 | if ! tc-is-cross-compiler; then |
| 318 | local -x PYTHON=./python |
| 319 | local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD} |
| 320 | else |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 321 | local -x PYTHON=${EPREFIX}/usr/bin/${EPYTHON} |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 322 | fi |
| 323 | |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 324 | echo "EPYTHON='${EPYTHON}'" > epython.py || die |
| 325 | python_domodule epython.py |
| 326 | |
| 327 | # python-exec wrapping support |
| 328 | local pymajor=${PYVER%.*} |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 329 | local scriptdir=${D}$(python_get_scriptdir) |
| 330 | mkdir -p "${scriptdir}" || die |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 331 | # python and pythonX |
| 332 | ln -s "../../../bin/${abiver}" \ |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 333 | "${scriptdir}/python${pymajor}" || die |
| 334 | ln -s "python${pymajor}" "${scriptdir}/python" || die |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 335 | # python-config and pythonX-config |
| 336 | # note: we need to create a wrapper rather than symlinking it due |
| 337 | # to some random dirname(argv[0]) magic performed by python-config |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 338 | cat > "${scriptdir}/python${pymajor}-config" <<-EOF || die |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 339 | #!/bin/sh |
| 340 | exec "${abiver}-config" "\${@}" |
| 341 | EOF |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 342 | chmod +x "${scriptdir}/python${pymajor}-config" || die |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 343 | ln -s "python${pymajor}-config" \ |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 344 | "${scriptdir}/python-config" || die |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 345 | # 2to3, pydoc, pyvenv |
| 346 | ln -s "../../../bin/2to3-${PYVER}" \ |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 347 | "${scriptdir}/2to3" || die |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 348 | ln -s "../../../bin/pydoc${PYVER}" \ |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 349 | "${scriptdir}/pydoc" || die |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 350 | ln -s "../../../bin/pyvenv-${PYVER}" \ |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 351 | "${scriptdir}/pyvenv" || die |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 352 | # idle |
| 353 | if use tk; then |
| 354 | ln -s "../../../bin/idle${PYVER}" \ |
Mike Frysinger | dc5029f | 2021-02-19 15:53:47 -0500 | [diff] [blame^] | 355 | "${scriptdir}/idle" || die |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 356 | fi |
Mike Frysinger | 12f1f69 | 2021-02-13 18:32:43 -0500 | [diff] [blame] | 357 | |
| 358 | # Delete unittests as they are a waste of space and are unused. |
| 359 | rm -rf "${libdir}/test" "${libdir}"/{ctypes,email,sqlite3,unittest}/test || die |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | pkg_preinst() { |
| 363 | if has_version "<${CATEGORY}/${PN}-${PYVER}" && ! has_version ">=${CATEGORY}/${PN}-${PYVER}_alpha"; then |
| 364 | python_updater_warning="1" |
| 365 | fi |
| 366 | } |
| 367 | |
| 368 | eselect_python_update() { |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 369 | if [[ -z "$(eselect python show)" || \ |
| 370 | ! -f "${EROOT}/usr/bin/$(eselect python show)" ]]; then |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 371 | eselect python update |
| 372 | fi |
| 373 | |
Mike Frysinger | 0e24516 | 2021-02-19 15:39:45 -0500 | [diff] [blame] | 374 | if [[ -z "$(eselect python show --python${PV%%.*})" || \ |
| 375 | ! -f "${EROOT}/usr/bin/$(eselect python show --python${PV%%.*})" ]] |
| 376 | then |
Chad Versace | 9c71f3c | 2018-10-24 16:49:31 -0700 | [diff] [blame] | 377 | eselect python update --python${PV%%.*} |
| 378 | fi |
| 379 | } |
| 380 | |
| 381 | pkg_postinst() { |
| 382 | eselect_python_update |
| 383 | |
| 384 | if [[ "${python_updater_warning}" == "1" ]]; then |
| 385 | ewarn "You have just upgraded from an older version of Python." |
| 386 | ewarn |
| 387 | ewarn "Please adjust PYTHON_TARGETS (if so desired), and run emerge with the --newuse or --changed-use option to rebuild packages installing python modules." |
| 388 | fi |
| 389 | } |
| 390 | |
| 391 | pkg_postrm() { |
| 392 | eselect_python_update |
| 393 | } |