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