commit: 8f841f52992c9013ea513e66ab3961ca5ac0fd60 Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Sat Jul 12 15:30:30 2025 +0000 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> CommitDate: Tue Jul 15 18:08:08 2025 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=8f841f52
python: Detect `EPYTEST_TIMEOUT` overriding user value Closes: https://github.com/pkgcore/pkgcheck/issues/740 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> Closes: https://github.com/pkgcore/pkgcheck/pull/747 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> src/pkgcheck/checks/python.py | 23 ++++++++++++++++++++++ .../ShadowedEPyTestTimeout/expected.json | 1 + .../PythonCheck/ShadowedEPyTestTimeout/fix.patch | 10 ++++++++++ .../ShadowedEPyTestTimeout-0.ebuild | 14 +++++++++++++ 4 files changed, 48 insertions(+) diff --git a/src/pkgcheck/checks/python.py b/src/pkgcheck/checks/python.py index 8249b3b8..39fbe55e 100644 --- a/src/pkgcheck/checks/python.py +++ b/src/pkgcheck/checks/python.py @@ -266,6 +266,21 @@ class MisplacedEPyTestVar(results.LineResult, results.Error): ) +class ShadowedEPyTestTimeout(results.LineResult, results.Warning): + """``EPYTEST_TIMEOUT`` shadows user-specified value + + ``EPYTEST_TIMEOUT`` should be set via ``${EPYTEST_TIMEOUT:=...}`` to permit + using an environment variable to override it. + """ + + @property + def desc(self): + return ( + f"line {self.lineno}: EPYTEST_TIMEOUT shadows user value, use " + f"${{EPYTEST_TIMEOUT:=...}} instead: {self.line!r}" + ) + + class PythonCheck(Check): """Python eclass checks. @@ -288,6 +303,7 @@ class PythonCheck(Check): PythonAnyMismatchedDepHasVersionCheck, PythonMissingSCMDependency, MisplacedEPyTestVar, + ShadowedEPyTestTimeout, } ) @@ -456,6 +472,13 @@ class PythonCheck(Check): line = pkg.node_str(var_node) yield MisplacedEPyTestVar(var_name, line=line, lineno=lineno + 1, pkg=pkg) + for var_node in bash.var_assign_query.captures(pkg.tree.root_node).get("assign", ()): + var_name = pkg.node_str(var_node.child_by_field_name("name")) + if var_name == "EPYTEST_TIMEOUT": + lineno, _ = var_node.start_point + line = pkg.node_str(var_node) + yield ShadowedEPyTestTimeout(line=line, lineno=lineno + 1, pkg=pkg) + @staticmethod def _prepare_deps(deps: str): try: diff --git a/testdata/data/repos/python/PythonCheck/ShadowedEPyTestTimeout/expected.json b/testdata/data/repos/python/PythonCheck/ShadowedEPyTestTimeout/expected.json new file mode 100644 index 00000000..a0d98f8a --- /dev/null +++ b/testdata/data/repos/python/PythonCheck/ShadowedEPyTestTimeout/expected.json @@ -0,0 +1 @@ +{"__class__": "ShadowedEPyTestTimeout", "category": "PythonCheck", "package": "ShadowedEPyTestTimeout", "version": "0", "line": "EPYTEST_TIMEOUT=1200", "lineno": 13} diff --git a/testdata/data/repos/python/PythonCheck/ShadowedEPyTestTimeout/fix.patch b/testdata/data/repos/python/PythonCheck/ShadowedEPyTestTimeout/fix.patch new file mode 100644 index 00000000..83dea272 --- /dev/null +++ b/testdata/data/repos/python/PythonCheck/ShadowedEPyTestTimeout/fix.patch @@ -0,0 +1,10 @@ +diff '--color=auto' -Naur python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild fixed/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild +--- python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild 2025-07-12 17:27:01.027875233 +0200 ++++ fixed/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild 2025-07-12 17:28:01.711247010 +0200 +@@ -10,5 +10,5 @@ + LICENSE="BSD" + SLOT="0" + +-EPYTEST_TIMEOUT=1200 ++: ${EPYTEST_TIMEOUT:=1200} + distutils_enable_tests pytest diff --git a/testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild b/testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild new file mode 100644 index 00000000..c87fee5a --- /dev/null +++ b/testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild @@ -0,0 +1,14 @@ +EAPI=8 + +DISTUTILS_USE_PEP517=flit +PYTHON_COMPAT=( python3_10 ) + +inherit distutils-r1 + +DESCRIPTION="Ebuild with misplaced EPYTEST vars" +HOMEPAGE="https://github.com/pkgcore/pkgcheck" +LICENSE="BSD" +SLOT="0" + +EPYTEST_TIMEOUT=1200 +distutils_enable_tests pytest
