public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH] distutils-r1.eclass: Report stray top-level files in site-packages
@ 2023-02-05  5:09 Michał Górny
  0 siblings, 0 replies; only message in thread
From: Michał Górny @ 2023-02-05  5:09 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

In addition to checking for known-bad package names, detect stray
files installed into top-level site-packages directory.  This is
primarily meant to cover the common mistake in using `include`
in Poetry-built packages.

Closes: https://bugs.gentoo.org/893172
Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 eclass/distutils-r1.eclass | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 8896768d3ce9..a6be88ad858d 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -171,7 +171,7 @@ esac
 
 if [[ ! ${_DISTUTILS_R1} ]]; then
 
-inherit multibuild multiprocessing ninja-utils toolchain-funcs
+inherit multibuild multilib multiprocessing ninja-utils toolchain-funcs
 
 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
 	inherit python-r1
@@ -1985,12 +1985,34 @@ _distutils-r1_post_python_install() {
 			examples test tests
 			.pytest_cache .hypothesis _trial_temp
 		)
+		local strays=()
 		local p
+		mapfile -d $'\0' -t strays < <(
+			find "${sitedir}" -maxdepth 1 -type f '!' '(' \
+					-name '*.egg-info' -o \
+					-name '*.pth' -o \
+					-name '*.py' -o \
+					-name '*.pyi' -o \
+					-name "*$(get_modname)" \
+				')' -print0
+		)
 		for p in "${forbidden_package_names[@]}"; do
-			if [[ -d ${sitedir}/${p} ]]; then
-				die "Package installs '${p}' package which is forbidden and likely a bug in the build system."
-			fi
+			[[ -d ${sitedir}/${p} ]] && strays+=( "${sitedir}/${p}" )
 		done
+
+		if [[ -n ${strays[@]} ]]; then
+			eerror "The following unexpected files/directories were found top-level"
+			eerror "in the site-packages directory:"
+			eerror
+			for p in "${strays[@]}"; do
+				eerror "  ${p#${ED}}"
+			done
+			eerror
+			eerror "This is most likely a bug in the build system.  More information"
+			eerror "can be found in the Python Guide:"
+			eerror "https://projects.gentoo.org/python/guide/qawarn.html#stray-top-level-files-in-site-packages"
+			die "Failing install because of stray top-level files in site-packages"
+		fi
 	fi
 }
 
-- 
2.39.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-05  5:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-05  5:09 [gentoo-dev] [PATCH] distutils-r1.eclass: Report stray top-level files in site-packages Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox