Skip to content

Commit

Permalink
NewerEAPIAvailable: committing new ebuilds with old EAPI
Browse files Browse the repository at this point in the history
Catch cases where new ebuilds are committed with old EAPIs. This is
checked during `--commits` stage.

Resolves: pkgcore#666
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
  • Loading branch information
arthurzam committed Mar 2, 2024
1 parent 7e0e513 commit 387e080
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
45 changes: 43 additions & 2 deletions src/pkgcheck/checks/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,23 @@ def desc(self):
return f"old PYTHON_COMPAT target{s} listed: [ {targets} ]"


class NewerEAPIAvailable(results.VersionResult, results.Warning):
"""Package is eligible for a newer EAPI.
A new package version was added, using an older EAPI, than all supported by
inherited eclasses. You should consider bumping the EAPI to the suggested
value.
"""

def __init__(self, eapi: int, **kwargs):
super().__init__(**kwargs)
self.eapi = eapi

@property
def desc(self):
return f"Ebuild eligible for newer EAPI={self.eapi}"


class _RemovalRepo(UnconfiguredTree):
"""Repository of removed packages stored in a temporary directory."""

Expand Down Expand Up @@ -295,7 +312,7 @@ class GitPkgCommitsCheck(GentooRepoCheck, GitCommitsCheck):
"""Check unpushed git package commits for various issues."""

_source = (sources.PackageRepoSource, (), (("source", GitCommitsRepoSource),))
required_addons = (git.GitAddon,)
required_addons = (git.GitAddon, sources.EclassAddon)
known_results = frozenset(
{
DirectStableKeywords,
Expand All @@ -311,6 +328,7 @@ class GitPkgCommitsCheck(GentooRepoCheck, GitCommitsCheck):
PythonPEP517WithoutRevbump,
EAPIChangeWithoutRevbump,
OldPythonCompat,
NewerEAPIAvailable,
}
)

Expand All @@ -321,12 +339,13 @@ class GitPkgCommitsCheck(GentooRepoCheck, GitCommitsCheck):
# package categories that are committed with stable keywords
allowed_direct_stable = frozenset(["acct-user", "acct-group"])

def __init__(self, *args, git_addon: git.GitAddon):
def __init__(self, *args, git_addon: git.GitAddon, eclass_addon: sources.EclassAddon):
super().__init__(*args)
self.today = datetime.today()
self.repo = self.options.target_repo
self.valid_arches: frozenset[str] = self.options.target_repo.known_arches
self._git_addon = git_addon
self.eclass_cache = eclass_addon.eclasses
self._cleanup = []
self.valid_python_targets = {
use.removeprefix("python_targets_")
Expand Down Expand Up @@ -354,6 +373,25 @@ def added_repo(self):
"""Create/load cached repo of packages added to git."""
return self._git_addon.cached_repo(git.GitAddedRepo)

def addition_checks(self, pkgs):
"""Check for issues due to package additions."""
pkg = pkgs[0]
try:
new_pkg = self.repo.match(pkg.versioned_atom)[0]
except IndexError:
# ignore missing ebuild
return

if new_pkg.inherit:
eclass_eapis = (
frozenset(map(int, self.eclass_cache[eclass].supported_eapis))
for eclass in new_pkg.inherit
)
current_eapi = int(str(new_pkg.eapi))
common_max_eapi = max(frozenset.intersection(*eclass_eapis))
if common_max_eapi > current_eapi:
yield NewerEAPIAvailable(common_max_eapi, pkg=new_pkg)

def removal_checks(self, pkgs):
"""Check for issues due to package removals."""
pkg = pkgs[0]
Expand Down Expand Up @@ -526,6 +564,9 @@ def feed(self, pkgset: list[git.GitPkgChange]):
pkg_map["A"].add(pkg)
pkg_map["D"].add(pkg.old_pkg())

# run added package checks
if pkg_map["A"]:
yield from self.addition_checks(list(pkg_map["A"]))
# run removed package checks
if pkg_map["D"]:
yield from self.removal_checks(list(pkg_map["D"]))
Expand Down
2 changes: 1 addition & 1 deletion tests/checks/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TestGitCommitMessageCheck(ReportTestCase):
check = git_mod.GitCommitMessageCheck(options)

def test_sign_offs(self):
# assert that it checks for both author and comitter
# assert that it checks for both author and committer
r = self.assertReport(
self.check, FakeCommit(author="user1", committer="user2", message=["blah"])
)
Expand Down

0 comments on commit 387e080

Please sign in to comment.