commit: f756179726eb700b9d1998d4d1bd16270d8ce1d4 Author: Brian Harring <ferringb <AT> gmail <DOT> com> AuthorDate: Fri Jan 12 05:43:40 2024 +0000 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> CommitDate: Fri Jan 12 07:07:44 2024 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=f7561797
fix: child repository not inheriting license groups when it defines none If the child repository defines no license groups, the previous code would exit out before it integrated the parents license groups. This fixes that, and adds tests for it. Signed-off-by: Brian Harring <ferringb <AT> gmail.com> Closes: https://github.com/pkgcore/pkgcore/pull/424 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> src/pkgcore/ebuild/repo_objs.py | 8 +++++--- tests/ebuild/test_repository.py | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/pkgcore/ebuild/repo_objs.py b/src/pkgcore/ebuild/repo_objs.py index 3359305bb..47422dc12 100644 --- a/src/pkgcore/ebuild/repo_objs.py +++ b/src/pkgcore/ebuild/repo_objs.py @@ -526,11 +526,13 @@ class Licenses(metaclass=WeakInstMeta): d = read_dict(self.license_groups_path, splitter=" ") for k, v in d.items(): d[k] = set(v.split()) - except EnvironmentError: - return mappings.ImmutableDict() + except EnvironmentError as e: + if e.errno != errno.ENOENT: + logger.error(f"failed reading parsing license_groups: {e}") + d = {} except BashParseError as pe: logger.error(f"failed parsing license_groups: {pe}") - return mappings.ImmutableDict() + d = {} for li in self._license_instances: for k, v in li.groups.items(): if k in d: diff --git a/tests/ebuild/test_repository.py b/tests/ebuild/test_repository.py index 71366ba2e..10c0b93b1 100644 --- a/tests/ebuild/test_repository.py +++ b/tests/ebuild/test_repository.py @@ -296,7 +296,7 @@ class TestSlavedTree(TestUnconfiguredTree): repo = self.mk_tree(slave_repo) assert set(repo.licenses) == set(master_licenses + slave_licenses) - def test_license_groups(self, master_repo, slave_repo): + def test_license_groups(self, master_repo, slave_repo, caplog): master_licenses = ("GPL-2", "BSD") slave_licenses = ("BSD-2", "MIT") @@ -324,6 +324,26 @@ class TestSlavedTree(TestUnconfiguredTree): } assert "BSD" in repo.licenses.groups["MISC-FREE"] + # verify it warns when parsing fails + (slave_repo / "profiles" / "license_groups").write_text('X"') + caplog.clear() + repo = self.mk_tree(slave_repo) + assert set(repo.licenses.groups) == {"FREE", "OSI-APPROVED"} + assert caplog.text + + # verify it warns when the file exists but it can't read it. + (slave_repo / "profiles" / "license_groups").write_text("") + (slave_repo / "profiles" / "license_groups").chmod(000) + caplog.clear() + repo = self.mk_tree(slave_repo) + assert set(repo.licenses.groups) == {"FREE", "OSI-APPROVED"} + assert caplog.text + + # verify it handles a missing license group. + (slave_repo / "profiles" / "license_groups").unlink() + repo = self.mk_tree(slave_repo) + assert set(repo.licenses.groups) == {"FREE", "OSI-APPROVED"} + def test_package_deprecated(self, slave_repo, master_repo): (master_repo / "profiles" / "package.deprecated").write_text( textwrap.dedent(