From f756179726eb700b9d1998d4d1bd16270d8ce1d4 Mon Sep 17 00:00:00 2001 From: Brian Harring Date: Thu, 11 Jan 2024 21:43:40 -0800 Subject: 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 Closes: https://github.com/pkgcore/pkgcore/pull/424 Signed-off-by: Arthur Zamarin --- 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 3359305b..47422dc1 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 71366ba2..10c0b93b 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( -- cgit v1.2.3-65-gdbad