From: Sebastian Luther Date: Sat, 14 Aug 2010 06:43:34 +0000 (+0200) Subject: Atom.violated_conditionals: Use iuse.is_valid_flag instead of iuse.all X-Git-Tag: v2.2_rc68~224 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1e69471d3eac6d0e2a01878ed3f0031783f57671;p=portage.git Atom.violated_conditionals: Use iuse.is_valid_flag instead of iuse.all --- diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index e3a47e8a7..643cc3edf 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -2078,7 +2078,7 @@ class depgraph(object): masked_pkg_instances.add(pkg) if atom.unevaluated_atom.use: if not pkg.iuse.is_valid_flag(atom.unevaluated_atom.use.required) \ - or atom.violated_conditionals(self._pkg_use_enabled(pkg), pkg.iuse.all).use: + or atom.violated_conditionals(self._pkg_use_enabled(pkg), pkg.iuse.is_valid_flag).use: missing_use.append(pkg) if not mreasons: continue @@ -2126,7 +2126,8 @@ class depgraph(object): # Lets see if the violated use deps are conditional. # If so, suggest to change them on the parent. mreasons = [] - violated_atom = atom.unevaluated_atom.violated_conditionals(self._pkg_use_enabled(pkg), pkg.iuse.all, myparent.use.enabled) + violated_atom = atom.unevaluated_atom.violated_conditionals(self._pkg_use_enabled(pkg), \ + pkg.iuse.is_valid_flag, myparent.use.enabled) if not (violated_atom.use.enabled or violated_atom.use.disabled): #all violated use deps are conditional changes = [] diff --git a/pym/_emerge/resolver/slot_collision.py b/pym/_emerge/resolver/slot_collision.py index b11fcb0c7..70f4f7141 100644 --- a/pym/_emerge/resolver/slot_collision.py +++ b/pym/_emerge/resolver/slot_collision.py @@ -212,7 +212,7 @@ class slot_conflict_handler(object): elif not atom_set.findAtomForPackage(other_pkg): #Use conditionals not met. violated_atom = atom.violated_conditionals(other_pkg.use.enabled, \ - other_pkg.iuse.all, ppkg.use.enabled) + other_pkg.iuse.is_valid_flag, ppkg.use.enabled) for flag in violated_atom.use.enabled.union(violated_atom.use.disabled): atoms = collision_reasons.get(("use", flag), set()) atoms.add((ppkg, atom, other_pkg)) @@ -252,7 +252,7 @@ class slot_conflict_handler(object): conditional_matches = set() for ppkg, atom, other_pkg in parents: violated_atom = atom.unevaluated_atom.violated_conditionals( \ - other_pkg.use.enabled, other_pkg.iuse.all, ppkg.use.enabled) + other_pkg.use.enabled, other_pkg.iuse.is_valid_flag, ppkg.use.enabled) if use in violated_atom.use.enabled.union(violated_atom.use.disabled): hard_matches.add((ppkg, atom)) else: @@ -457,10 +457,11 @@ class slot_conflict_handler(object): if ppkg.installed: #We cannot assume that it's possible to reinstall the package. Do not #check if some of its atom has use.conditional - violated_atom = atom.violated_conditionals(pkg.use.enabled, pkg.iuse.all, ppkg.use.enabled) + violated_atom = atom.violated_conditionals(pkg.use.enabled, \ + pkg.iuse.is_valid_flag, ppkg.use.enabled) else: violated_atom = atom.unevaluated_atom.violated_conditionals(pkg.use.enabled, \ - pkg.iuse.all, ppkg.use.enabled) + pkg.iuse.is_valid_flag, ppkg.use.enabled) if pkg.installed and (violated_atom.use.enabled or violated_atom.use.disabled): #We can't change USE of an installed package (only of an ebuild, but that is already diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py index 6c12c96d2..9e4242edf 100644 --- a/pym/portage/dep/__init__.py +++ b/pym/portage/dep/__init__.py @@ -589,7 +589,7 @@ class _use_dep(object): return _use_dep(tokens) - def violated_conditionals(self, other_use, iuse, parent_use=None): + def violated_conditionals(self, other_use, is_valid_flag, parent_use=None): """ Create a new instance with satisfied use deps removed. """ @@ -599,7 +599,7 @@ class _use_dep(object): for x in self.enabled: if x not in other_use: - if x in iuse: + if is_valid_flag(x): tokens.append(self._append_use_default(x, x)) else: if x in self.missing_disabled: @@ -607,7 +607,7 @@ class _use_dep(object): for x in self.disabled: if x not in other_use: - if x not in iuse: + if not is_valid_flag(x): if x in self.missing_enabled: tokens.append(self._append_use_default("-" + x, x)) else: @@ -625,7 +625,7 @@ class _use_dep(object): continue if x not in other_use: - if x in iuse: + if is_valid_flag(x): tokens.append(self._append_use_default(x + "?", x)) else: if x in self.missing_disabled: @@ -636,7 +636,7 @@ class _use_dep(object): continue if x not in other_use: - if x not in iuse: + if not is_valid_flag(x): if x in self.missing_enabled: tokens.append(self._append_use_default("!" + x + "?", x)) else: @@ -647,7 +647,7 @@ class _use_dep(object): continue if x not in other_use: - if x in iuse: + if is_valid_flag(x): tokens.append(self._append_use_default(x + "=", x)) else: if x in self.missing_disabled: @@ -658,7 +658,7 @@ class _use_dep(object): continue if x not in other_use: - if x not in iuse: + if not is_valid_flag(x): if x in self.missing_enabled: tokens.append(self._append_use_default(x + "=", x)) else: @@ -669,7 +669,7 @@ class _use_dep(object): continue if x not in other_use: - if x in iuse: + if is_valid_flag(x): tokens.append(self._append_use_default("!" + x + "=", x)) else: if x in self.missing_disabled: @@ -680,7 +680,7 @@ class _use_dep(object): continue if x not in other_use: - if x not in iuse: + if not is_valid_flag(x): if x in self.missing_enabled: tokens.append(self._append_use_default("!" + x + "=", x)) else: @@ -874,14 +874,16 @@ class Atom(_atom_base): atom += str(self.use.evaluate_conditionals(use)) return Atom(atom, unevaluated_atom=self) - def violated_conditionals(self, other_use, iuse, parent_use=None): + def violated_conditionals(self, other_use, is_valid_flag, parent_use=None): """ Create an atom instance with any USE conditional removed, that is satisfied by other_use. - @param use: The set of enabled USE flags - @type use: set - @param use: The set of enabled USE flags to check against - @type use: set + @param other_use: The set of enabled USE flags + @type other_use: set + @param is_valid_flag: Function that decides if a use flag is referenceable in use deps + @type is_valid_flag: function + @param parent_use: Set of enabled use flags of the package requiring this atom + @type parent_use: set @rtype: Atom @return: an atom instance with any satisfied USE conditionals removed """ @@ -890,7 +892,7 @@ class Atom(_atom_base): atom = remove_slot(self) if self.slot: atom += ":%s" % self.slot - atom += str(self.use.violated_conditionals(other_use, iuse, parent_use)) + atom += str(self.use.violated_conditionals(other_use, is_valid_flag, parent_use)) return Atom(atom, unevaluated_atom=self) def _eval_qa_conditionals(self, use_mask, use_force): diff --git a/pym/portage/tests/dep/testAtom.py b/pym/portage/tests/dep/testAtom.py index fecf2bfa0..650e5c332 100644 --- a/pym/portage/tests/dep/testAtom.py +++ b/pym/portage/tests/dep/testAtom.py @@ -197,10 +197,18 @@ class TestAtom(TestCase): test_cases_xfail = ( ("dev-libs/A[a,b=,!c=,d?,!e?,-f]", [], ["a", "b", "c", "d", "e", "f"], None), ) - + + class use_flag_validator(object): + def __init__(self, iuse): + self.iuse = iuse + + def is_valid_flag(self, flag): + return flag in iuse + for atom, other_use, iuse, parent_use, expected_violated_atom in test_cases: a = Atom(atom) - violated_atom = a.violated_conditionals(other_use, iuse, parent_use) + validator = use_flag_validator(iuse) + violated_atom = a.violated_conditionals(other_use, validator.is_valid_flag, parent_use) if parent_use is None: fail_msg = "Atom: %s, other_use: %s, iuse: %s, parent_use: %s, got: %s, expected: %s" % \ (atom, " ".join(other_use), " ".join(iuse), "None", str(violated_atom), expected_violated_atom) @@ -211,8 +219,9 @@ class TestAtom(TestCase): for atom, other_use, iuse, parent_use in test_cases_xfail: a = Atom(atom) + validator = use_flag_validator(iuse) self.assertRaisesMsg(atom, InvalidAtom, \ - a.violated_conditionals, other_use, iuse, parent_use) + a.violated_conditionals, other_use, validator.is_valid_flag, parent_use) def test_evaluate_conditionals(self): test_cases = (