Skip to content

Commit 69e6b88

Browse files
committed
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: #14 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 82c3dea commit 69e6b88

3 files changed

Lines changed: 65 additions & 47 deletions

File tree

‎NEWS.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ pkgdev 0.2.17 (unreleased)
3737
solve the dependency there. Versions already stable (or already keyworded,
3838
for a keywordreq) on a failing arch are now passed over (Arthur Zamarin, #186)
3939

40+
**pkgdev commit:**
41+
42+
- commit: a new ``acct-user`` or ``acct-group`` package now gets a summary
43+
naming the identifier it allocates, ``acct-user/foo: add user 123``, instead
44+
of the generic ``new package, add 0`` (Arthur Zamarin, #14)
45+
4046
**pkgdev tatt:**
4147

4248
- tatt: fix ebuild ``IUSE`` defaults overriding the profile when deciding a

‎src/pkgdev/scripts/pkgdev_commit.py‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import re
66
import shlex
77
import subprocess
8-
import sys
98
import tarfile
109
import tempfile
1110
import textwrap
@@ -318,12 +317,13 @@ def _populate(self, pkgs):
318317
error = old_files.stderr.read().decode().strip()
319318
raise Exception(f"failed populating archive repo: {error}")
320319
with tarfile.open(mode="r|", fileobj=old_files.stdout) as tar:
321-
extra_kwargs = {}
322320
# see filter in https://docs.python.org/3/library/tarfile.html#tarfile.TarFile.extractall
323321
# Whilst we trust git archive, we still leave the basic protections on.
324-
if sys.version_info >= (3, 12, 0):
325-
extra_kwargs["filter"] = "data"
326-
tar.extractall(path=self.location, **extra_kwargs)
322+
tar.extractall(path=self.location, filter="data")
323+
324+
325+
# GLEP 81 categories, mapped to what their packages allocate
326+
_ACCT_CATEGORIES = {"acct-user": "user", "acct-group": "group"}
327327

328328

329329
def change(*statuses):
@@ -461,10 +461,26 @@ def existing(self):
461461
"""Existing packages in the tree related to the package."""
462462
return tuple(self.repo.match(next(iter(self.changes)).unversioned_atom))
463463

464+
@jit_attr
465+
def account(self):
466+
"""Identifier a new GLEP 81 user or group package allocates, if any."""
467+
atom = next(iter(self.changes))
468+
if (kind := _ACCT_CATEGORIES.get(atom.category)) is None or len(self.changes) != 1:
469+
return None
470+
# a negative id asks the eclass to allocate dynamically, nothing to name
471+
id_re = re.compile(rf"""ACCT_{kind.upper()}_ID=(?P<quot>['"]?)(?P<id>\d+)(?P=quot)""")
472+
for pkg in self.repo.match(atom):
473+
for line in pkg.ebuild.text_fileobj():
474+
if mo := id_re.match(line):
475+
return f"{kind} {mo.group('id')}"
476+
return None
477+
464478
@change("A")
465479
def add(self):
466480
"""Generate summaries for add actions."""
467481
if len(self.existing) == len(self.changes):
482+
if self.account is not None:
483+
return f"add {self.account}"
468484
msg = f"new package, add {', '.join(self.versions)}"
469485
if len(self.versions) == 1 or len(msg) <= 50:
470486
return msg

‎tests/scripts/test_pkgdev_commit.py‎

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -489,24 +489,25 @@ def commit():
489489
f.write("# comment\n")
490490
assert commit() == "msg"
491491

492+
def _auto_commit(self, capsys, git_repo):
493+
with (
494+
os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"),
495+
patch("sys.argv", self.args + ["-a"]),
496+
pytest.raises(SystemExit) as excinfo,
497+
chdir(git_repo.path),
498+
):
499+
self.script()
500+
assert excinfo.value.code == 0
501+
out, err = capsys.readouterr()
502+
assert err == out == ""
503+
message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"])
504+
return message[0]
505+
492506
def test_generated_commit_summaries(self, capsys, repo, make_git_repo):
493507
git_repo = make_git_repo(repo.location)
494508
repo.create_ebuild("cat/pkg-0")
495509
git_repo.add_all("cat/pkg-0")
496-
497-
def commit():
498-
with (
499-
os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"),
500-
patch("sys.argv", self.args + ["-a"]),
501-
pytest.raises(SystemExit) as excinfo,
502-
chdir(git_repo.path),
503-
):
504-
self.script()
505-
assert excinfo.value.code == 0
506-
out, err = capsys.readouterr()
507-
assert err == out == ""
508-
message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"])
509-
return message[0]
510+
commit = partial(self._auto_commit, capsys, git_repo)
510511

511512
# initial package import
512513
repo.create_ebuild("cat/newpkg-0")
@@ -630,9 +631,31 @@ def commit():
630631
shutil.rmtree(pjoin(git_repo.path, "newcat/pkg"))
631632
assert commit() == "newcat/pkg: treeclean"
632633

634+
def test_generated_commit_summaries_accounts(self, capsys, repo, make_git_repo):
635+
git_repo = make_git_repo(repo.location)
636+
repo.create_ebuild("cat/pkg-0")
637+
git_repo.add_all("cat/pkg-0")
638+
commit = partial(self._auto_commit, capsys, git_repo)
639+
640+
# GLEP 81 accounts name the identifier they allocate
641+
repo.create_ebuild("acct-user/newuser-0", acct_user_id=123)
642+
assert commit() == "acct-user/newuser: add user 123"
643+
644+
repo.create_ebuild("acct-group/newgroup-0", acct_group_id=456)
645+
assert commit() == "acct-group/newgroup: add group 456"
646+
647+
# a dynamically allocated id has nothing to name
648+
repo.create_ebuild("acct-user/dynamic-0", acct_user_id=-1)
649+
assert commit() == "acct-user/dynamic: new package, add 0"
650+
651+
# only for a new package, not a version added to an existing one
652+
repo.create_ebuild("acct-user/newuser-1", acct_user_id=123)
653+
assert commit() == "acct-user/newuser: add 1"
654+
633655
def test_generated_commit_summaries_keywords(self, capsys, make_repo, make_git_repo):
634656
repo = make_repo(arches=["amd64", "arm64", "ia64", "x86"])
635657
git_repo = make_git_repo(repo.location)
658+
commit = partial(self._auto_commit, capsys, git_repo)
636659
pkgdir = os.path.dirname(repo.create_ebuild("cat/pkg-0"))
637660
with open(pjoin(pkgdir, "metadata.xml"), "w") as f:
638661
f.write(
@@ -648,20 +671,6 @@ def test_generated_commit_summaries_keywords(self, capsys, make_repo, make_git_r
648671
)
649672
git_repo.add_all("cat/pkg-0")
650673

651-
def commit():
652-
with (
653-
os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"),
654-
patch("sys.argv", self.args + ["-a"]),
655-
pytest.raises(SystemExit) as excinfo,
656-
chdir(git_repo.path),
657-
):
658-
self.script()
659-
assert excinfo.value.code == 0
660-
out, err = capsys.readouterr()
661-
assert err == out == ""
662-
message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"])
663-
return message[0]
664-
665674
# keyword version
666675
repo.create_ebuild("cat/pkg-0", keywords=["~amd64"])
667676
assert commit() == "cat/pkg: keyword 0 for ~amd64"
@@ -711,6 +720,7 @@ def commit():
711720
def test_metadata_summaries(self, capsys, repo, make_git_repo):
712721
git_repo = make_git_repo(repo.location)
713722
pkgdir = os.path.dirname(repo.create_ebuild("cat/pkg-0"))
723+
commit = partial(self._auto_commit, capsys, git_repo)
714724
# stub metadata
715725
with open(pjoin(pkgdir, "metadata.xml"), "w") as f:
716726
f.write(
@@ -729,20 +739,6 @@ def test_metadata_summaries(self, capsys, repo, make_git_repo):
729739
)
730740
git_repo.add_all("cat/pkg-0")
731741

732-
def commit():
733-
with (
734-
os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"),
735-
patch("sys.argv", self.args + ["-a"]),
736-
pytest.raises(SystemExit) as excinfo,
737-
chdir(git_repo.path),
738-
):
739-
self.script()
740-
assert excinfo.value.code == 0
741-
out, err = capsys.readouterr()
742-
assert err == out == ""
743-
message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"])
744-
return message[0]
745-
746742
# add yourself
747743
with open(pjoin(pkgdir, "metadata.xml"), "w") as f:
748744
f.write(

0 commit comments

Comments
 (0)