From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id EA42C15800F for ; Fri, 3 Feb 2023 13:03:55 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 30F10E0809; Fri, 3 Feb 2023 13:03:55 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 1AB1CE0809 for ; Fri, 3 Feb 2023 13:03:54 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 03B9E340D3A for ; Fri, 3 Feb 2023 13:03:54 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 6EAB8889 for ; Fri, 3 Feb 2023 13:03:52 +0000 (UTC) From: "Arthur Zamarin" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Arthur Zamarin" Message-ID: <1675429415.87226810dca088b8eec5d03639b3d830293c82aa.arthurzam@gentoo> Subject: [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: src/pkgcheck/checks/, ... X-VCS-Repository: proj/pkgcore/pkgcheck X-VCS-Files: src/pkgcheck/checks/python.py testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/expected.json testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/fix.patch testdata/repos/python/PythonCheck/PythonMissingSCMDependency/PythonMissingSCMDependency-0.ebuild testdata/repos/python/PythonCheck/PythonMissingSCMDependency/metadata.xml X-VCS-Directories: testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/ src/pkgcheck/checks/ testdata/repos/python/PythonCheck/PythonMissingSCMDependency/ X-VCS-Committer: arthurzam X-VCS-Committer-Name: Arthur Zamarin X-VCS-Revision: 87226810dca088b8eec5d03639b3d830293c82aa X-VCS-Branch: master Date: Fri, 3 Feb 2023 13:03:52 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: a1505ac1-8095-4cc3-8c0c-cd184955b6a2 X-Archives-Hash: 976e43d56755d59b2c99732b08dd21a6 commit: 87226810dca088b8eec5d03639b3d830293c82aa Author: Arthur Zamarin gentoo org> AuthorDate: Tue Jan 31 18:00:51 2023 +0000 Commit: Arthur Zamarin gentoo org> CommitDate: Fri Feb 3 13:03:35 2023 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=87226810 PythonCheck: check for missing scm dep when needed Resolves: https://github.com/pkgcore/pkgcheck/issues/537 Signed-off-by: Arthur Zamarin gentoo.org> src/pkgcheck/checks/python.py | 37 ++++++++++++++++++++-- .../PythonMissingSCMDependency/expected.json | 1 + .../PythonMissingSCMDependency/fix.patch | 8 +++++ .../PythonMissingSCMDependency-0.ebuild | 13 ++++++++ .../PythonMissingSCMDependency/metadata.xml | 4 +++ 5 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/pkgcheck/checks/python.py b/src/pkgcheck/checks/python.py index 2b20ee93..11ebc1e1 100644 --- a/src/pkgcheck/checks/python.py +++ b/src/pkgcheck/checks/python.py @@ -1,6 +1,7 @@ -from collections import defaultdict import itertools import re +from collections import defaultdict +from operator import attrgetter from pkgcore import fetch from pkgcore.ebuild.atom import atom @@ -222,6 +223,20 @@ class PythonAnyMismatchedDepHasVersionCheck(results.VersionResult, results.Warni return f"{self.dep_category}: missing check for {self.dep_atom}[{use_flags}] in {self.location!r}" +class PythonMissingSCMDependency(results.VersionResult, results.Warning): + """Package is missing BDEPEND on setuptools_scm or alike. + + Packages which define ``SETUPTOOLS_SCM_PRETEND_VERSION`` should BDEPEND + on ``dev-python/setuptools_scm`` or a similar package [#]_. + + .. [#] https://projects.gentoo.org/python/guide/distutils.html#setuptools-scm-flit-scm-hatch-vcs-and-snapshots + """ + + desc = ( + "defines SETUPTOOLS_SCM_PRETEND_VERSION but is missing BDEPEND on setuptools_scm or alike" + ) + + class PythonCheck(Check): """Python eclass checks. @@ -242,6 +257,7 @@ class PythonCheck(Check): PythonHasVersionMissingPythonUseDep, PythonAnyMismatchedUseHasVersionCheck, PythonAnyMismatchedDepHasVersionCheck, + PythonMissingSCMDependency, ] ) @@ -263,6 +279,14 @@ class PythonCheck(Check): "python-r1": "python_gen_any_dep", } + setuptools_scm = frozenset( + { + "dev-python/setuptools_scm", + "dev-python/flit_scm", + "dev-python/hatch-vcs", + } + ) + def scan_tree_recursively(self, deptree, expected_cls): for x in deptree: if not isinstance(x, expected_cls): @@ -319,6 +343,7 @@ class PythonCheck(Check): """ has_distutils_optional = None has_distutils_deps = False + uses_setuptools_scm = False pep517_value = None for var_node, _ in bash.var_assign_query.captures(pkg.tree.root_node): @@ -328,21 +353,29 @@ class PythonCheck(Check): has_distutils_optional = True elif var_name == "DISTUTILS_USE_PEP517": pep517_value = pkg.node_str(var_node.children[-1]) + elif var_name == "SETUPTOOLS_SCM_PRETEND_VERSION": + uses_setuptools_scm = True if "DISTUTILS_DEPS" in pkg.node_str(var_node.parent): # If they're referencing the eclass' dependency variable, # there's nothing for us to do anyway. has_distutils_deps = True + bdepends = frozenset(map(attrgetter("key"), iflatten_instance(pkg.bdepend, atom))) + if pep517_value is None: yield DistutilsNonPEP517Build(pkg=pkg) elif has_distutils_optional and not has_distutils_deps and pep517_value != "no": # We always need BDEPEND for these if != no. # We are looking for USE-conditional on appropriate target # flag, with dep on dev-python/gpep517. - if "dev-python/gpep517" not in iflatten_instance(pkg.bdepend, atom): + if "dev-python/gpep517" not in bdepends: yield PythonMissingDeps("BDEPEND", pkg=pkg, dep_value="DISTUTILS_DEPS") + if uses_setuptools_scm: + if not self.setuptools_scm.intersection(bdepends): + yield PythonMissingSCMDependency(pkg=pkg) + @staticmethod def _prepare_deps(deps: str): try: diff --git a/testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/expected.json b/testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/expected.json new file mode 100644 index 00000000..9297a0d5 --- /dev/null +++ b/testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/expected.json @@ -0,0 +1 @@ +{"__class__": "PythonMissingSCMDependency", "category": "PythonCheck", "package": "PythonMissingSCMDependency", "version": "0"} diff --git a/testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/fix.patch b/testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/fix.patch new file mode 100644 index 00000000..94f8de26 --- /dev/null +++ b/testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/fix.patch @@ -0,0 +1,8 @@ +--- python/PythonCheck/PythonMissingSCMDependency/PythonMissingSCMDependency-0.ebuild ++++ fixed/PythonCheck/PythonMissingSCMDependency/PythonMissingSCMDependency-0.ebuild +@@ -10,4 +10,5 @@ + LICENSE="BSD" + SLOT="0" + ++BDEPEND="dev-python/hatch-vcs[${PYTHON_USEDEP}]" + export SETUPTOOLS_SCM_PRETEND_VERSION=${PV} diff --git a/testdata/repos/python/PythonCheck/PythonMissingSCMDependency/PythonMissingSCMDependency-0.ebuild b/testdata/repos/python/PythonCheck/PythonMissingSCMDependency/PythonMissingSCMDependency-0.ebuild new file mode 100644 index 00000000..79a8a8df --- /dev/null +++ b/testdata/repos/python/PythonCheck/PythonMissingSCMDependency/PythonMissingSCMDependency-0.ebuild @@ -0,0 +1,13 @@ +EAPI=8 + +DISTUTILS_USE_PEP517=setuptools +PYTHON_COMPAT=( python3_10 ) + +inherit distutils-r1 + +DESCRIPTION="Ebuild with missing dep on scm" +HOMEPAGE="https://github.com/pkgcore/pkgcheck" +LICENSE="BSD" +SLOT="0" + +export SETUPTOOLS_SCM_PRETEND_VERSION=${PV} diff --git a/testdata/repos/python/PythonCheck/PythonMissingSCMDependency/metadata.xml b/testdata/repos/python/PythonCheck/PythonMissingSCMDependency/metadata.xml new file mode 100644 index 00000000..097975e3 --- /dev/null +++ b/testdata/repos/python/PythonCheck/PythonMissingSCMDependency/metadata.xml @@ -0,0 +1,4 @@ + + + +