[gentoo-dev] [PATCH 2/2] distutils-r1.eclass: Remove obsolete DISTUTILS_USE_SETUPTOOLS check

2020-09-18 Thread Michał Górny
The DISTUTILS_USE_SETUPTOOLS check is now done in install-qa-check.d,
so remove the duplicate.

Signed-off-by: Michał Górny 
---
 eclass/distutils-r1.eclass | 42 --
 1 file changed, 42 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index e0e7a945ab87..25cb67b78a31 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -455,47 +455,6 @@ distutils_enable_tests() {
return 0
 }
 
-# @FUNCTION: _distutils-r1_verify_use_setuptools
-# @INTERNAL
-# @DESCRIPTION:
-# Check setup.py for signs that DISTUTILS_USE_SETUPTOOLS have been set
-# incorrectly.
-_distutils_verify_use_setuptools() {
-   [[ ${DISTUTILS_OPTIONAL} ]] && return
-   [[ ${DISTUTILS_USE_SETUPTOOLS} == manual ]] && return
-   [[ ${DISTUTILS_USE_SETUPTOOLS} == pyproject.toml ]] && return
-
-   # ok, those are cheap greps.  we can try toimprove them if we hit
-   # false positives.
-   local expected=no
-   if [[ ${CATEGORY}/${PN} == dev-python/setuptools ]]; then
-   # as a special case, setuptools provides itself ;-)
-   :
-   elif grep -E -q -s '(from|import)\s+setuptools' setup.py; then
-   if grep -E -q -s 'entry_points\s*=' setup.py; then
-   expected=rdepend
-   elif grep -F -q -s '[options.entry_points]' setup.cfg; then
-   expected=rdepend
-   elif grep -F -q -s '[entry_points]' setup.cfg; then  # pbr
-   expected=rdepend
-   else
-   expected=bdepend
-   fi
-   fi
-
-   if [[ ${DISTUTILS_USE_SETUPTOOLS} != ${expected} ]]; then
-   if [[ ! ${_DISTUTILS_SETUPTOOLS_WARNED} ]]; then
-   _DISTUTILS_SETUPTOOLS_WARNED=1
-   local def=
-   [[ ${DISTUTILS_USE_SETUPTOOLS} == bdepend ]] && def=' 
(default?)'
-
-   eqawarn "DISTUTILS_USE_SETUPTOOLS value is probably 
incorrect"
-   eqawarn "  value:
DISTUTILS_USE_SETUPTOOLS=${DISTUTILS_USE_SETUPTOOLS}${def}"
-   eqawarn "  expected: 
DISTUTILS_USE_SETUPTOOLS=${expected}"
-   fi
-   fi
-}
-
 # @FUNCTION: esetup.py
 # @USAGE: [...]
 # @DESCRIPTION:
@@ -518,7 +477,6 @@ esetup.py() {
[[ ${EAPI} != [45] ]] && die_args+=( -n )
 
[[ ${BUILD_DIR} ]] && _distutils-r1_create_setup_cfg
-   _distutils_verify_use_setuptools
 
set -- "${EPYTHON:-python}" setup.py "${mydistutilsargs[@]}" "${@}"
 
-- 
2.28.0




[gentoo-dev] [PATCH 1/2] install-qa-check.d: add DISTUTILS_USE_SETUPTOOLS check

2020-09-18 Thread Michał Górny
Move DISTUTILS_USE_SETUPTOOLS check from distutils-r1.eclass to install
QA checks, and rewrite it to use installed egg-info rather than greps
on input files.  This produces less false positives, particularly
in packages that use boilerplate empty 'entry_points' in their setup
script or configuration file.

We also no longer require explicit setuptools RDEPEND for packages using
other entry point types than console_scripts -- instead, we assume that
the package consuming these entry points will bring setuptools
as necessary.

The rough idea is to look at egg-info metadata installed by distutils
or setuptools.  Plain distutils installs it as a regular file, while
setuptools as a directory, and that's how we distinguish the two.
For setuptools, we additionally grep entry_points.txt for
`[console_scripts]`, and require RDEPEND when they are present.

Signed-off-by: Michał Górny 
---
 .../60distutils-use-setuptools| 60 +++
 1 file changed, 60 insertions(+)
 create mode 100644 metadata/install-qa-check.d/60distutils-use-setuptools

diff --git a/metadata/install-qa-check.d/60distutils-use-setuptools 
b/metadata/install-qa-check.d/60distutils-use-setuptools
new file mode 100644
index ..db07212cce48
--- /dev/null
+++ b/metadata/install-qa-check.d/60distutils-use-setuptools
@@ -0,0 +1,60 @@
+# Copyright 2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# QA check: verify correctness of DISTUTILS_USE_SETUPTOOLS
+# Maintainer: Python project 
+
+get_expected_distutils_use_setuptools() {
+   local sitedir=${D}$(python_get_sitedir)
+   local egg new_expected
+   while read -d $'\0' -r egg; do
+   if [[ -f ${egg} ]]; then
+   # if .egg-info is a file, it's plain distutils
+   new_expected=no
+   elif grep -q -s -F '[console_scripts]' "${egg}"/entry_points.txt
+   then
+   # entry_points == we need rdepend
+   new_expected=rdepend
+   else
+   new_expected=bdepend
+   fi
+
+   if [[ ${expected} && ${new_expected} != ${expected} ]]; then
+   expected=integrity-error
+   else
+   expected=${new_expected}
+   fi
+   done < <(find "${sitedir}" -name '*.egg-info' -print0)
+}
+
+distutils_use_setuptools_check() {
+   # applicable only to ebuilds inheriting distutils-r1
+   [[ ${_DISTUTILS_R1} ]] || return
+   # 'manual' means no checking
+   [[ ${DISTUTILS_USE_SETUPTOOLS} == manual ]] && return
+   # pyproject.toml is verified by using it
+   [[ ${DISTUTILS_USE_SETUPTOOLS} == pyproject.toml ]] && return
+
+   local expected
+   _distutils-r1_run_foreach_impl get_expected_distutils_use_setuptools
+
+   if [[ ${expected} == integrity-error ]]; then
+   eerror "DISTUTILS_USE_SETUPTOOLS integrity error!"
+   eerror "expected was:${expected}"
+   eerror "new_expected is: ${new_expected}"
+   eerror "Please report a bug about this and CC python@"
+   elif [[ ${DISTUTILS_USE_SETUPTOOLS} != ${expected} ]]; then
+   local def=
+   [[ ${DISTUTILS_USE_SETUPTOOLS} == bdepend ]] && def=' 
(or unset)'
+
+   eqawarn "DISTUTILS_USE_SETUPTOOLS value is probably 
incorrect"
+   eqawarn "  have: 
DISTUTILS_USE_SETUPTOOLS=${DISTUTILS_USE_SETUPTOOLS}${def}"
+   eqawarn "  expected: 
DISTUTILS_USE_SETUPTOOLS=${expected}"
+   fi
+}
+
+distutils_use_setuptools_check
+
+: # guarantee successful exit
+
+# vim:ft=ebuild
-- 
2.28.0