Diff python-2.7.18_p16-r1 with a python-3.8.18

/usr/portage/dev-lang/python/python-3.8.18.ebuild 2023-10-09 14:52:29.472368350 +0300
4 4
EAPI="7"
5 5
WANT_LIBTOOL="none"
6 6

  
7
inherit autotools flag-o-matic pax-utils toolchain-funcs verify-sig
7
inherit autotools flag-o-matic multiprocessing pax-utils
8
inherit prefix python-utils-r1 toolchain-funcs verify-sig
8 9

  
9
MY_P="Python-${PV%_p*}"
10
MY_PV=${PV/_rc/rc}
11
MY_P="Python-${MY_PV%_p*}"
10 12
PYVER=$(ver_cut 1-2)
11
PATCHSET="python-gentoo-patches-${PV}"
13
PATCHSET="python-gentoo-patches-${MY_PV}"
12 14

  
13 15
DESCRIPTION="An interpreted, interactive, object-oriented programming language"
14 16
HOMEPAGE="
15 17
	https://www.python.org/
16 18
	https://github.com/python/cpython/
17
	https://gitweb.gentoo.org/fork/cpython.git/
18 19
"
19 20
SRC_URI="
20
	https://www.python.org/ftp/python/${PV%_*}/${MY_P}.tar.xz
21
	https://www.python.org/ftp/python/${PV%%_*}/${MY_P}.tar.xz
21 22
	https://dev.gentoo.org/~mgorny/dist/python/${PATCHSET}.tar.xz
22 23
	verify-sig? (
23
		https://www.python.org/ftp/python/${PV%_*}/${MY_P}.tar.xz.asc
24
		https://www.python.org/ftp/python/${PV%%_*}/${MY_P}.tar.xz.asc
24 25
	)
25 26
"
26 27
S="${WORKDIR}/${MY_P}"
......
29 30
SLOT="${PYVER}"
30 31
KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~loong ~m68k ~mips ppc ppc64 ~riscv ~s390 sparc x86"
31 32
IUSE="
32
	berkdb bluetooth build examples gdbm +ncurses +readline
33
	+sqlite +ssl tk valgrind wininst +xml
33
	bluetooth build debug +ensurepip examples gdbm lto +ncurses pgo
34
	+readline +sqlite +ssl test tk valgrind wininst +xml
34 35
"
35
RESTRICT="test"
36
RESTRICT="!test? ( test )"
36 37

  
37 38
# Do not add a dependency on dev-lang/python to this ebuild.
38 39
# If you need to apply a patch which requires python for bootstrapping, please
......
41 42

  
42 43
RDEPEND="
43 44
	app-arch/bzip2:=
45
	app-arch/xz-utils:=
44 46
	dev-libs/libffi:=
45 47
	>=sys-libs/zlib-1.1.3:=
46 48
	virtual/libcrypt:=
47 49
	virtual/libintl
48
	berkdb? ( || (
49
		sys-libs/db:5.3
50
		sys-libs/db:4.8
51
	) )
50
	ensurepip? ( dev-python/ensurepip-wheels )
52 51
	gdbm? ( sys-libs/gdbm:=[berkdb] )
52
	kernel_linux? ( sys-apps/util-linux:= )
53 53
	ncurses? ( >=sys-libs/ncurses-5.2:= )
54 54
	readline? ( >=sys-libs/readline-4.1:= )
55 55
	sqlite? ( >=dev-db/sqlite-3.3.8:3= )
56
	ssl? ( dev-libs/openssl:= )
56
	ssl? ( >=dev-libs/openssl-1.1.1:= )
