public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: python@gentoo.org, dev-portage@entoo.org,
	"Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH 1/3] distutils-r1.eclass: Depend on setuptools by default
Date: Fri, 29 Nov 2019 14:32:11 +0100	[thread overview]
Message-ID: <20191129133213.137173-1-mgorny@gentoo.org> (raw)

Add a new DISTUTILS_USE_SETUPTOOLS top variable, and make it default
to BDEPEND-ing on dev-python/setuptools (which should be correct
for the majority of packages).  Packages that either need RDEPEND
or no dependency at all can override it.

Also add a check for correct value in esetup.py.  This should make it
easy for developers to adjust the new variable in their packages.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 eclass/distutils-r1.eclass | 82 +++++++++++++++++++++++++++++++++++---
 1 file changed, 76 insertions(+), 6 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index f44f0aee9c21..083a72bd0589 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -77,9 +77,23 @@ esac
 # to be exported. It must be run in order for the eclass functions
 # to function properly.
 
+# @ECLASS-VARIABLE: DISTUTILS_USE_SETUPTOOLS
+# @PRE_INHERIT
+# @DESCRIPTION:
+# Controls adding dev-python/setuptools dependency.  The allowed values
+# are:
+#
+# - no -- do not add the dependency (pure distutils package)
+# - bdepend -- add it to BDEPEND (the default)
+# - rdepend -- add it to BDEPEND+RDEPEND (when using entry_points)
+#
+# This variable is effective only if DISTUTILS_OPTIONAL is disabled.
+# It needs to be set before the inherit line.
+: ${DISTUTILS_USE_SETUPTOOLS:=bdepend}
+
 if [[ ! ${_DISTUTILS_R1} ]]; then
 
-[[ ${EAPI} == [45] ]] && inherit eutils
+[[ ${EAPI} == [456] ]] && inherit eutils
 [[ ${EAPI} == [56] ]] && inherit xdg-utils
 inherit multiprocessing toolchain-funcs
 
@@ -97,15 +111,35 @@ fi
 
 if [[ ! ${_DISTUTILS_R1} ]]; then
 
-if [[ ! ${DISTUTILS_OPTIONAL} ]]; then
-	RDEPEND=${PYTHON_DEPS}
+_distutils_set_globals() {
+	local rdep=${PYTHON_DEPS}
+	local bdep=${rdep}
+
+	case ${DISTUTILS_USE_SETUPTOOLS} in
+		no)
+			;;
+		bdepend)
+			bdep+=" dev-python/setuptools[${PYTHON_USEDEP}]"
+			;;
+		rdepend)
+			bdep+=" dev-python/setuptools[${PYTHON_USEDEP}]"
+			rdep+=" dev-python/setuptools[${PYTHON_USEDEP}]"
+			;;
+		*)
+			die "Invalid DISTUTILS_USE_SETUPTOOLS=${DISTUTILS_USE_SETUPTOOLS}"
+			;;
+	esac
+
+	RDEPEND=${rdep}
 	if [[ ${EAPI} != [56] ]]; then
-		BDEPEND=${PYTHON_DEPS}
+		BDEPEND=${bdep}
 	else
-		DEPEND=${PYTHON_DEPS}
+		DEPEND=${bdep}
 	fi
 	REQUIRED_USE=${PYTHON_REQUIRED_USE}
-fi
+}
+[[ ! ${DISTUTILS_OPTIONAL} ]] && _distutils_set_globals
+unset -f _distutils_set_globals
 
 # @ECLASS-VARIABLE: PATCHES
 # @DEFAULT_UNSET
@@ -395,6 +429,41 @@ 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
+
+	# 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
+		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: [<args>...]
 # @DESCRIPTION:
@@ -417,6 +486,7 @@ 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.24.0



             reply	other threads:[~2019-11-29 13:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-29 13:32 Michał Górny [this message]
2019-11-29 13:32 ` [gentoo-dev] [PATCH 2/3] dev-python/setuptools: Disable setuptools self-dependency Michał Górny
2019-11-29 13:32 ` [gentoo-dev] [PATCH 3/3] sys-apps/portage: Disable setuptools dependency Michał Górny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191129133213.137173-1-mgorny@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=dev-portage@entoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    --cc=python@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox