proj/pkgcore/pkgdev:main commit in: tests/scripts/, src/pkgdev/scripts/

"Arthur Zamarin" <[email protected]>
Newsgroups gmane.linux.gentoo.cvs
Message-ID <1786642470.e46ee4baa0935f115ad6baf060c7f35868ab45a6.arthurzam@gentoo>
commit:     e46ee4baa0935f115ad6baf060c7f35868ab45a6
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Thu Aug 13 17:34:30 2026 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Thu Aug 13 17:34:30 2026 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/pkgdev.git/commit/?id=e46ee4ba

commit: name the identifier a new GLEP 81 package allocates

A new acct-user or acct-group package got the generic "new package, add 0"
summary, where the interesting part is which UID or GID it takes. Scrape it
out of the ebuild and use it instead:

    acct-user/foo: add user 123
    acct-group/foo: add group 456

Resolves: https://github.com/pkgcore/pkgdev/issues/14
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgdev/scripts/pkgdev_commit.py | 20 ++++++++++
 tests/scripts/test_pkgdev_commit.py | 80 ++++++++++++++++++-------------------
 2 files changed, 58 insertions(+), 42 deletions(-)

diff --git a/src/pkgdev/scripts/pkgdev_commit.py b/src/pkgdev/scripts/pkgdev_commit.py
index ebcc759..ecee48d 100644
--- a/src/pkgdev/scripts/pkgdev_commit.py
+++ b/src/pkgdev/scripts/pkgdev_commit.py
@@ -326,6 +326,10 @@ class HistoricalRepo(UnconfiguredTree):
             tar.extractall(path=self.location, **extra_kwargs)
 
 
+# GLEP 81 categories, mapped to what their packages allocate
+_ACCT_CATEGORIES = {"acct-user": "user", "acct-group": "group"}
+
+
 def change(*statuses):
     """Decorator to register change status summary methods."""
 
@@ -461,10 +465,26 @@ class PkgSummary(ChangeSummary):
         """Existing packages in the tree related to the package."""
         return tuple(self.repo.match(next(iter(self.changes)).unversioned_atom))
 
+    @jit_attr
+    def account(self):
+        """Identifier a new GLEP 81 user or group package allocates, if any."""
+        atom = next(iter(self.changes))
+        if (kind := _ACCT_CATEGORIES.get(atom.category)) is None or len(self.changes) != 1:
+            return None
+        # a negative id asks the eclass to allocate dynamically, nothing to name
+        id_re = re.compile(rf"""ACCT_{kind.upper()}_ID=(?P<quot>['"]?)(?P<id>\d+)(?P=quot)""")
+        for pkg in self.repo.match(atom):
+            for line in pkg.ebuild.text_fileobj():
+                if mo := id_re.match(line):
+                    return f"{kind} {mo.group('id')}"
+        return None
+
     @change("A")
     def add(self):
         """Generate summaries for add actions."""
         if len(self.existing) == len(self.changes):
+            if self.account is not None:
+                return f"add {self.account}"
             msg = f"new package, add {', '.join(self.versions)}"
             if len(self.versions) == 1 or len(msg) <= 50:
                 return msg

diff --git a/tests/scripts/test_pkgdev_commit.py b/tests/scripts/test_pkgdev_commit.py
index f5bb6fd..7ced6bc 100644
--- a/tests/scripts/test_pkgdev_commit.py
+++ b/tests/scripts/test_pkgdev_commit.py
@@ -489,24 +489,25 @@ class TestPkgdevCommit:
             f.write("# comment\n")
         assert commit() == "msg"
 
+    def _auto_commit(self, capsys, git_repo):
+        with (
+            os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"),
+            patch("sys.argv", self.args + ["-a"]),
+            pytest.raises(SystemExit) as excinfo,
+            chdir(git_repo.path),
+        ):
+            self.script()
+        assert excinfo.value.code == 0
+        out, err = capsys.readouterr()
+        assert err == out == ""
+        message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"])
+        return message[0]
+
     def test_generated_commit_summaries(self, capsys, repo, make_git_repo):
         git_repo = make_git_repo(repo.location)
         repo.create_ebuild("cat/pkg-0")
         git_repo.add_all("cat/pkg-0")
