diff options
author | Arthur Zamarin <arthurzam@gentoo.org> | 2023-08-29 20:35:08 +0300 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2023-08-29 20:35:08 +0300 |
commit | 73b2cc0ecf48fec9242823009e0de953981913b3 (patch) | |
tree | 048722edbb14045cf2226d2d7ca0aee88d0f7a04 | |
parent | ebuild.repository: add support for stabilization groups (diff) | |
download | pkgcore-73b2cc0ecf48fec9242823009e0de953981913b3.tar.gz pkgcore-73b2cc0ecf48fec9242823009e0de953981913b3.tar.bz2 pkgcore-73b2cc0ecf48fec9242823009e0de953981913b3.zip |
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@gentoo.org>
Follows: d00711f2d6cbae14a57088ef78caa3daf72069aa
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r-- | src/pkgcore/ebuild/repository.py | 35 | ||||
-rw-r--r-- | 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 50f115cc..49bd72e1 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 fceb70b3..2ba4eda5 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"]) == { |