diff --git a/koji/__init__.py b/koji/__init__.py index 50d224b8..8786063f 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -111,13 +111,17 @@ RPM_FILEDIGESTALGO_IDS = { 11: 'SHA224' } -# rpm 4.12 introduces optional deps -try: - RPM_SUPPORTS_OPTIONAL_DEPS = int(rpm.__version_info__[0]) > 4 or \ - (int(rpm.__version_info__[0]) == 4 and int(rpm.__version_info__[1]) >= 12) -except AttributeError: - # older versions don't even have __version_info__ - RPM_SUPPORTS_OPTIONAL_DEPS = False +# rpm 4.12 introduces optional deps, but they can also be backported in some +# rpm installations. So, we need to check their real support, not only rpm +# version. +SUPPORTED_OPT_DEP_HDRS = {} +for h in ( + 'SUGGESTNAME', 'SUGGESTVERSION', 'SUGGESTFLAGS', + 'ENHANCENAME', 'ENHANCEVERSION', 'ENHANCEFLAGS', + 'SUPPLEMENTNAME', 'SUPPLEMENTVERSION', 'SUPPLEMENTFLAGS', + 'RECOMMENDNAME', 'RECOMMENDVERSION', 'RECOMMENDFLAGS'): + SUPPORTED_OPT_DEP_HDRS[h] = hasattr(rpm, 'RPMTAG_%s' % h) + class Enum(dict): """A simple class to track our enumerated constants @@ -893,12 +897,8 @@ def get_rpm_header(f, ts=None): def get_header_field(hdr, name, src_arch=False): """Extract named field from an rpm header""" name = name.upper() - opt_dep_hdrs = ( - 'SUGGESTNAME', 'SUGGESTVERSION', 'SUGGESTFLAGS', - 'ENHANCENAME', 'ENHANCEVERSION', 'ENHANCEFLAGS', - 'SUPPLEMENTNAME', 'SUPPLEMENTVERSION', 'SUPPLEMENTFLAGS', - 'RECOMMENDNAME', 'RECOMMENDVERSION', 'RECOMMENDFLAGS') - if not RPM_SUPPORTS_OPTIONAL_DEPS and name in opt_dep_hdrs: + # if field is not supported by host's rpm (>4.12), return empty list + if not SUPPORTED_OPT_DEP_HDRS.get(name, True): return [] if (src_arch and name == "ARCH" diff --git a/tests/test_hub/test_getRPMDeps.py b/tests/test_hub/test_getRPMDeps.py index e6a64e82..093de145 100644 --- a/tests/test_hub/test_getRPMDeps.py +++ b/tests/test_hub/test_getRPMDeps.py @@ -19,7 +19,7 @@ class TestGetRPMDeps(unittest.TestCase): getRPMDeps = kojihub.RootExports().getRPMDeps res = getRPMDeps('') # limit test for rpm < 4.12 - if koji.RPM_SUPPORTS_OPTIONAL_DEPS: + if any(koji.SUPPORTED_OPT_DEP_HDRS.values()): self.assertEqual(len(res), 22) types = set([x['type'] for x in res]) self.assertEqual(set([koji.DEP_REQUIRE, diff --git a/tests/test_lib/test_parsers.py b/tests/test_lib/test_parsers.py index 93365c5e..8c67f671 100644 --- a/tests/test_lib/test_parsers.py +++ b/tests/test_lib/test_parsers.py @@ -200,7 +200,7 @@ class HeaderTestCase(unittest.TestCase): @mock.patch('rpm.RPMTAG_NOSOURCE', new=None) @mock.patch('rpm.RPMTAG_NOPATCH', new=None) - @mock.patch('koji.RPM_SUPPORTS_OPTIONAL_DEPS', new=False) + @mock.patch('koji.SUPPORTED_OPT_DEP_HDRS', new={'SUGGESTNAME': False}) def test_get_header_field_workarounds(self): srpm0 = os.path.join(self.rpmdir, 'test-src-1-1.fc24.src.rpm') srpm1 = os.path.join(self.rpmdir, 'test-nosrc-1-1.fc24.nosrc.rpm')