depgraph: pass use_reduce result to dep_check
authorZac Medico <zmedico@gentoo.org>
Fri, 8 Jun 2012 22:08:19 +0000 (15:08 -0700)
committerZac Medico <zmedico@gentoo.org>
Sat, 9 Jun 2012 00:27:12 +0000 (17:27 -0700)
This allows us to avoid extraneous use_reduce/paren_enclose calls.

pym/_emerge/depgraph.py
pym/portage/dep/__init__.py
pym/portage/dep/dep_check.py

index 935c37642e17e1723ae0c539c122a8ed94291e50..2e98be837322adaf202a0f87e9ff036023999fc5 100644 (file)
@@ -1456,7 +1456,10 @@ class depgraph(object):
 
                                try:
                                        dep_string = portage.dep.use_reduce(dep_string,
-                                               uselist=self._pkg_use_enabled(pkg), is_valid_flag=pkg.iuse.is_valid_flag)
+                                               uselist=self._pkg_use_enabled(pkg),
+                                               is_valid_flag=pkg.iuse.is_valid_flag,
+                                               opconvert=True, token_class=Atom,
+                                               eapi=pkg.metadata['EAPI'])
                                except portage.exception.InvalidDependString as e:
                                        if not pkg.installed:
                                                # should have been masked before it was selected
@@ -1468,7 +1471,9 @@ class depgraph(object):
                                        # practical to ignore this issue for installed packages.
                                        try:
                                                dep_string = portage.dep.use_reduce(dep_string,
-                                                       uselist=self._pkg_use_enabled(pkg))
+                                                       uselist=self._pkg_use_enabled(pkg),
+                                                       opconvert=True, token_class=Atom,
+                                                       eapi=pkg.metadata['EAPI'])
                                        except portage.exception.InvalidDependString as e:
                                                self._dynamic_config._masked_installed.add(pkg)
                                                del e
@@ -1489,9 +1494,6 @@ class depgraph(object):
                                if not dep_string:
                                        continue
 
-                               dep_string = portage.dep.paren_enclose(dep_string,
-                                       unevaluated_atom=True)
-
                                if not self._add_pkg_dep_string(
                                        pkg, dep_root, dep_priority, dep_string,
                                        allow_unsatisfied):
@@ -1525,7 +1527,9 @@ class depgraph(object):
                if debug:
                        writemsg_level("\nParent:    %s\n" % (pkg,),
                                noiselevel=-1, level=logging.DEBUG)
