From 94dd535faaa9e74a4792cd3a96da94fa8856d8ff Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Mon, 23 Jul 2018 17:46:29 +0200 Subject: [PATCH] Fix user profile display Without this patch, issuing 'bindep --profiles' would fail on groups that aren't a 2-tuple, because we assume always two elements and unpack these two [1]. This is a problem, because in the case of loci [2], it prevents a user from predicting the list of packages to be installed on the system in a read only fashion. Additionally, the current --profile function is showing platform details under "Configuration profiles" AND "Platform Profiles", as platforms are not filtered by the profiles() function. This patch solves the two linked problems by: - ensuring the lists of profiles are flattened - ensure the profiles are following the _partition function. [1]: https://github.com/openstack-infra/bindep/blob/cec3a7576bc7599f97a705a42e3572133b4891a1/bindep/depends.py#L276 [2]: https://github.com/openstack/loci/blob/8982c3ae717578eb8e565fd75e78a800970dbb25/bindep.txt#L13 Change-Id: Ied4ac178e20daf35f105e2acae0a2b3e11219a56 --- bindep/depends.py | 10 ++++++++-- bindep/tests/test_depends.py | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bindep/depends.py b/bindep/depends.py index 2066d41..5be7fce 100644 --- a/bindep/depends.py +++ b/bindep/depends.py @@ -273,8 +273,14 @@ class Depends(object): def profiles(self): profiles = set() for rule in self._rules: - for _, selector in rule[1]: - profiles.add(selector) + # Partition rules, but keep only the user ones + _, user_profiles = self._partition(rule) + for profile in user_profiles: + # Flatten a series of AND conditionals in a user rule + if isinstance(profile, list): + profiles.update([rule[1] for rule in profile]) + elif isinstance(profile, tuple): + profiles.add(profile[1]) return sorted(profiles) def codenamebits(self, distro_id, codename): diff --git a/bindep/tests/test_depends.py b/bindep/tests/test_depends.py index a737ac2..0be22c1 100644 --- a/bindep/tests/test_depends.py +++ b/bindep/tests/test_depends.py @@ -67,6 +67,11 @@ class TestDepends(TestCase): depends = Depends("") self.assertEqual([], depends.profiles()) + def test_3tuple(self): + depends = Depends(u"erlang [(infra rabbitmq hipe)]\n") + self.assertEqual(sorted([u'infra', u'rabbitmq', u'hipe']), + depends.profiles()) + def test_platform_profiles_succeeds(self): with DistroFixture('Ubuntu'): depends = Depends("")