-
-        def commit():
-            with (
-                os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"),
-                patch("sys.argv", self.args + ["-a"]),
-                pytest.raises(SystemExit) as excinfo,
-                chdir(git_repo.path),
-            ):
-                self.script()
-            assert excinfo.value.code == 0
-            out, err = capsys.readouterr()
-            assert err == out == ""
-            message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"])
-            return message[0]
+        commit = partial(self._auto_commit, capsys, git_repo)
 
         # initial package import
         repo.create_ebuild("cat/newpkg-0")
@@ -630,9 +631,31 @@ class TestPkgdevCommit:
         shutil.rmtree(pjoin(git_repo.path, "newcat/pkg"))
         assert commit() == "newcat/pkg: treeclean"
 
+    def test_generated_commit_summaries_acounts(self, capsys, repo, make_git_repo):
+        git_repo = make_git_repo(repo.location)
+        repo.create_ebuild("cat/pkg-0")
+        git_repo.add_all("cat/pkg-0")
+        commit = partial(self._auto_commit, capsys, git_repo)
+
+        # GLEP 81 accounts name the identifier they allocate
+        repo.create_ebuild("acct-user/newuser-0", acct_user_id=123)
+        assert commit() == "acct-user/newuser: add user 123"
+
+        repo.create_ebuild("acct-group/newgroup-0", acct_group_id=456)
+        assert commit() == "acct-group/newgroup: add group 456"
+
+        # a dynamically allocated id has nothing to name
+        repo.create_ebuild("acct-user/dynamic-0", acct_user_id=-1)
+        assert commit() == "acct-user/dynamic: new package, add 0"
+
+        # only for a new package, not a version added to an existing one
+        repo.create_ebuild("acct-user/newuser-1", acct_user_id=123)
+        assert commit() == "acct-user/newuser: add 1"
+
     def test_generated_commit_summaries_keywords(self, capsys, make_repo, make_git_repo):
         repo = make_repo(arches=["amd64", "arm64", "ia64", "x86"])
         git_repo = make_git_repo(repo.location)
+        commit = partial(self._auto_commit, capsys, git_repo)
         pkgdir = os.path.dirname(repo.create_ebuild("cat/pkg-0"))
         with open(pjoin(pkgdir, "metadata.xml"), "w") as f:
             f.write(
@@ -648,20 +671,6 @@ class TestPkgdevCommit:
             )
         git_repo.add_all("cat/pkg-0")
 
-        def commit():
-            with (
-                os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"),
-                patch("sys.argv", self.args + ["-a"]),
-                pytest.raises(SystemExit) as excinfo,
-                chdir(git_repo.path),
-            ):
-                self.script()
-            assert excinfo.value.code == 0
-            out, err = capsys.readouterr()
-            assert err == out == ""
-            message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"])
-            return message[0]
-
         # keyword version
         repo.create_ebuild("cat/pkg-0", keywords=["~amd64"])
         assert commit() == "cat/pkg: keyword 0 for ~amd64"
@@ -711,6 +720,7 @@ class TestPkgdevCommit:
     def test_metadata_summaries(self, capsys, repo, make_git_repo):
         git_repo = make_git_repo(repo.location)
         pkgdir = os.path.dirname(repo.create_ebuild("cat/pkg-0"))
+        commit = partial(self._auto_commit, capsys, git_repo)
         # stub metadata
         with open(pjoin(pkgdir, "metadata.xml"), "w") as f:
             f.write(
@@ -729,20 +739,6 @@ class TestPkgdevCommit:
             )
         git_repo.add_all("cat/pkg-0")
 
-        def commit():
-            with (
-                os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"),
-                patch("sys.argv", self.args + ["-a"]),
-                pytest.raises(SystemExit) as excinfo,
-                chdir(git_repo.path),
-            ):
-                self.script()
-            assert excinfo.value.code == 0
-            out, err = capsys.readouterr()
-            assert err == out == ""
-            message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"])
-            return message[0]
-
         # add yourself
         with open(pjoin(pkgdir, "metadata.xml"), "w") as f:
             f.write(
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.