commit:     0c42cc962e1926ecbdc83d903a2804f9e037f2a9
Author:     Pin-yen Lin <treapking <AT> chromium <DOT> org>
AuthorDate: Fri Nov 25 03:36:26 2022 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Nov 28 00:37:41 2022 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=0c42cc96

Move and rename check_reverse_dependencies

Move the function outside the original scope and rename the function to
_slot_operator_check_reverse_dependencies to accommodate the coding
style.

Signed-off-by: Pin-yen Lin <treapking <AT> chromium.org>
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/_emerge/depgraph.py | 226 ++++++++++++++++++++++++------------------------
 1 file changed, 113 insertions(+), 113 deletions(-)

diff --git a/lib/_emerge/depgraph.py b/lib/_emerge/depgraph.py
index e556d6616..bb0824324 100644
--- a/lib/_emerge/depgraph.py
+++ b/lib/_emerge/depgraph.py
@@ -2240,6 +2240,111 @@ class depgraph:
 
         return None
 
+    def _slot_operator_check_reverse_dependencies(
+        self, existing_pkg, candidate_pkg, replacement_parent=None
+    ):
+        """
+        Check if candidate_pkg satisfies all of existing_pkg's non-
+        slot operator parents.
+        """
+        debug = "--debug" in self._frozen_config.myopts
+        built_slot_operator_parents = set()
+        for parent, atom in 
self._dynamic_config._parent_atoms.get(existing_pkg, []):
+            if atom.soname or atom.slot_operator_built:
+                built_slot_operator_parents.add(parent)
+
+        for parent, atom in 
self._dynamic_config._parent_atoms.get(existing_pkg, []):
+            if isinstance(parent, Package):
+                if parent in built_slot_operator_parents:
+                    if hasattr(atom, "_orig_atom"):
+                        # If atom is the result of virtual expansion, then
+                        # derefrence it to _orig_atom so that it will be 
correctly
+                        # handled as a built slot operator dependency when
+                        # appropriate (see bug 764764).
+                        atom = atom._orig_atom
+                    # This parent may need to be rebuilt, therefore
+                    # discard its soname and built slot operator
+                    # dependency components which are not necessarily
+                    # relevant.
+                    if atom.soname:
+                        continue
+                    elif atom.package and atom.slot_operator_built:
+                        # This discards the slot/subslot component.
+                        atom = atom.with_slot("=")
+
+                if replacement_parent is not None and (
+                    replacement_parent.slot_atom == parent.slot_atom
+                    or replacement_parent.cpv == parent.cpv
+                ):
+                    # This parent is irrelevant because we intend to
+                    # replace it with replacement_parent.
+                    continue
+
+                if any(
+                    pkg is not parent
+                    and (pkg.slot_atom == parent.slot_atom or pkg.cpv == 
parent.cpv)
+                    for pkg in self._dynamic_config._package_tracker.match(
+                        parent.root, Atom(parent.cp)
+                    )
+                ):
+                    # This parent may need to be eliminated due to a
+                    # slot conflict,  so its dependencies aren't
+                    # necessarily relevant.
+                    continue
+
+                if not self._too_deep(
+                    parent.depth
+                ) and not self._frozen_config.excluded_pkgs.findAtomForPackage(
+                    parent, modified_use=self._pkg_use_enabled(parent)
+                ):
+                    # Check for common reasons that the parent's
+                    # dependency might be irrelevant.
+                    if self._upgrade_available(parent):
+                        # This parent could be replaced by
+                        # an upgrade (bug 584626).
+                        continue
+                    if parent.installed and self._in_blocker_conflict(parent):
+                        # This parent could be uninstalled in order
+                        # to solve a blocker conflict (bug 612772).
+                        continue
+                    if self._dynamic_config.digraph.has_edge(parent, 
existing_pkg):
+                        # There is a direct circular dependency between
+                        # parent and existing_pkg. This type of
+                        # relationship tends to prevent updates
+                        # of packages (bug 612874). Since candidate_pkg
+                        # is available, we risk a missed update if we
+                        # don't try to eliminate this parent from the
+                        # graph. Therefore, we give candidate_pkg a
+                        # chance, and assume that it will be masked
+                        # by backtracking if necessary.
+                        continue
+
+            atom_set = InternalPackageSet(initial_atoms=(atom,), 
allow_repo=True)
+            if not atom_set.findAtomForPackage(
+                candidate_pkg, 
modified_use=self._pkg_use_enabled(candidate_pkg)
+            ):
+                if debug:
+                    parent_atoms = []
+                    for (
+                        other_parent,
+                        other_atom,
+                    ) in self._dynamic_config._parent_atoms.get(existing_pkg, 
[]):
+                        if other_parent is parent:
+                            parent_atoms.append(other_atom)
+                    msg = (
+                        "",
+                        "",
+                        "_slot_operator_check_reverse_dependencies:",
+                        "   candidate package does not match atom '%s': %s"
+                        % (atom, candidate_pkg),
+                        "   parent: %s" % parent,
+                        "   parent atoms: %s" % " ".join(parent_atoms),
+                        "",
+                    )
+                    writemsg_level("\n".join(msg), noiselevel=-1, 
level=logging.DEBUG)
+                return False
+        return True
+
     def _slot_operator_update_probe(
         self, dep, new_child_slot=False, slot_conflict=False, 
autounmask_level=None
     ):
