commit:     73b2cc0ecf48fec9242823009e0de953981913b3
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Tue Aug 29 17:35:08 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Tue Aug 29 17:35:08 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=73b2cc0e

ebuild.repository: require .group extension for stabilization groups

After further consideration, it seems that the requiring .group extension
will make our life easier, with exact format, and save us from backup
files, readme or similar.

https://github.com/pkgcore/pkgcore/pull/412#discussion_r1307738865

Suggested-by: Michał Górny <mgorny <AT> gentoo.org>
Follows: d00711f2d6cbae14a57088ef78caa3daf72069aa
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgcore/ebuild/repository.py | 35 ++++++++++++++++++++---------------
 tests/ebuild/test_repository.py  | 21 +++++++++++----------
 2 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/src/pkgcore/ebuild/repository.py b/src/pkgcore/ebuild/repository.py
index 50f115cc1..49bd72e19 100644
--- a/src/pkgcore/ebuild/repository.py
+++ b/src/pkgcore/ebuild/repository.py
@@ -676,22 +676,27 @@ class UnconfiguredTree(prototype.tree):
     @klass.jit_attr
     def stabilization_groups(self):
         """Return a mapping of stabilization groups to packages."""
-        stabilization_groups = {}
         base_dir = pjoin(self.location, "metadata", "stabilization-groups")
-        for dirname, _dirs, files in os.walk(base_dir):
-            dirbase = dirname.removeprefix(base_dir)
-            for file in files:
-                pkgs = set()
-                for lineno, line in enumerate(readlines_utf8(pjoin(dirname, 
file)), 1):
-                    try:
-                        if line := line.split("#", maxsplit=1)[0].strip():
-                            pkgs.add(atom(line))
-                    except ebuild_errors.MalformedAtom as exc:
-                        logger.error(
-                            f"{dirname.removeprefix(self.location)}/{file}, 
line {lineno}: parsing error: {exc}"
-                        )
-                group = f"{dirbase}/{file}".removeprefix("/")
-                stabilization_groups[group] = frozenset(pkgs)
+        group_files = {
+            pjoin(dirname, file)
+            .removeprefix(base_dir + "/")
+            .removesuffix(".group"): pjoin(dirname, file)
+            for dirname, _dirs, files in os.walk(base_dir)
+            for file in files
+            if file.endswith(".group")
+        }
+        stabilization_groups = {}
+        for group_name, group_file in group_files.items():
+            pkgs = set()
+            for lineno, line in enumerate(readlines_utf8(group_file), 1):
+                try:
+                    if line := line.split("#", maxsplit=1)[0].strip():
+                        pkgs.add(atom(line))
+                except ebuild_errors.MalformedAtom as exc:
+                    logger.error(
+                        f"{group_file.removeprefix(self.location)}, line 
{lineno}: parsing error: {exc}"
+                    )
+            stabilization_groups[group_name] = frozenset(pkgs)
         return ImmutableDict(stabilization_groups)
 
     def _regen_operation_helper(self, **kwds):

diff --git a/tests/ebuild/test_repository.py b/tests/ebuild/test_repository.py
index fceb70b37..2ba4eda57 100644
--- a/tests/ebuild/test_repository.py
+++ b/tests/ebuild/test_repository.py
@@ -202,17 +202,18 @@ class TestUnconfiguredTree:
     def test_stabilization_groups(self, tmp_path, caplog):
         base = tmp_path / "metadata/stabilization-groups"
         (base / "pkgcore").mkdir(parents=True)
-        (base / "gentoo").write_text(
-            textwrap.dedent(
-                """\
-                    # some text here
-                        dev-python/pkgcore
-                    dev-python/pytest # comment
-                    @bad_atom@
-                """
-            )
+        (base / "gentoo.group").write_text(
+            """\
+                # some text here
+                    dev-python/pkgcore
+                dev-python/pytest # comment
+                @bad_atom@
+            """
+        )
+        (base / "pkgcore" / "snakeoil.group").write_text(
+            """dev-python/snakeoil # comment"""
         )
-        (base / "pkgcore" / "snakeoil").write_text("""dev-python/snakeoil # 
comment""")
+        (base / "pkgcore" / "pkgdev").write_text("""dev-python/pkgdev # 
comment""")
         mirrors = self.mk_tree(tmp_path).stabilization_groups
         assert set(mirrors.keys()) == {"gentoo", "pkgcore/snakeoil"}
         assert set(mirrors["gentoo"]) == {

Reply via email to