app-editors/vscodium: add 1.97.0.25037
[gentoo/gentoo.git] / dev-lang / python / python-3.9.20_p2.ebuild
blob64cab1508101a6a6cbfc8b368bf12c2ec401cd5f
1 # Copyright 1999-2025 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 EAPI="8"
5 WANT_LIBTOOL="none"
7 inherit autotools check-reqs flag-o-matic multiprocessing pax-utils
8 inherit prefix python-utils-r1 toolchain-funcs verify-sig
10 MY_PV=${PV/_rc/rc}
11 MY_P="Python-${MY_PV%_p*}"
12 PYVER=$(ver_cut 1-2)
13 PATCHSET="python-gentoo-patches-${MY_PV}"
15 DESCRIPTION="An interpreted, interactive, object-oriented programming language"
16 HOMEPAGE="
17         https://www.python.org/
18         https://github.com/python/cpython/
20 SRC_URI="
21         https://www.python.org/ftp/python/${PV%%_*}/${MY_P}.tar.xz
22         https://dev.gentoo.org/~mgorny/dist/python/${PATCHSET}.tar.xz
23         verify-sig? (
24                 https://www.python.org/ftp/python/${PV%%_*}/${MY_P}.tar.xz.asc
25         )
27 S="${WORKDIR}/${MY_P}"
29 LICENSE="PSF-2"
30 SLOT="${PYVER}"
31 KEYWORDS="~alpha amd64 arm arm64 hppa ~loong ~m68k ~mips ppc ppc64 ~riscv ~s390 sparc x86"
32 IUSE="
33         bluetooth build debug +ensurepip examples gdbm +ncurses pgo
34         +readline +sqlite +ssl test tk valgrind
36 RESTRICT="!test? ( test )"
38 # Do not add a dependency on dev-lang/python to this ebuild.
39 # If you need to apply a patch which requires python for bootstrapping, please
40 # run the bootstrap code on your dev box and include the results in the
41 # patchset. See bug 447752.
43 RDEPEND="
44         app-arch/bzip2:=
45         app-arch/xz-utils:=
46         >=dev-libs/expat-2.1:=
47         dev-libs/libffi:=
48         dev-libs/mpdecimal:=
49         dev-python/gentoo-common
50         >=sys-libs/zlib-1.1.3:=
51         virtual/libcrypt:=
52         virtual/libintl
53         ensurepip? ( dev-python/ensurepip-wheels )
54         gdbm? ( sys-libs/gdbm:=[berkdb] )
55         kernel_linux? ( sys-apps/util-linux:= )
56         ncurses? ( >=sys-libs/ncurses-5.2:= )
57         readline? ( >=sys-libs/readline-4.1:= )
58         sqlite? ( >=dev-db/sqlite-3.3.8:3= )
59         ssl? ( >=dev-libs/openssl-1.1.1:= )
60         tk? (
61                 >=dev-lang/tcl-8.0:=
62                 >=dev-lang/tk-8.0:=
63                 dev-tcltk/blt:=
64                 dev-tcltk/tix
65         )
67 # bluetooth requires headers from bluez
68 DEPEND="
69         ${RDEPEND}
70         bluetooth? ( net-wireless/bluez )
71         test? ( app-arch/xz-utils )
72         valgrind? ( dev-debug/valgrind )
74 # autoconf-archive needed to eautoreconf
75 BDEPEND="
76         dev-build/autoconf-archive
77         app-alternatives/awk
78         virtual/pkgconfig
79         verify-sig? ( sec-keys/openpgp-keys-python )
81 RDEPEND+="
82         !build? ( app-misc/mime-types )
85 VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/openpgp-keys/python.org.asc
87 # large file tests involve a 2.5G file being copied (duplicated)
88 CHECKREQS_DISK_BUILD=5500M
90 QA_PKGCONFIG_VERSION=${PYVER}
91 # false positives -- functions specific to *BSD
92 QA_CONFIG_IMPL_DECL_SKIP=( chflags lchflags )
94 pkg_pretend() {
95         use test && check-reqs_pkg_pretend
98 pkg_setup() {
99         use test && check-reqs_pkg_setup
102 src_unpack() {
103         if use verify-sig; then
104                 verify-sig_verify_detached "${DISTDIR}"/${MY_P}.tar.xz{,.asc}
105         fi
106         default
109 src_prepare() {
110         # Ensure that internal copies of expat and libffi are not used.
111         rm -r Modules/expat || die
112         rm -r Modules/_ctypes/libffi* || die
114         local PATCHES=(
115                 "${WORKDIR}/${PATCHSET}"
116         )
118         default
120         # https://bugs.gentoo.org/850151
121         sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" setup.py || die
123         # force the correct number of jobs
124         # https://bugs.gentoo.org/737660
125         local jobs=$(makeopts_jobs)
126         sed -i -e "s:-j0:-j${jobs}:" Makefile.pre.in || die
127         sed -i -e "/self\.parallel/s:True:${jobs}:" setup.py || die
129         eautoreconf
132 src_configure() {
133         # disable automagic bluetooth headers detection
134         if ! use bluetooth; then
135                 local -x ac_cv_header_bluetooth_bluetooth_h=no
136         fi
137         local disable
138         use gdbm      || disable+=" gdbm"
139         use ncurses   || disable+=" _curses _curses_panel"
140         use readline  || disable+=" readline"
141         use sqlite    || disable+=" _sqlite3"
142         use ssl       || export PYTHON_DISABLE_SSL="1"
143         use tk        || disable+=" _tkinter"
144         export PYTHON_DISABLE_MODULES="${disable}"
146         if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
147                 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
148         fi
150         append-flags -fwrapv
151         filter-flags -malign-double
153         # Export CXX so it ends up in /usr/lib/python3.X/config/Makefile.
154         # PKG_CONFIG needed for cross.
155         tc-export CXX PKG_CONFIG
157         local dbmliborder=
158         if use gdbm; then
159                 dbmliborder+="${dbmliborder:+:}gdbm"
160         fi
162         # Set baseline test skip flags.
163         COMMON_TEST_SKIPS=(
164                 -x test_gdb
165         )
167         # Arch-specific skips.  See #931888 for a collection of these.
168         case ${CHOST} in
169                 alpha*)
170                         COMMON_TEST_SKIPS+=(
171                                 -x test_builtin
172                                 -x test_capi
173                                 -x test_cmath
174                                 -x test_float
175                                 # timeout
176                                 -x test_free_threading
177                                 -x test_math
178                                 -x test_numeric_tower
179                                 -x test_random
180                                 -x test_statistics
181                                 # bug 653850
182                                 -x test_resource
183                                 -x test_strtod
184                         )
185                         ;;
186                 mips*)
187                         COMMON_TEST_SKIPS+=(
188                                 -x test_ctypes
189                                 -x test_external_inspection
190                                 -x test_statistics
191                         )
192                         ;;
193                 powerpc64-*) # big endian
194                         COMMON_TEST_SKIPS+=(
195                                 -x test_descr
196                         )
197                         ;;
198                 riscv*)
199                         COMMON_TEST_SKIPS+=(
200                                 -x test_urllib2
201                         )
202                         ;;
203                 sparc*)
204                         COMMON_TEST_SKIPS+=(
205                                 # bug 788022
206                                 -x test_multiprocessing_fork
207                                 -x test_multiprocessing_forkserver
208                                 -x test_multiprocessing_spawn
210                                 -x test_ctypes
211                                 -x test_descr
212                                 # bug 931908
213                                 -x test_exceptions
214                         )
215                         ;;
216         esac
218         # musl-specific skips
219         use elibc_musl && COMMON_TEST_SKIPS+=(
220                 # various musl locale deficiencies
221                 -x test__locale
222                 -x test_c_locale_coercion
223                 -x test_locale
224                 -x test_re
226                 # known issues with find_library on musl
227                 # https://bugs.python.org/issue21622
228                 -x test_ctypes
230                 # fpathconf, ttyname errno values
231                 -x test_os
232         )
234         if use pgo; then
235                 local profile_task_flags=(
236                         -m test
237                         "-j$(makeopts_jobs)"
238                         --pgo-extended
239                         -u-network
241                         # We use a timeout because of how often we've had hang issues
242                         # here. It also matches the default upstream PROFILE_TASK.
243                         --timeout 1200
245                         "${COMMON_TEST_SKIPS[@]}"
247                         -x test_dtrace
249                         # All of these seem to occasionally hang for PGO inconsistently
250                         # They'll even hang here but be fine in src_test sometimes.
251                         # bug #828535 (and related: bug #788022)
252                         -x test_asyncio
253                         -x test_concurrent_futures
254                         -x test_httpservers
255                         -x test_logging
256                         -x test_multiprocessing_fork
257                         -x test_socket
258                         -x test_xmlrpc
260                         # Hangs (actually runs indefinitely executing itself w/ many cpython builds)
261                         # bug #900429
262                         -x test_tools
263                 )
265                 # Arch-specific skips.  See #931888 for a collection of these.
266                 case ${CHOST} in
267                         alpha*)
268                                 profile_task_flags+=(
269                                         -x test_os
270                                 )
271                                 ;;
272                         hppa*)
273                                 profile_task_flags+=(
274                                         -x test_descr
275                                         # bug 931908
276                                         -x test_exceptions
277                                         -x test_os
278                                 )
279                                 ;;
280                         powerpc64-*) # big endian
281                                 profile_task_flags+=(
282                                         # bug 931908
283                                         -x test_exceptions
284                                 )
285                                 ;;
286                         riscv*)
287                                 profile_task_flags+=(
288                                         -x test_statistics
289                                 )
290                                 ;;
291                 esac
293                 if has_version "app-arch/rpm" ; then
294                         # Avoid sandbox failure (attempts to write to /var/lib/rpm)
295                         profile_task_flags+=(
296                                 -x test_distutils
297                         )
298                 fi
299                 local -x PROFILE_TASK="${profile_task_flags[*]}"
300         fi
302         local myeconfargs=(
303                 # glibc-2.30 removes it; since we can't cleanly force-rebuild
304                 # Python on glibc upgrade, remove it proactively to give
305                 # a chance for users rebuilding python before glibc
306                 ac_cv_header_stropts_h=no
308                 --enable-shared
309                 --enable-ipv6
310                 --infodir='${prefix}/share/info'
311                 --mandir='${prefix}/share/man'
312                 --with-computed-gotos
313                 --with-dbmliborder="${dbmliborder}"
314                 --with-libc=
315                 --enable-loadable-sqlite-extensions
316                 --without-ensurepip
317                 --without-lto
318                 --with-system-expat
319                 --with-system-ffi
320                 --with-system-libmpdec
321                 --with-wheel-pkg-dir="${EPREFIX}"/usr/lib/python/ensurepip
323                 $(use_with debug assertions)
324                 $(use_enable pgo optimizations)
325                 $(use_with valgrind)
326         )
328         # disable implicit optimization/debugging flags
329         local -x OPT=
331         # https://bugs.gentoo.org/700012
332         if tc-is-lto; then
333                 append-cflags $(test-flags-CC -ffat-lto-objects)
334                 myeconfargs+=(
335                         --with-lto
336                 )
337         fi
339         if tc-is-cross-compiler ; then
340                 # Hack to workaround get_libdir not being able to handle CBUILD, bug #794181
341                 local cbuild_libdir=$(unset PKG_CONFIG_PATH ; $(tc-getBUILD_PKG_CONFIG) --keep-system-libs --libs-only-L libffi)
343                 # pass system CFLAGS & LDFLAGS as _NODIST, otherwise they'll get
344                 # propagated to sysconfig for built extensions
345                 #
346                 # -fno-lto to avoid bug #700012 (not like it matters for mini-CBUILD Python anyway)
347                 local -x CFLAGS_NODIST="${BUILD_CFLAGS} -fno-lto"
348                 local -x LDFLAGS_NODIST=${BUILD_LDFLAGS}
349                 local -x CFLAGS= LDFLAGS=
350                 local -x BUILD_CFLAGS="${CFLAGS_NODIST}"
351                 local -x BUILD_LDFLAGS=${LDFLAGS_NODIST}
353                 # We need to build our own Python on CBUILD first, and feed it in.
354                 # bug #847910 and bug #864911.
355                 local myeconfargs_cbuild=(
356                         "${myeconfargs[@]}"
358                         --libdir="${cbuild_libdir:2}"
360                         # Avoid needing to load the right libpython.so.
361                         --disable-shared
363                         # As minimal as possible for the mini CBUILD Python
364                         # we build just for cross.
365                         --without-lto
366                         --disable-optimizations
367                 )
369                 # Point the imminent CHOST build to the Python we just
370                 # built for CBUILD.
371                 export PATH="${WORKDIR}/${P}-${CBUILD}:${PATH}"
373                 mkdir "${WORKDIR}"/${P}-${CBUILD} || die
374                 pushd "${WORKDIR}"/${P}-${CBUILD} &> /dev/null || die
375                 # We disable _ctypes and _crypt for CBUILD because Python's setup.py can't handle locating
376                 # libdir correctly for cross.
377                 PYTHON_DISABLE_MODULES="${PYTHON_DISABLE_MODULES} _ctypes _crypt" \
378                         ECONF_SOURCE="${S}" econf_build "${myeconfargs_cbuild[@]}"
380                 # Avoid as many dependencies as possible for the cross build.
381                 cat >> Makefile <<-EOF || die
382                         MODULE_NIS=disabled
383                         MODULE__DBM=disabled
384                         MODULE__GDBM=disabled
385                         MODULE__DBM=disabled
386                         MODULE__SQLITE3=disabled
387                         MODULE__HASHLIB=disabled
388                         MODULE__SSL=disabled
389                         MODULE__CURSES=disabled
390                         MODULE__CURSES_PANEL=disabled
391                         MODULE_READLINE=disabled
392                         MODULE__TKINTER=disabled
393                         MODULE_PYEXPAT=disabled
394                         MODULE_ZLIB=disabled
395                 EOF
397                 # Unfortunately, we do have to build this immediately, and
398                 # not in src_compile, because CHOST configure for Python
399                 # will check the existence of the Python it was pointed to
400                 # immediately.
401                 PYTHON_DISABLE_MODULES="${PYTHON_DISABLE_MODULES} _ctypes _crypt" emake
402                 popd &> /dev/null || die
403         fi
405         # pass system CFLAGS & LDFLAGS as _NODIST, otherwise they'll get
406         # propagated to sysconfig for built extensions
407         local -x CFLAGS_NODIST=${CFLAGS}
408         local -x LDFLAGS_NODIST=${LDFLAGS}
409         local -x CFLAGS= LDFLAGS=
411         # Fix implicit declarations on cross and prefix builds. Bug #674070.
412         if use ncurses; then
413                 append-cppflags -I"${ESYSROOT}"/usr/include/ncursesw
414         fi
416         hprefixify setup.py
417         econf "${myeconfargs[@]}"
419         if grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
420                 eerror "configure has detected that the sem_open function is broken."
421                 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
422                 die "Broken sem_open function (bug 496328)"
423         fi
425         # install epython.py as part of stdlib
426         echo "EPYTHON='python${PYVER}'" > Lib/epython.py || die
429 src_compile() {
430         # Ensure sed works as expected
431         # https://bugs.gentoo.org/594768
432         local -x LC_ALL=C
433         # Prevent using distutils bundled by setuptools.
434         # https://bugs.gentoo.org/823728
435         export SETUPTOOLS_USE_DISTUTILS=stdlib
437         # Save PYTHONDONTWRITEBYTECODE so that 'has_version' doesn't
438         # end up writing bytecode & violating sandbox.
439         # bug #831897
440         local -x _PYTHONDONTWRITEBYTECODE=${PYTHONDONTWRITEBYTECODE}
442         # Gentoo hack to disable accessing system site-packages
443         export GENTOO_CPYTHON_BUILD=1
445         if use pgo ; then
446                 # bug 660358
447                 local -x COLUMNS=80
448                 local -x PYTHONDONTWRITEBYTECODE=
449                 local -x TMPDIR=/tmp
450         fi
452         # also need to clear the flags explicitly here or they end up
453         # in _sysconfigdata*
454         emake CPPFLAGS= CFLAGS= LDFLAGS=
456         # Restore saved value from above.
457         local -x PYTHONDONTWRITEBYTECODE=${_PYTHONDONTWRITEBYTECODE}
459         # Work around bug 329499. See also bug 413751 and 457194.
460         if has_version dev-libs/libffi[pax-kernel]; then
461                 pax-mark E python
462         else
463                 pax-mark m python
464         fi
467 src_test() {
468         # Tests will not work when cross compiling.
469         if tc-is-cross-compiler; then
470                 elog "Disabling tests due to crosscompiling."
471                 return
472         fi
474         local test_opts=(
475                 --verbose3
476                 -u-network
477                 -j "$(makeopts_jobs)"
478                 "${COMMON_TEST_SKIPS[@]}"
479         )
481         # bug 660358
482         local -x COLUMNS=80
483         local -x PYTHONDONTWRITEBYTECODE=
484         local -x TMPDIR=/tmp
486         nonfatal emake -Onone test EXTRATESTOPTS="${test_opts[*]}" \
487                 CPPFLAGS= CFLAGS= LDFLAGS= < /dev/tty
488         local ret=${?}
490         [[ ${ret} -eq 0 ]] || die "emake test failed"
493 src_install() {
494         local libdir=${ED}/usr/lib/python${PYVER}
496         emake DESTDIR="${D}" altinstall
498         # Remove static library
499         rm "${ED}"/usr/$(get_libdir)/libpython*.a || die
501         # Fix collisions between different slots of Python.
502         rm "${ED}/usr/$(get_libdir)/libpython3.so" || die
504         # Cheap hack to get version with ABIFLAGS
505         local abiver=$(cd "${ED}/usr/include"; echo python*)
506         if [[ ${abiver} != python${PYVER} ]]; then
507                 # Replace python3.X with a symlink to python3.Xm
508                 rm "${ED}/usr/bin/python${PYVER}" || die
509                 dosym "${abiver}" "/usr/bin/python${PYVER}"
510                 # Create python3.X-config symlink
511                 dosym "${abiver}-config" "/usr/bin/python${PYVER}-config"
512                 # Create python-3.5m.pc symlink
513                 dosym "python-${PYVER}.pc" "/usr/$(get_libdir)/pkgconfig/${abiver/${PYVER}/-${PYVER}}.pc"
514         fi
516         # python seems to get rebuilt in src_install (bug 569908)
517         # Work around it for now.
518         if has_version dev-libs/libffi[pax-kernel]; then
519                 pax-mark E "${ED}/usr/bin/${abiver}"
520         else
521                 pax-mark m "${ED}/usr/bin/${abiver}"
522         fi
524         rm -r "${libdir}"/ensurepip/_bundled || die
525         if ! use ensurepip; then
526                 rm -r "${libdir}"/ensurepip || die
527         fi
528         if ! use sqlite; then
529                 rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
530         fi
531         if ! use tk; then
532                 rm -r "${ED}/usr/bin/idle${PYVER}" || die
533                 rm -r "${libdir}/"{idlelib,tkinter,test/test_tk*} || die
534         fi
536         ln -s ../python/EXTERNALLY-MANAGED "${libdir}/EXTERNALLY-MANAGED" || die
538         dodoc Misc/{ACKS,HISTORY,NEWS}
540         if use examples; then
541                 docinto examples
542                 find Tools -name __pycache__ -exec rm -fr {} + || die
543                 dodoc -r Tools
544         fi
545         insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
546         local libname=$(
547                 printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' |
548                 emake --no-print-directory -s -f - 2>/dev/null
549         )
550         newins Tools/gdb/libpython.py "${libname}"-gdb.py
552         newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER}
553         newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
554         sed \
555                 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${PYVER/./_}_PORT:" \
556                 -e "s:@PYDOC@:pydoc${PYVER}:" \
557                 -i "${ED}/etc/conf.d/pydoc-${PYVER}" \
558                 "${ED}/etc/init.d/pydoc-${PYVER}" || die "sed failed"
560         # python-exec wrapping support
561         local pymajor=${PYVER%.*}
562         local EPYTHON=python${PYVER}
563         local scriptdir=${D}$(python_get_scriptdir)
564         mkdir -p "${scriptdir}" || die
565         # python and pythonX
566         ln -s "../../../bin/${abiver}" "${scriptdir}/python${pymajor}" || die
567         ln -s "python${pymajor}" "${scriptdir}/python" || die
568         # python-config and pythonX-config
569         # note: we need to create a wrapper rather than symlinking it due
570         # to some random dirname(argv[0]) magic performed by python-config
571         cat > "${scriptdir}/python${pymajor}-config" <<-EOF || die
572                 #!/bin/sh
573                 exec "${abiver}-config" "\${@}"
574         EOF
575         chmod +x "${scriptdir}/python${pymajor}-config" || die
576         ln -s "python${pymajor}-config" "${scriptdir}/python-config" || die
577         # 2to3, pydoc
578         ln -s "../../../bin/2to3-${PYVER}" "${scriptdir}/2to3" || die
579         ln -s "../../../bin/pydoc${PYVER}" "${scriptdir}/pydoc" || die
580         # idle
581         if use tk; then
582                 ln -s "../../../bin/idle${PYVER}" "${scriptdir}/idle" || die
583         fi