commit: 87226810dca088b8eec5d03639b3d830293c82aa Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> AuthorDate: Tue Jan 31 18:00:51 2023 +0000 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> 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 <arthurzam <AT> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd"> +<pkgmetadata> +</pkgmetadata>