Atom.violated_conditionals: Use iuse.is_valid_flag instead of iuse.all
authorSebastian Luther <SebastianLuther@gmx.de>
Sat, 14 Aug 2010 06:43:34 +0000 (08:43 +0200)
committerZac Medico <zmedico@gentoo.org>
Sat, 14 Aug 2010 06:51:35 +0000 (23:51 -0700)
pym/_emerge/depgraph.py
pym/_emerge/resolver/slot_collision.py
pym/portage/dep/__init__.py
pym/portage/tests/dep/testAtom.py

index e3a47e8a70ce5a8885d17713005c85a867be8f54..643cc3edfa996a88848758417af9a2ea1fe1bf43 100644 (file)
@@ -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 = []
index b11fcb0c7e7f60fb8909786237609d9db6f2fdb8..70f4f7141bce99e6bb3586d4e48fb0a58852b0e7 100644 (file)
@@ -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
index 6c12c96d263ba3434b5471f8a2a2ec53c8478150..9e4242edf3802027b97fd70e9893ee34d9826d9f 100644 (file)
@@ -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):
index fecf2bfa0c909f46106d5a32136d9e60a96d27a1..650e5c332aa9fdbb3be19504b09bea70c71351ee 100644 (file)
@@ -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 = (