summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-07-09 15:23:52 -0700
committerZac Medico <zmedico@gentoo.org>2011-07-09 15:23:52 -0700
commit50da885309a3a69f0927a730e19026734523b090 (patch)
tree80c2d030943ce20af02adb5924efb5983a0c3009
parent3189ba035110795212c49db501a62b5007df4e18 (diff)
downloadportage-50da885309a3a69f0927a730e19026734523b090.tar.gz
portage-50da885309a3a69f0927a730e19026734523b090.tar.bz2
portage-50da885309a3a69f0927a730e19026734523b090.zip
circular_dependency: use itertools.product()
Python's cartesian product function does exactly what we want, so use it to simplify our code.
-rw-r--r--pym/_emerge/resolver/circular_dependency.py27
1 files changed, 3 insertions, 24 deletions
diff --git a/pym/_emerge/resolver/circular_dependency.py b/pym/_emerge/resolver/circular_dependency.py
index 17898012e..9a3286c5c 100644
--- a/pym/_emerge/resolver/circular_dependency.py
+++ b/pym/_emerge/resolver/circular_dependency.py
@@ -3,7 +3,7 @@
from __future__ import print_function
-from itertools import chain
+from itertools import chain, product
from portage.dep import use_reduce, extract_affecting_use, check_required_use, get_required_use_flags
from portage.exception import InvalidDependString
@@ -147,27 +147,9 @@ class circular_dependency_handler(object):
#We iterate over all possible settings of these use flags and gather
#a set of possible changes
#TODO: Use the information encoded in REQUIRED_USE
- use_state = []
- for flag in affecting_use:
- use_state.append("disabled")
-
- def _next_use_state(state, id=None):
- if id is None:
- id = len(state)-1
-
- if id == 0 and state[0] == "enabled":
- return False
-
- if state[id] == "disabled":
- state[id] = "enabled"
- for i in range(id+1,len(state)):
- state[i] = "disabled"
- return True
- else:
- return _next_use_state(state, id-1)
-
solutions = set()
- while(True):
+ for use_state in product(("disabled", "enabled"),
+ repeat=len(affecting_use)):
current_use = set(self.depgraph._pkg_use_enabled(parent))
for flag, state in zip(affecting_use, use_state):
if state == "enabled":
@@ -200,9 +182,6 @@ class circular_dependency_handler(object):
solution.add((flag, False))
solutions.add(frozenset(solution))
- if not _next_use_state(use_state):
- break
-
for solution in solutions:
ignore_solution = False
for other_solution in solutions: