commit: f850924100957202b8593a3251a874993d858a63 Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Fri Jul 11 19:08:11 2025 +0000 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> CommitDate: Fri Jul 11 19:26:04 2025 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=f8509241
DependencyCheck: include replacement suggestions Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> Closes: https://github.com/pkgcore/pkgcheck/pull/743 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> src/pkgcheck/checks/metadata.py | 23 +++++++++++++++++++--- .../MissingPackageRevision/expected.json | 12 +++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/pkgcheck/checks/metadata.py b/src/pkgcheck/checks/metadata.py index 429c774f..53bfdf2e 100644 --- a/src/pkgcheck/checks/metadata.py +++ b/src/pkgcheck/checks/metadata.py @@ -756,15 +756,19 @@ class MissingPackageRevision(results.VersionResult, results.Warning): operators. """ - def __init__(self, dep, op, atom, **kwargs): + def __init__(self, dep: str, op: str, atom: str, suggestions: list[str], **kwargs): super().__init__(**kwargs) self.dep = dep.upper() self.op = op self.atom = atom + self.suggestions = tuple(suggestions) @property def desc(self): - return f'"{self.op}" operator used without package revision: {self.dep}="{self.atom}"' + return ( + f'"{self.op}" operator used without package revision: {self.dep}="{self.atom}"; ' + f'did you mean either of: {self.suggestions}?' + ) class MissingUseDepDefault(results.VersionResult, results.Warning): @@ -910,6 +914,13 @@ class DependencyCheck(Check): return missing_use_deps return {} + def _make_replacement_atom(self, orig: atom_cls, op: str, rev: str) -> str: + """Make a replacement atom string from orig, with op & rev replaced""" + s = f"{op}{orig.key}-{orig.version}{rev}" + if orig.blocks: + s = ("!!" if orig.blocks_strongly else "!") + s + return s + def feed(self, pkg): deprecated = defaultdict(set) @@ -960,7 +971,13 @@ class DependencyCheck(Check): # these operators are most likely to mean "the whole version" rather than r0 # blockers also matched intentionally if atom.op in ("=", "<=", ">") and not atom.revision: - yield MissingPackageRevision(attr, atom.op, str(atom), pkg=pkg) + repl0 = self._make_replacement_atom(atom, atom.op, "-r0") + if atom.op == "=": + repl1 = self._make_replacement_atom(atom, "~", "") + else: + repl1 = self._make_replacement_atom(atom, atom.op, "-r9999") + + yield MissingPackageRevision(attr, atom.op, str(atom), [repl0, repl1], pkg=pkg) if isinstance(atom, transitive_use_atom) and atom.use is not None: for useflag in atom.use: diff --git a/testdata/data/repos/standalone/DependencyCheck/MissingPackageRevision/expected.json b/testdata/data/repos/standalone/DependencyCheck/MissingPackageRevision/expected.json index 96124dea..86ca3797 100644 --- a/testdata/data/repos/standalone/DependencyCheck/MissingPackageRevision/expected.json +++ b/testdata/data/repos/standalone/DependencyCheck/MissingPackageRevision/expected.json @@ -1,6 +1,6 @@ -{"__class__": "MissingPackageRevision", "category": "DependencyCheck", "package": "MissingPackageRevision", "version": "0", "dep": "RDEPEND", "op": "=", "atom": "=stub/stub5-1"} -{"__class__": "MissingPackageRevision", "category": "DependencyCheck", "package": "MissingPackageRevision", "version": "1", "dep": "DEPEND", "op": "<=", "atom": "<=stub/stub5-1"} -{"__class__": "MissingPackageRevision", "category": "DependencyCheck", "package": "MissingPackageRevision", "version": "2", "dep": "BDEPEND", "op": ">", "atom": ">stub/stub5-0"} -{"__class__": "MissingPackageRevision", "category": "DependencyCheck", "package": "MissingPackageRevision", "version": "0-r1", "dep": "RDEPEND", "op": "=", "atom": "!=stub/stub5-0"} -{"__class__": "MissingPackageRevision", "category": "DependencyCheck", "package": "MissingPackageRevision", "version": "1-r1", "dep": "RDEPEND", "op": "<=", "atom": "!<=stub/stub5-0"} -{"__class__": "MissingPackageRevision", "category": "DependencyCheck", "package": "MissingPackageRevision", "version": "2-r1", "dep": "RDEPEND", "op": ">", "atom": "!>stub/stub5-2"} +{"__class__": "MissingPackageRevision", "category": "DependencyCheck", "package": "MissingPackageRevision", "version": "0", "dep": "RDEPEND", "op": "=", "atom": "=stub/stub5-1", "suggestions": ["=stub/stub5-1-r0", "~stub/stub5-1"]} +{"__class__": "MissingPackageRevision", "category": "DependencyCheck", "package": "MissingPackageRevision", "version": "0-r1", "dep": "RDEPEND", "op": "=", "atom": "!=stub/stub5-0", "suggestions": ["!=stub/stub5-0-r0", "!~stub/stub5-0"]} +{"__class__": "MissingPackageRevision", "category": "DependencyCheck", "package": "MissingPackageRevision", "version": "1", "dep": "DEPEND", "op": "<=", "atom": "<=stub/stub5-1", "suggestions": ["<=stub/stub5-1-r0", "<=stub/stub5-1-r9999"]} +{"__class__": "MissingPackageRevision", "category": "DependencyCheck", "package": "MissingPackageRevision", "version": "1-r1", "dep": "RDEPEND", "op": "<=", "atom": "!<=stub/stub5-0", "suggestions": ["!<=stub/stub5-0-r0", "!<=stub/stub5-0-r9999"]} +{"__class__": "MissingPackageRevision", "category": "DependencyCheck", "package": "MissingPackageRevision", "version": "2", "dep": "BDEPEND", "op": ">", "atom": ">stub/stub5-0", "suggestions": [">stub/stub5-0-r0", ">stub/stub5-0-r9999"]} +{"__class__": "MissingPackageRevision", "category": "DependencyCheck", "package": "MissingPackageRevision", "version": "2-r1", "dep": "RDEPEND", "op": ">", "atom": "!>stub/stub5-2", "suggestions": ["!>stub/stub5-2-r0", "!>stub/stub5-2-r9999"]}
