commit: b9dc3859c9a507639548ce292656388a4b6418e6 Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Thu Oct 13 13:28:47 2022 +0000 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> CommitDate: Thu Oct 13 17:05:35 2022 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=b9dc3859
PythonCheck: warn about use of distutils-r1 non-PEP517 mode Closes: https://github.com/pkgcore/pkgcheck/issues/467 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> src/pkgcheck/checks/python.py | 33 ++++++++++++++++++++-- .../DistutilsNonPEP517Build/expected.json | 1 + .../PythonCheck/DistutilsNonPEP517Build/fix.patch | 10 +++++++ .../DistutilsNonPEP517Build-0.ebuild | 10 +++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/pkgcheck/checks/python.py b/src/pkgcheck/checks/python.py index 9bfa0bad..a1d5ff5f 100644 --- a/src/pkgcheck/checks/python.py +++ b/src/pkgcheck/checks/python.py @@ -139,6 +139,17 @@ class PythonEclassError(results.VersionResult, results.Error): return self.msg +class DistutilsNonPEP517Build(results.VersionResult, results.Warning): + """Ebuild uses the deprecated non-PEP517 build""" + + @property + def desc(self): + return ( + "uses deprecated non-PEP517 build mode, please switch to " + "DISTUTILS_USE_PEP517=..." + ) + + class PythonCheck(Check): """Python eclass checks. @@ -150,6 +161,7 @@ class PythonCheck(Check): known_results = frozenset([ MissingPythonEclass, PythonMissingRequiredUse, PythonMissingDeps, PythonRuntimeDepInAnyR1, PythonEclassError, + DistutilsNonPEP517Build, ]) def scan_tree_recursively(self, deptree, expected_cls): @@ -240,6 +252,20 @@ class PythonCheck(Check): return True + def check_pep517_mode(self, item): + """Check whether PEP517 mode is used.""" + # We're not interested in testing fake objects from TestPythonCheck + if not isinstance(item, sources._ParsedPkg) or not hasattr(item, 'tree'): # pragma: no cover + return True + + for var_node, _ in bash.var_assign_query.captures(item.tree.root_node): + var_name = item.node_str(var_node.child_by_field_name('name')) + + if var_name == "DISTUTILS_USE_PEP517": + return True + + return False + def feed(self, pkg): try: eclass = get_python_eclass(pkg) @@ -285,8 +311,11 @@ class PythonCheck(Check): yield PythonMissingRequiredUse(pkg=pkg) if not self.check_depend(pkg.rdepend, *(req_use_args[:2])): yield PythonMissingDeps('RDEPEND', pkg=pkg) - if 'distutils-r1' in pkg.inherited and not self.check_pep517_depend(pkg): - yield PythonMissingDeps("BDEPEND", pkg=pkg, dep_value="DISTUTILS_DEPS") + if "distutils-r1" in pkg.inherited: + if not self.check_pep517_mode(pkg): + yield DistutilsNonPEP517Build(pkg=pkg) + if not self.check_pep517_depend(pkg): + yield PythonMissingDeps("BDEPEND", pkg=pkg, dep_value="DISTUTILS_DEPS") else: # python-any-r1 for attr in ("rdepend", "pdepend"): for p in iflatten_instance(getattr(pkg, attr), atom): diff --git a/testdata/data/repos/python/PythonCheck/DistutilsNonPEP517Build/expected.json b/testdata/data/repos/python/PythonCheck/DistutilsNonPEP517Build/expected.json new file mode 100644 index 00000000..db292bed --- /dev/null +++ b/testdata/data/repos/python/PythonCheck/DistutilsNonPEP517Build/expected.json @@ -0,0 +1 @@ +{"__class__": "DistutilsNonPEP517Build", "category": "PythonCheck", "package": "DistutilsNonPEP517Build", "version": "0"} diff --git a/testdata/data/repos/python/PythonCheck/DistutilsNonPEP517Build/fix.patch b/testdata/data/repos/python/PythonCheck/DistutilsNonPEP517Build/fix.patch new file mode 100644 index 00000000..6ad28c31 --- /dev/null +++ b/testdata/data/repos/python/PythonCheck/DistutilsNonPEP517Build/fix.patch @@ -0,0 +1,10 @@ +diff -Naur python/PythonCheck/DistutilsNonPEP517Build/DistutilsNonPEP517Build-0.ebuild fixed/PythonCheck/DistutilsNonPEP517Build/DistutilsNonPEP517Build-0.ebuild +--- python/PythonCheck/DistutilsNonPEP517Build/DistutilsNonPEP517Build-0.ebuild 2022-10-13 15:21:07.676924455 +0200 ++++ fixed/PythonCheck/DistutilsNonPEP517Build/DistutilsNonPEP517Build-0.ebuild 2022-10-13 15:24:54.005682963 +0200 +@@ -1,5 +1,6 @@ + EAPI=7 + ++DISTUTILS_USE_PEP517=setuptools + PYTHON_COMPAT=( python3_10 ) + + inherit distutils-r1 diff --git a/testdata/repos/python/PythonCheck/DistutilsNonPEP517Build/DistutilsNonPEP517Build-0.ebuild b/testdata/repos/python/PythonCheck/DistutilsNonPEP517Build/DistutilsNonPEP517Build-0.ebuild new file mode 100644 index 00000000..03ff2937 --- /dev/null +++ b/testdata/repos/python/PythonCheck/DistutilsNonPEP517Build/DistutilsNonPEP517Build-0.ebuild @@ -0,0 +1,10 @@ +EAPI=7 + +PYTHON_COMPAT=( python3_10 ) + +inherit distutils-r1 + +DESCRIPTION="Ebuild using non-PEP517 build" +HOMEPAGE="https://github.com/pkgcore/pkgcheck" +LICENSE="BSD" +SLOT="0"