proj/pkgcore/pkgdev:main commit in: src/pkgdev/scripts/, tests/scripts/, /
"Arthur Zamarin" <[email protected]>
| Newsgroups | gmane.linux.gentoo.cvs |
|---|---|
| Message-ID | <1786643339.69e6b88a29d6205f0cbc28c734b99bff700cb67f.arthurzam@gentoo> |
commit: 69e6b88a29d6205f0cbc28c734b99bff700cb67f
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:48:59 2026 +0000
URL: https://gitweb.gentoo.org/proj/pkgcore/pkgdev.git/commit/?id=69e6b88a
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>
NEWS.rst | 6 +++
src/pkgdev/scripts/pkgdev_commit.py | 26 +++++++++---
tests/scripts/test_pkgdev_commit.py | 80 ++++++++++++++++++-------------------
3 files changed, 65 insertions(+), 47 deletions(-)
diff --git a/NEWS.rst b/NEWS.rst
index 6e4a730..c2f4e3c 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -37,6 +37,12 @@ pkgdev 0.2.17 (unreleased)
solve the dependency there. Versions already stable (or already keyworded,
for a keywordreq) on a failing arch are now passed over (Arthur Zamarin, #186)
+**pkgdev commit:**
+
+- commit: a new ``acct-user`` or ``acct-group`` package now gets a summary
+ naming the identifier it allocates, ``acct-user/foo: add user 123``, instead
+ of the generic ``new package, add 0`` (Arthur Zamarin, #14)
+
**pkgdev tatt:**
- tatt: fix ebuild ``IUSE`` defaults overriding the profile when deciding a
diff --git a/src/pkgdev/scripts/pkgdev_commit.py b/src/pkgdev/scripts/pkgdev_commit.py
index ebcc759..fb32d24 100644
--- a/src/pkgdev/scripts/pkgdev_commit.py
+++ b/src/pkgdev/scripts/pkgdev_commit.py
@@ -5,7 +5,6 @@ import os
import re
import shlex
import subprocess
-import sys
import tarfile
import tempfile
import textwrap
@@ -318,12 +317,13 @@ class HistoricalRepo(UnconfiguredTree):
error = old_files.stderr.read().decode().strip()
raise Exception(f"failed populating archive repo: {error}")
with tarfile.open(mode="r|", fileobj=old_files.stdout) as tar:
- extra_kwargs = {}
# see filter in https://docs.python.org/3/library/tarfile.html#tarfile.TarFile.extractall
# Whilst we trust git archive, we still leave the basic protections on.
- if sys.version_info >= (3, 12, 0):
- extra_kwargs["filter"] = "data"
- tar.extractall(path=self.location, **extra_kwargs)
+ tar.extractall(path=self.location, filter="data")
+
+
+# GLEP 81 categories, mapped to what their packages allocate
+_ACCT_CATEGORIES = {"acct-user": "user", "acct-group": "group"}
def change(*statuses):
@@ -461,10 +461,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..b074413 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_accounts(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(