Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH] distutils-r1.eclass: Report stray top-level files in site-packages
Date: Sun, 05 Feb 2023 05:09:42
Message-Id: 20230205050927.145328-1-mgorny@gentoo.org
1 In addition to checking for known-bad package names, detect stray
2 files installed into top-level site-packages directory. This is
3 primarily meant to cover the common mistake in using `include`
4 in Poetry-built packages.
5
6 Closes: https://bugs.gentoo.org/893172
7 Signed-off-by: Michał Górny <mgorny@g.o>
8 ---
9 eclass/distutils-r1.eclass | 30 ++++++++++++++++++++++++++----
10 1 file changed, 26 insertions(+), 4 deletions(-)
11
12 diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
13 index 8896768d3ce9..a6be88ad858d 100644
14 --- a/eclass/distutils-r1.eclass
15 +++ b/eclass/distutils-r1.eclass
16 @@ -171,7 +171,7 @@ esac
17
18 if [[ ! ${_DISTUTILS_R1} ]]; then
19
20 -inherit multibuild multiprocessing ninja-utils toolchain-funcs
21 +inherit multibuild multilib multiprocessing ninja-utils toolchain-funcs
22
23 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
24 inherit python-r1
25 @@ -1985,12 +1985,34 @@ _distutils-r1_post_python_install() {
26 examples test tests
27 .pytest_cache .hypothesis _trial_temp
28 )
29 + local strays=()
30 local p
31 + mapfile -d $'\0' -t strays < <(
32 + find "${sitedir}" -maxdepth 1 -type f '!' '(' \
33 + -name '*.egg-info' -o \
34 + -name '*.pth' -o \
35 + -name '*.py' -o \
36 + -name '*.pyi' -o \
37 + -name "*$(get_modname)" \
38 + ')' -print0
39 + )
40 for p in "${forbidden_package_names[@]}"; do
41 - if [[ -d ${sitedir}/${p} ]]; then
42 - die "Package installs '${p}' package which is forbidden and likely a bug in the build system."
43 - fi
44 + [[ -d ${sitedir}/${p} ]] && strays+=( "${sitedir}/${p}" )
45 done
46 +
47 + if [[ -n ${strays[@]} ]]; then
48 + eerror "The following unexpected files/directories were found top-level"
49 + eerror "in the site-packages directory:"
50 + eerror
51 + for p in "${strays[@]}"; do
52 + eerror " ${p#${ED}}"
53 + done
54 + eerror
55 + eerror "This is most likely a bug in the build system. More information"
56 + eerror "can be found in the Python Guide:"
57 + eerror "https://projects.gentoo.org/python/guide/qawarn.html#stray-top-level-files-in-site-packages"
58 + die "Failing install because of stray top-level files in site-packages"
59 + fi
60 fi
61 }
62
63 --
64 2.39.1