@@ -2274,116 +2379,6 @@ class depgraph:
         want_downgrade = None
         want_downgrade_parent = None
 
-        def check_reverse_dependencies(
-            existing_pkg, candidate_pkg, replacement_parent=None
-        ):
-            """
-            Check if candidate_pkg satisfies all of existing_pkg's non-
-            slot operator parents.
-            """
-            built_slot_operator_parents = set()
-            for parent, atom in self._dynamic_config._parent_atoms.get(
-                existing_pkg, []
-            ):
-                if atom.soname or atom.slot_operator_built:
-                    built_slot_operator_parents.add(parent)
-
-            for parent, atom in self._dynamic_config._parent_atoms.get(
-                existing_pkg, []
-            ):
-                if isinstance(parent, Package):
-                    if parent in built_slot_operator_parents:
-                        if hasattr(atom, "_orig_atom"):
-                            # If atom is the result of virtual expansion, then
-                            # derefrence it to _orig_atom so that it will be 
correctly
-                            # handled as a built slot operator dependency when
-                            # appropriate (see bug 764764).
-                            atom = atom._orig_atom
-                        # This parent may need to be rebuilt, therefore
-                        # discard its soname and built slot operator
-                        # dependency components which are not necessarily
-                        # relevant.
-                        if atom.soname:
-                            continue
-                        elif atom.package and atom.slot_operator_built:
-                            # This discards the slot/subslot component.
-                            atom = atom.with_slot("=")
-
-                    if replacement_parent is not None and (
-                        replacement_parent.slot_atom == parent.slot_atom
-                        or replacement_parent.cpv == parent.cpv
-                    ):
-                        # This parent is irrelevant because we intend to
-                        # replace it with replacement_parent.
-                        continue
-
-                    if any(
-                        pkg is not parent
-                        and (pkg.slot_atom == parent.slot_atom or pkg.cpv == 
parent.cpv)
-                        for pkg in self._dynamic_config._package_tracker.match(
-                            parent.root, Atom(parent.cp)
-                        )
-                    ):
-                        # This parent may need to be eliminated due to a
-                        # slot conflict,  so its dependencies aren't
-                        # necessarily relevant.
-                        continue
-
-                    if not self._too_deep(
-                        parent.depth
-                    ) and not 
self._frozen_config.excluded_pkgs.findAtomForPackage(
-                        parent, modified_use=self._pkg_use_enabled(parent)
-                    ):
-                        # Check for common reasons that the parent's
-                        # dependency might be irrelevant.
-                        if self._upgrade_available(parent):
-                            # This parent could be replaced by
-                            # an upgrade (bug 584626).
-                            continue
-                        if parent.installed and 
self._in_blocker_conflict(parent):
-                            # This parent could be uninstalled in order
-                            # to solve a blocker conflict (bug 612772).
-                            continue
-                        if self._dynamic_config.digraph.has_edge(parent, 
existing_pkg):
-                            # There is a direct circular dependency between
-                            # parent and existing_pkg. This type of
-                            # relationship tends to prevent updates
-                            # of packages (bug 612874). Since candidate_pkg
-                            # is available, we risk a missed update if we
-                            # don't try to eliminate this parent from the
-                            # graph. Therefore, we give candidate_pkg a
-                            # chance, and assume that it will be masked
-                            # by backtracking if necessary.
-                            continue
-
-                atom_set = InternalPackageSet(initial_atoms=(atom,), 
allow_repo=True)
-                if not atom_set.findAtomForPackage(
-                    candidate_pkg, 
modified_use=self._pkg_use_enabled(candidate_pkg)
-                ):
-                    if debug:
-                        parent_atoms = []
-                        for (
-                            other_parent,
-                            other_atom,
-                        ) in 
self._dynamic_config._parent_atoms.get(existing_pkg, []):
-                            if other_parent is parent:
-                                parent_atoms.append(other_atom)
-                        msg = (
-                            "",
-                            "",
-                            "check_reverse_dependencies:",
-                            "   candidate package does not match atom '%s': %s"
-                            % (atom, candidate_pkg),
-                            "   parent: %s" % parent,
-                            "   parent atoms: %s" % " ".join(parent_atoms),
-                            "",
-                        )
-                        writemsg_level(
-                            "\n".join(msg), noiselevel=-1, level=logging.DEBUG
-                        )
-                    return False
-            return True
-
         for replacement_parent in self._iter_similar_available(
             dep.parent, dep.parent.slot_atom, autounmask_level=autounmask_level
         ):
@@ -2397,7 +2392,9 @@ class depgraph:
                 if not want_downgrade_parent:
                     continue
 
-            if not check_reverse_dependencies(dep.parent, replacement_parent):
+            if not self._slot_operator_check_reverse_dependencies(
+                dep.parent, replacement_parent
+            ):
                 continue
 
             selected_atoms = None
@@ -2510,8 +2507,11 @@ class depgraph:
                         if atom_not_selected:
                             break
 
-                    if not insignificant and check_reverse_dependencies(
-                        dep.child, pkg, replacement_parent=replacement_parent
+                    if (
+                        not insignificant
+                        and self._slot_operator_check_reverse_dependencies(
+                            dep.child, pkg, 
replacement_parent=replacement_parent
+                        )
                     ):
 
                         candidate_pkg_atoms.append((pkg, unevaluated_atom or 
atom))

Reply via email to