Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: python@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 1/2] install-qa-check.d: add DISTUTILS_USE_SETUPTOOLS check
Date: Fri, 18 Sep 2020 20:43:41
Message-Id: 20200918204329.1128613-1-mgorny@gentoo.org
1 Move DISTUTILS_USE_SETUPTOOLS check from distutils-r1.eclass to install
2 QA checks, and rewrite it to use installed egg-info rather than greps
3 on input files. This produces less false positives, particularly
4 in packages that use boilerplate empty 'entry_points' in their setup
5 script or configuration file.
6
7 We also no longer require explicit setuptools RDEPEND for packages using
8 other entry point types than console_scripts -- instead, we assume that
9 the package consuming these entry points will bring setuptools
10 as necessary.
11
12 The rough idea is to look at egg-info metadata installed by distutils
13 or setuptools. Plain distutils installs it as a regular file, while
14 setuptools as a directory, and that's how we distinguish the two.
15 For setuptools, we additionally grep entry_points.txt for
16 `[console_scripts]`, and require RDEPEND when they are present.
17
18 Signed-off-by: Michał Górny <mgorny@g.o>
19 ---
20 .../60distutils-use-setuptools | 60 +++++++++++++++++++
21 1 file changed, 60 insertions(+)
22 create mode 100644 metadata/install-qa-check.d/60distutils-use-setuptools
23
24 diff --git a/metadata/install-qa-check.d/60distutils-use-setuptools b/metadata/install-qa-check.d/60distutils-use-setuptools
25 new file mode 100644
26 index 000000000000..db07212cce48
27 --- /dev/null
28 +++ b/metadata/install-qa-check.d/60distutils-use-setuptools
29 @@ -0,0 +1,60 @@
30 +# Copyright 2020 Gentoo Authors
31 +# Distributed under the terms of the GNU General Public License v2
32 +
33 +# QA check: verify correctness of DISTUTILS_USE_SETUPTOOLS
34 +# Maintainer: Python project <python@g.o>
35 +
36 +get_expected_distutils_use_setuptools() {
37 + local sitedir=${D}$(python_get_sitedir)
38 + local egg new_expected
39 + while read -d $'\0' -r egg; do
40 + if [[ -f ${egg} ]]; then
41 + # if .egg-info is a file, it's plain distutils
42 + new_expected=no
43 + elif grep -q -s -F '[console_scripts]' "${egg}"/entry_points.txt
44 + then
45 + # entry_points == we need rdepend
46 + new_expected=rdepend
47 + else
48 + new_expected=bdepend
49 + fi
50 +
51 + if [[ ${expected} && ${new_expected} != ${expected} ]]; then
52 + expected=integrity-error
53 + else
54 + expected=${new_expected}
55 + fi
56 + done < <(find "${sitedir}" -name '*.egg-info' -print0)
57 +}
58 +
59 +distutils_use_setuptools_check() {
60 + # applicable only to ebuilds inheriting distutils-r1
61 + [[ ${_DISTUTILS_R1} ]] || return
62 + # 'manual' means no checking
63 + [[ ${DISTUTILS_USE_SETUPTOOLS} == manual ]] && return
64 + # pyproject.toml is verified by using it
65 + [[ ${DISTUTILS_USE_SETUPTOOLS} == pyproject.toml ]] && return
66 +
67 + local expected
68 + _distutils-r1_run_foreach_impl get_expected_distutils_use_setuptools
69 +
70 + if [[ ${expected} == integrity-error ]]; then
71 + eerror "DISTUTILS_USE_SETUPTOOLS integrity error!"
72 + eerror "expected was: ${expected}"
73 + eerror "new_expected is: ${new_expected}"
74 + eerror "Please report a bug about this and CC python@"
75 + elif [[ ${DISTUTILS_USE_SETUPTOOLS} != ${expected} ]]; then
76 + local def=
77 + [[ ${DISTUTILS_USE_SETUPTOOLS} == bdepend ]] && def=' (or unset)'
78 +
79 + eqawarn "DISTUTILS_USE_SETUPTOOLS value is probably incorrect"
80 + eqawarn " have: DISTUTILS_USE_SETUPTOOLS=${DISTUTILS_USE_SETUPTOOLS}${def}"
81 + eqawarn " expected: DISTUTILS_USE_SETUPTOOLS=${expected}"
82 + fi
83 +}
84 +
85 +distutils_use_setuptools_check
86 +
87 +: # guarantee successful exit
88 +
89 +# vim:ft=ebuild
90 --
91 2.28.0

Replies