57 57
	tk? (
58 58
		>=dev-lang/tcl-8.0:=
59 59
		>=dev-lang/tk-8.0:=
......
66 66
DEPEND="
67 67
	${RDEPEND}
68 68
	bluetooth? ( net-wireless/bluez )
69
	test? ( app-arch/xz-utils[extra-filters(+)] )
69 70
	valgrind? ( dev-util/valgrind )
70 71
"
72
# autoconf-archive needed to eautoreconf
71 73
BDEPEND="
74
	sys-devel/autoconf-archive
72 75
	app-alternatives/awk
73 76
	virtual/pkgconfig
74 77
	verify-sig? ( sec-keys/openpgp-keys-python )
......
83 86
# false positives -- functions specific to *BSD
84 87
QA_CONFIG_IMPL_DECL_SKIP=( chflags lchflags )
85 88

  
86
pkg_setup() {
87
	if use berkdb; then
88
		ewarn "'bsddb' module is out-of-date and no longer maintained inside"
89
		ewarn "dev-lang/python. 'bsddb' and 'dbhash' modules have been additionally"
90
		ewarn "removed in Python 3. A maintained alternative of 'bsddb3' module"
91
		ewarn "is provided by dev-python/bsddb3."
92
	fi
93
}
94

  
95 89
src_unpack() {
96 90
	if use verify-sig; then
97 91
		verify-sig_verify_detached "${DISTDIR}"/${MY_P}.tar.xz{,.asc}
......
100 94
}
101 95

  
102 96
src_prepare() {
103
	# Ensure that internal copies of expat, libffi and zlib are not used.
97
	# Ensure that internal copies of expat and libffi are not used.
104 98
	rm -r Modules/expat || die
105 99
	rm -r Modules/_ctypes/libffi* || die
106
	rm -r Modules/zlib || die
107 100

  
108 101
	local PATCHES=(
109 102
		"${WORKDIR}/${PATCHSET}"
......
111 104

  
112 105
	default
113 106

  
114
	sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
115
		Lib/distutils/command/install.py \
116
		Lib/distutils/sysconfig.py \
117
		Lib/site.py \
118
		Lib/sysconfig.py \
119
		Lib/test/test_site.py \
120
		Makefile.pre.in \
121
		Modules/Setup.dist \
122
		Modules/getpath.c \
123
		setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
107
	# https://bugs.gentoo.org/850151
108
	sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" setup.py || die
109

  
110
	# force the correct number of jobs
111
	# https://bugs.gentoo.org/737660
112
	local jobs=$(makeopts_jobs)
113
	sed -i -e "s:-j0:-j${jobs}:" Makefile.pre.in || die
114
	sed -i -e "/self\.parallel/s:True:${jobs}:" setup.py || die
124 115

  
125 116
	if ! use wininst; then
126 117
		rm Lib/distutils/command/wininst*.exe || die
......
130 121
}
131 122

  
132 123
src_configure() {
133
	# dbm module can be linked against berkdb or gdbm.
134
	# Defaults to gdbm when both are enabled, #204343.
135
	local disable
136
	use berkdb    || use gdbm || disable+=" dbm"
137
	use berkdb    || disable+=" _bsddb"
138 124
	# disable automagic bluetooth headers detection
139
	use bluetooth || export ac_cv_header_bluetooth_bluetooth_h=no
125
	if ! use bluetooth; then
126
		local -x ac_cv_header_bluetooth_bluetooth_h=no
127
	fi
128
	local disable
140 129
	use gdbm      || disable+=" gdbm"
141 130
	use ncurses   || disable+=" _curses _curses_panel"
142 131
	use readline  || disable+=" readline"
......
160 149

  
161 150
	filter-flags -malign-double
162 151

  
163
	if tc-is-cross-compiler; then
164
		# Force some tests that try to poke fs paths.
165
		export ac_cv_file__dev_ptc=no
166
		export ac_cv_file__dev_ptmx=yes
152
	# https://bugs.gentoo.org/700012
153
	if is-flagq -flto || is-flagq '-flto=*'; then
154
		append-cflags $(test-flags-CC -ffat-lto-objects)
167 155
	fi
168 156

  
169
	# Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
170
	tc-export CXX
171
	# The configure script fails to use pkg-config correctly.
172
	# http://bugs.python.org/issue15506
173
	export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
157
	# Export CXX so it ends up in /usr/lib/python3.X/config/Makefile.
158
	# PKG_CONFIG needed for cross.
159
	tc-export CXX PKG_CONFIG
174 160

  
175 161
	local dbmliborder=
176 162
	if use gdbm; then
177 163
		dbmliborder+="${dbmliborder:+:}gdbm"
178 164
	fi
179
	if use berkdb; then
180
		dbmliborder+="${dbmliborder:+:}bdb"
181
	fi
182 165

  
183 166
	local myeconfargs=(
184
		# The check is broken on clang, and gives false positive:
185
		# https://bugs.gentoo.org/596798
186
		# (upstream dropped this flag in 3.2a4 anyway)
187
		ac_cv_opt_olimit_ok=no
188 167
		# glibc-2.30 removes it; since we can't cleanly force-rebuild
189 168
		# Python on glibc upgrade, remove it proactively to give
190 169
		# a chance for users rebuilding python before glibc
191 170
		ac_cv_header_stropts_h=no
192
		# Test program has missing includes.  This doesn't change
193
		# the result but it's cleaner to force it.
194
		ac_cv_broken_poll=no
195 171

  
196
		--with-fpectl
197 172
		--enable-shared
198 173
		--enable-ipv6
199
		--with-threads
200
		--enable-unicode=ucs4
201 174
		--infodir='${prefix}/share/info'
202 175
		--mandir='${prefix}/share/man'
203 176
		--with-computed-gotos
......
207 180
		--without-ensurepip
208 181
		--with-system-expat
209 182
		--with-system-ffi
183
		--with-wheel-pkg-dir="${EPREFIX}"/usr/lib/python/ensurepip
210 184

  
185
		$(use_with debug assertions)
211 186
		$(use_with valgrind)
212 187
	)
213 188

  
214 189
	# disable implicit optimization/debugging flags
215 190
	local -x OPT=
191

  
192
	if tc-is-cross-compiler ; then
193
		# Hack to workaround get_libdir not being able to handle CBUILD, bug #794181
194
		local cbuild_libdir=$(unset PKG_CONFIG_PATH ; $(tc-getBUILD_PKG_CONFIG) --keep-system-libs --libs-only-L libffi)
195

  
196
		# pass system CFLAGS & LDFLAGS as _NODIST, otherwise they'll get
197
		# propagated to sysconfig for built extensions
198
		#
199
		# -fno-lto to avoid bug #700012 (not like it matters for mini-CBUILD Python anyway)
200
		local -x CFLAGS_NODIST="${BUILD_CFLAGS} -fno-lto"
201
		local -x LDFLAGS_NODIST=${BUILD_LDFLAGS}
202
		local -x CFLAGS= LDFLAGS=
203
		local -x BUILD_CFLAGS="${CFLAGS_NODIST}"
204
		local -x BUILD_LDFLAGS=${LDFLAGS_NODIST}
205

  
206
		# We need to build our own Python on CBUILD first, and feed it in.
207
		# bug #847910 and bug #864911.
208
		local myeconfargs_cbuild=(
209
			"${myeconfargs[@]}"
210

  
211
			--libdir="${cbuild_libdir:2}"
212

  
213
			# Avoid needing to load the right libpython.so.
214
			--disable-shared
215

  
216
			# As minimal as possible for the mini CBUILD Python
217
			# we build just for cross.
218
			--without-lto
219
			--disable-optimizations
220
		)
221

  
222
		# Point the imminent CHOST build to the Python we just
223
		# built for CBUILD.
224
		export PATH="${WORKDIR}/${P}-${CBUILD}:${PATH}"
225

  
226
		mkdir "${WORKDIR}"/${P}-${CBUILD} || die
227
		pushd "${WORKDIR}"/${P}-${CBUILD} &> /dev/null || die
228
		# We disable _ctypes and _crypt for CBUILD because Python's setup.py can't handle locating
229
		# libdir correctly for cross.
230
		PYTHON_DISABLE_MODULES="${PYTHON_DISABLE_MODULES} _ctypes _crypt" \
231
			ECONF_SOURCE="${S}" econf_build "${myeconfargs_cbuild[@]}"
232

  
233
		# Avoid as many dependencies as possible for the cross build.
234
		cat >> Makefile <<-EOF || die
235
			MODULE_NIS=disabled
236
			MODULE__DBM=disabled
237
			MODULE__GDBM=disabled
238
			MODULE__DBM=disabled
239
			MODULE__SQLITE3=disabled
240
			MODULE__HASHLIB=disabled
241
			MODULE__SSL=disabled
242
			MODULE__CURSES=disabled
243
			MODULE__CURSES_PANEL=disabled
244
			MODULE_READLINE=disabled
245
			MODULE__TKINTER=disabled
246
			MODULE_PYEXPAT=disabled
247
			MODULE_ZLIB=disabled
248
		EOF
249

  
250
		# Unfortunately, we do have to build this immediately, and
251
		# not in src_compile, because CHOST configure for Python
252
		# will check the existence of the Python it was pointed to
253
		# immediately.
254
		PYTHON_DISABLE_MODULES="${PYTHON_DISABLE_MODULES} _ctypes _crypt" emake
255
		popd &> /dev/null || die
256
	fi
257

  
258
	# pass system CFLAGS & LDFLAGS as _NODIST, otherwise they'll get
259
	# propagated to sysconfig for built extensions
260
	local -x CFLAGS_NODIST=${CFLAGS}
261
	local -x LDFLAGS_NODIST=${LDFLAGS}
262
	local -x CFLAGS= LDFLAGS=
263

  
264
	# Fix implicit declarations on cross and prefix builds. Bug #674070.
265
	if use ncurses; then
266
		append-cppflags -I"${ESYSROOT}"/usr/include/ncursesw
267
	fi
268

  
269
	hprefixify setup.py
216 270
	econf "${myeconfargs[@]}"
217 271

  
218 272
	if grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
......
229 283
	# Ensure sed works as expected
230 284
	# https://bugs.gentoo.org/594768
231 285
	local -x LC_ALL=C
232

  
233
	# Avoid invoking pgen for cross-compiles.
234
	touch Include/graminit.h Python/graminit.c || die
235

  
236
	emake
286
	# Prevent using distutils bundled by setuptools.
287
	# https://bugs.gentoo.org/823728
288
	export SETUPTOOLS_USE_DISTUTILS=stdlib
289

  
290
	# also need to clear the flags explicitly here or they end up
291
	# in _sysconfigdata*
292
	emake CPPFLAGS= CFLAGS= LDFLAGS=
237 293

  
238 294
	# Work around bug 329499. See also bug 413751 and 457194.
239 295
	if has_version dev-libs/libffi[pax-kernel]; then
......
250 306
		return
251 307
	fi
252 308

  
253
	# Skip failing tests.
254
	local skipped_tests=( distutils gdb )
309
	local test_opts=(
310
		-u-network
311
		-j "$(makeopts_jobs)"
255 312

  
256
	for test in "${skipped_tests[@]}"; do
257
		mv Lib/test/test_${test}.py "${T}"/ || die
258
	done
313
		# fails
314
		-x test_gdb
315
	)
316

  
317
	if use sparc ; then
318
		# bug #788022
319
		test_opts+=(
320
			-x test_multiprocessing_fork
321
			-x test_multiprocessing_forkserver
322
		)
323
	fi
324

  
325
	# workaround docutils breaking tests
326
	cat > Lib/docutils.py <<-EOF || die
327
		raise ImportError("Thou shalt not import!")
328
	EOF
259 329

  
260 330
	# bug 660358
261 331
	local -x COLUMNS=80
332
	local -x PYTHONDONTWRITEBYTECODE=
333

  
334
	nonfatal emake test EXTRATESTOPTS="${test_opts[*]}" \
335
		CPPFLAGS= CFLAGS= LDFLAGS= < /dev/tty
336
	local ret=${?}
262 337

  
263
	# Daylight saving time problem
264
	# https://bugs.python.org/issue22067
265
	# https://bugs.gentoo.org/610628
266
	local -x TZ=UTC
267

  
268
	# Rerun failed tests in verbose mode (regrtest -w).
269
	emake test EXTRATESTOPTS="-w" < /dev/tty
270

  
271
	for test in "${skipped_tests[@]}"; do
272
		mv "${T}/test_${test}.py" Lib/test/ || die
273
	done
338
	rm Lib/docutils.py || die
339

  
340
	[[ ${ret} -eq 0 ]] || die "emake test failed"
274 341
}
275 342

  
276 343
src_install() {
277
	local libdir=${ED}/usr/$(get_libdir)/python${PYVER}
344
	local libdir=${ED}/usr/lib/python${PYVER}
278 345

  
279 346
	emake DESTDIR="${D}" altinstall
280 347

  
281
	sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die
282

  
283 348
	# Remove static library
284 349
	rm "${ED}"/usr/$(get_libdir)/libpython*.a || die
285 350

  
286 351
	# Fix collisions between different slots of Python.
287
	mv "${ED}/usr/bin/2to3" "${ED}/usr/bin/2to3-${PYVER}" || die
288
	mv "${ED}/usr/bin/pydoc" "${ED}/usr/bin/pydoc${PYVER}" || die
289
	mv "${ED}/usr/bin/idle" "${ED}/usr/bin/idle${PYVER}" || die
290
	rm "${ED}/usr/bin/smtpd.py" || die
352
	rm "${ED}/usr/$(get_libdir)/libpython3.so" || die
353

  
354
	# Cheap hack to get version with ABIFLAGS
355
	local abiver=$(cd "${ED}/usr/include"; echo python*)
356
	if [[ ${abiver} != python${PYVER} ]]; then
357
		# Replace python3.X with a symlink to python3.Xm
358
		rm "${ED}/usr/bin/python${PYVER}" || die
359
		dosym "${abiver}" "/usr/bin/python${PYVER}"
360
		# Create python3.X-config symlink
361
		dosym "${abiver}-config" "/usr/bin/python${PYVER}-config"
362
		# Create python-3.5m.pc symlink
363
		dosym "python-${PYVER}.pc" "/usr/$(get_libdir)/pkgconfig/${abiver/${PYVER}/-${PYVER}}.pc"
364
	fi
291 365

  
292
	if ! use berkdb; then
293
		rm -r "${libdir}/"{bsddb,dbhash.py*,test/test_bsddb*} || die
366
	# python seems to get rebuilt in src_install (bug 569908)
367
	# Work around it for now.
368
	if has_version dev-libs/libffi[pax-kernel]; then
369
		pax-mark E "${ED}/usr/bin/${abiver}"
370
	else
371
		pax-mark m "${ED}/usr/bin/${abiver}"
372
	fi
373

  
374
	rm -r "${libdir}"/ensurepip/_bundled || die
375
	if ! use ensurepip; then
376
		rm -r "${libdir}"/ensurepip || die
294 377
	fi
295 378
	if ! use sqlite; then
296 379
		rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
297 380
	fi
298 381
	if ! use tk; then
299 382
		rm -r "${ED}/usr/bin/idle${PYVER}" || die
300
		rm -r "${libdir}/"{idlelib,lib-tk} || die
383
		rm -r "${libdir}/"{idlelib,tkinter,test/test_tk*} || die
301 384
	fi
302 385

  
303 386
	dodoc Misc/{ACKS,HISTORY,NEWS}
304 387

  
305 388
	if use examples; then
306 389
		docinto examples
390
		find Tools -name __pycache__ -exec rm -fr {} + || die
307 391
		dodoc -r Tools
308 392
	fi
393
	insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
394
	local libname=$(
395
		printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' |
396
		emake --no-print-directory -s -f - 2>/dev/null
397
	)
398
	newins Tools/gdb/libpython.py "${libname}"-gdb.py
309 399

  
310 400
	newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER}
311 401
	newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
......
315 405
		-i "${ED}/etc/conf.d/pydoc-${PYVER}" \
316 406
		"${ED}/etc/init.d/pydoc-${PYVER}" || die "sed failed"
317 407

  
318
	# python2* is no longer wrapped, so just symlink it
408
	# python-exec wrapping support
319 409
	local pymajor=${PYVER%.*}
320
	dosym "python${PYVER}" "/usr/bin/python${pymajor}"
321
	dosym "python${PYVER}-config" "/usr/bin/python${pymajor}-config"
410
	local EPYTHON=python${PYVER}
411
	local scriptdir=${D}$(python_get_scriptdir)
412
	mkdir -p "${scriptdir}" || die
413
	# python and pythonX
414
	ln -s "../../../bin/${abiver}" "${scriptdir}/python${pymajor}" || die
415
	ln -s "python${pymajor}" "${scriptdir}/python" || die
416
	# python-config and pythonX-config
417
	# note: we need to create a wrapper rather than symlinking it due
418
	# to some random dirname(argv[0]) magic performed by python-config
419
	cat > "${scriptdir}/python${pymajor}-config" <<-EOF || die
420
		#!/bin/sh
421
		exec "${abiver}-config" "\${@}"
422
	EOF
423
	chmod +x "${scriptdir}/python${pymajor}-config" || die
424
	ln -s "python${pymajor}-config" "${scriptdir}/python-config" || die
425
	# 2to3, pydoc
426
	ln -s "../../../bin/2to3-${PYVER}" "${scriptdir}/2to3" || die
427
	ln -s "../../../bin/pydoc${PYVER}" "${scriptdir}/pydoc" || die
428
	# idle
429
	if use tk; then
430
		ln -s "../../../bin/idle${PYVER}" "${scriptdir}/idle" || die
431
	fi
322 432
}
Thank you!