-                       writemsg_level("Depstring: %s\n" % (dep_string,),
+                       dep_repr = portage.dep.paren_enclose(dep_string,
+                               unevaluated_atom=True, opconvert=True)
+                       writemsg_level("Depstring: %s\n" % (dep_repr,),
                                noiselevel=-1, level=logging.DEBUG)
                        writemsg_level("Priority:  %s\n" % (dep_priority,),
                                noiselevel=-1, level=logging.DEBUG)
@@ -1847,34 +1851,22 @@ class depgraph(object):
                Yields non-disjunctive deps. Raises InvalidDependString when 
                necessary.
                """
-               i = 0
-               while i < len(dep_struct):
-                       x = dep_struct[i]
+               for x in dep_struct:
                        if isinstance(x, list):
-                               for y in self._queue_disjunctive_deps(
-                                       pkg, dep_root, dep_priority, x):
-                                       yield y
-                       elif x == "||":
-                               self._queue_disjunction(pkg, dep_root, dep_priority,
-                                       [ x, dep_struct[ i + 1 ] ] )
-                               i += 1
+                               if x and x[0] == "||":
+                                       self._queue_disjunction(pkg, dep_root, dep_priority, [x])
+                               else:
+                                       for y in self._queue_disjunctive_deps(
+                                               pkg, dep_root, dep_priority, x):
+                                               yield y
                        else:
-                               try:
-                                       x = portage.dep.Atom(x, eapi=pkg.metadata["EAPI"])
-                               except portage.exception.InvalidAtom:
-                                       if not pkg.installed:
-                                               raise portage.exception.InvalidDependString(
-                                                       "invalid atom: '%s'" % x)
+                               # Note: Eventually this will check for PROPERTIES=virtual
+                               # or whatever other metadata gets implemented for this
+                               # purpose.
+                               if x.cp.startswith('virtual/'):
+                                       self._queue_disjunction(pkg, dep_root, dep_priority, [x])
                                else:
-                                       # Note: Eventually this will check for PROPERTIES=virtual
-                                       # or whatever other metadata gets implemented for this
-                                       # purpose.
-                                       if x.cp.startswith('virtual/'):
-                                               self._queue_disjunction( pkg, dep_root,
-                                                       dep_priority, [ str(x) ] )
-                                       else:
-                                               yield str(x)
-                       i += 1
+                                       yield x
 
        def _queue_disjunction(self, pkg, dep_root, dep_priority, dep_struct):
                self._dynamic_config._dep_disjunctive_stack.append(
@@ -1887,10 +1879,8 @@ class depgraph(object):
                """
                pkg, dep_root, dep_priority, dep_struct = \
                        self._dynamic_config._dep_disjunctive_stack.pop()
-               dep_string = portage.dep.paren_enclose(dep_struct,
-                       unevaluated_atom=True)
                if not self._add_pkg_dep_string(
-                       pkg, dep_root, dep_priority, dep_string, allow_unsatisfied):
+                       pkg, dep_root, dep_priority, dep_struct, allow_unsatisfied):
                        return 0
                return 1
 
index 4cd081310e402e163b13184654800dc9292f6257..ade3a73a8cd6e6e197aa07fad94df17cf5e811d2 100644 (file)
@@ -250,7 +250,7 @@ class paren_normalize(list):
                                        self._zap_parens(x, dest)
                return dest
 
-def paren_enclose(mylist, unevaluated_atom=False):
+def paren_enclose(mylist, unevaluated_atom=False, opconvert=False):
        """
        Convert a list to a string with sublists enclosed with parens.
 
@@ -267,7 +267,10 @@ def paren_enclose(mylist, unevaluated_atom=False):
        mystrparts = []
        for x in mylist:
                if isinstance(x, list):
-                       mystrparts.append("( "+paren_enclose(x)+" )")
+                       if opconvert and x and x[0] == "||":
+                               mystrparts.append("%s ( %s )" % (x[0], paren_enclose(x[1:])))
+                       else:
+                               mystrparts.append("( %s )" % paren_enclose(x))
                else:
                        if unevaluated_atom:
                                x = getattr(x, 'unevaluated_atom', x)
index 99a5eb0116cd1127c30fcdcd3dc9e47879d7d2eb..d575ab3bca143f014d385eceea9ae00123d8ce78 100644 (file)
@@ -611,12 +611,15 @@ def dep_check(depstring, mydbapi, mysettings, use="yes", mode=None, myuse=None,
                if not current_parent.installed:
                        eapi = current_parent.metadata['EAPI']
 
-       try:
-               mysplit = use_reduce(depstring, uselist=myusesplit, masklist=mymasks, \
-                       matchall=(use=="all"), excludeall=useforce, opconvert=True, \
-                       token_class=Atom, eapi=eapi)
-       except InvalidDependString as e:
-               return [0, _unicode_decode("%s") % (e,)]
+       if isinstance(depstring, list):
+               mysplit = depstring
+       else:
+               try:
+                       mysplit = use_reduce(depstring, uselist=myusesplit,
+                       masklist=mymasks, matchall=(use=="all"), excludeall=useforce,
+                       opconvert=True, token_class=Atom, eapi=eapi)
+               except InvalidDependString as e:
+                       return [0, _unicode_decode("%s") % (e,)]
 
        if mysplit == []:
                #dependencies were reduced to nothing