1 |
Move the function outside the original scope and rename the function to |
2 |
_slot_operator_check_reverse_dependencies to accommodate the coding |
3 |
style. |
4 |
|
5 |
Signed-off-by: Pin-yen Lin <treapking@××××××××.org> |
6 |
--- |
7 |
lib/_emerge/depgraph.py | 232 +++++++++++++++++++++------------------- |
8 |
1 file changed, 119 insertions(+), 113 deletions(-) |
9 |
|
10 |
diff --git a/lib/_emerge/depgraph.py b/lib/_emerge/depgraph.py |
11 |
index c976f8205..ce6cabcc1 100644 |
12 |
--- a/lib/_emerge/depgraph.py |
13 |
+++ b/lib/_emerge/depgraph.py |
14 |
@@ -2240,6 +2240,117 @@ class depgraph: |
15 |
|
16 |
return None |
17 |
|
18 |
+ def _slot_operator_check_reverse_dependencies( |
19 |
+ self, existing_pkg, candidate_pkg, replacement_parent=None |
20 |
+ ): |
21 |
+ """ |
22 |
+ Check if candidate_pkg satisfies all of existing_pkg's non- |
23 |
+ slot operator parents. |
24 |
+ """ |
25 |
+ debug = "--debug" in self._frozen_config.myopts |
26 |
+ built_slot_operator_parents = set() |
27 |
+ for parent, atom in self._dynamic_config._parent_atoms.get( |
28 |
+ existing_pkg, [] |
29 |
+ ): |
30 |
+ if atom.soname or atom.slot_operator_built: |
31 |
+ built_slot_operator_parents.add(parent) |
32 |
+ |
33 |
+ for parent, atom in self._dynamic_config._parent_atoms.get( |
34 |
+ existing_pkg, [] |
35 |
+ ): |
36 |
+ if isinstance(parent, Package): |
37 |
+ if parent in built_slot_operator_parents: |
38 |
+ if hasattr(atom, "_orig_atom"): |
39 |
+ # If atom is the result of virtual expansion, then |
40 |
+ # derefrence it to _orig_atom so that it will be correctly |
41 |
+ # handled as a built slot operator dependency when |
42 |
+ # appropriate (see bug 764764). |
43 |
+ atom = atom._orig_atom |
44 |
+ # This parent may need to be rebuilt, therefore |
45 |
+ # discard its soname and built slot operator |
46 |
+ # dependency components which are not necessarily |
47 |
+ # relevant. |
48 |
+ if atom.soname: |
49 |
+ continue |
50 |
+ elif atom.package and atom.slot_operator_built: |
51 |
+ # This discards the slot/subslot component. |
52 |
+ atom = atom.with_slot("=") |
53 |
+ |
54 |
+ if replacement_parent is not None and ( |
55 |
+ replacement_parent.slot_atom == parent.slot_atom |
56 |
+ or replacement_parent.cpv == parent.cpv |
57 |
+ ): |
58 |
+ # This parent is irrelevant because we intend to |
59 |
+ # replace it with replacement_parent. |
60 |
+ continue |
61 |
+ |
62 |
+ if any( |
63 |
+ pkg is not parent |
64 |
+ and (pkg.slot_atom == parent.slot_atom or pkg.cpv == parent.cpv) |
65 |
+ for pkg in self._dynamic_config._package_tracker.match( |
66 |
+ parent.root, Atom(parent.cp) |
67 |
+ ) |
68 |
+ ): |
69 |
+ # This parent may need to be eliminated due to a |
70 |
+ # slot conflict, so its dependencies aren't |
71 |
+ # necessarily relevant. |
72 |
+ continue |
73 |
+ |
74 |
+ if not self._too_deep( |
75 |
+ parent.depth |
76 |
+ ) and not self._frozen_config.excluded_pkgs.findAtomForPackage( |
77 |
+ parent, modified_use=self._pkg_use_enabled(parent) |
78 |
+ ): |
79 |
+ # Check for common reasons that the parent's |
80 |
+ # dependency might be irrelevant. |
81 |
+ if self._upgrade_available(parent): |
82 |
+ # This parent could be replaced by |
83 |
+ # an upgrade (bug 584626). |
84 |
+ continue |
85 |
+ if parent.installed and self._in_blocker_conflict(parent): |
86 |
+ # This parent could be uninstalled in order |
87 |
+ # to solve a blocker conflict (bug 612772). |
88 |
+ continue |
89 |
+ if self._dynamic_config.digraph.has_edge(parent, existing_pkg): |
90 |
+ # There is a direct circular dependency between |
91 |
+ # parent and existing_pkg. This type of |
92 |
+ # relationship tends to prevent updates |
93 |
+ # of packages (bug 612874). Since candidate_pkg |
94 |
+ # is available, we risk a missed update if we |
95 |
+ # don't try to eliminate this parent from the |
96 |
+ # graph. Therefore, we give candidate_pkg a |
97 |
+ # chance, and assume that it will be masked |
98 |
+ # by backtracking if necessary. |
99 |
+ continue |
100 |
+ |
101 |
+ atom_set = InternalPackageSet(initial_atoms=(atom,), allow_repo=True) |
102 |
+ if not atom_set.findAtomForPackage( |
103 |
+ candidate_pkg, modified_use=self._pkg_use_enabled(candidate_pkg) |
104 |
+ ): |
105 |
+ if debug: |
106 |
+ parent_atoms = [] |
107 |
+ for ( |
108 |
+ other_parent, |
109 |
+ other_atom, |
110 |
+ ) in self._dynamic_config._parent_atoms.get(existing_pkg, []): |
111 |
+ if other_parent is parent: |
112 |
+ parent_atoms.append(other_atom) |
113 |
+ msg = ( |
114 |
+ "", |
115 |
+ "", |
116 |
+ "_slot_operator_check_reverse_dependencies:", |
117 |
+ " candidate package does not match atom '%s': %s" |
118 |
+ % (atom, candidate_pkg), |
119 |
+ " parent: %s" % parent, |
120 |
+ " parent atoms: %s" % " ".join(parent_atoms), |
121 |
+ "", |
122 |
+ ) |
123 |
+ writemsg_level( |
124 |
+ "\n".join(msg), noiselevel=-1, level=logging.DEBUG |
125 |
+ ) |
126 |
+ return False |
127 |
+ return True |
128 |
+ |
129 |
def _slot_operator_update_probe( |
130 |
self, dep, new_child_slot=False, slot_conflict=False, autounmask_level=None |
131 |
): |
132 |
@@ -2274,116 +2385,6 @@ class depgraph: |
133 |
want_downgrade = None |
134 |
want_downgrade_parent = None |
135 |
|
136 |
- def check_reverse_dependencies( |
137 |
- existing_pkg, candidate_pkg, replacement_parent=None |
138 |
- ): |
139 |
- """ |
140 |
- Check if candidate_pkg satisfies all of existing_pkg's non- |
141 |
- slot operator parents. |
142 |
- """ |
143 |
- built_slot_operator_parents = set() |
144 |
- for parent, atom in self._dynamic_config._parent_atoms.get( |
145 |
- existing_pkg, [] |
146 |
- ): |
147 |
- if atom.soname or atom.slot_operator_built: |
148 |
- built_slot_operator_parents.add(parent) |
149 |
- |
150 |
- for parent, atom in self._dynamic_config._parent_atoms.get( |
151 |
- existing_pkg, [] |
152 |
- ): |
153 |
- if isinstance(parent, Package): |
154 |
- if parent in built_slot_operator_parents: |
155 |
- if hasattr(atom, "_orig_atom"): |
156 |
- # If atom is the result of virtual expansion, then |
157 |
- # derefrence it to _orig_atom so that it will be correctly |
158 |
- # handled as a built slot operator dependency when |
159 |
- # appropriate (see bug 764764). |
160 |
- atom = atom._orig_atom |
161 |
- # This parent may need to be rebuilt, therefore |
162 |
- # discard its soname and built slot operator |
163 |
- # dependency components which are not necessarily |
164 |
- # relevant. |
165 |
- if atom.soname: |
166 |
- continue |
167 |
- elif atom.package and atom.slot_operator_built: |
168 |
- # This discards the slot/subslot component. |
169 |
- atom = atom.with_slot("=") |
170 |
- |
171 |
- if replacement_parent is not None and ( |
172 |
- replacement_parent.slot_atom == parent.slot_atom |
173 |
- or replacement_parent.cpv == parent.cpv |
174 |
- ): |
175 |
- # This parent is irrelevant because we intend to |
176 |
- # replace it with replacement_parent. |
177 |
- continue |
178 |
- |
179 |
- if any( |
180 |
- pkg is not parent |
181 |
- and (pkg.slot_atom == parent.slot_atom or pkg.cpv == parent.cpv) |
182 |
- for pkg in self._dynamic_config._package_tracker.match( |
183 |
- parent.root, Atom(parent.cp) |
184 |
- ) |
185 |
- ): |
186 |
- # This parent may need to be eliminated due to a |
187 |
- # slot conflict, so its dependencies aren't |
188 |
- # necessarily relevant. |
189 |
- continue |
190 |
- |
191 |
- if not self._too_deep( |
192 |
- parent.depth |
193 |
- ) and not self._frozen_config.excluded_pkgs.findAtomForPackage( |
194 |
- parent, modified_use=self._pkg_use_enabled(parent) |
195 |
- ): |
196 |
- # Check for common reasons that the parent's |
197 |
- # dependency might be irrelevant. |
198 |
- if self._upgrade_available(parent): |
199 |
- # This parent could be replaced by |
200 |
- # an upgrade (bug 584626). |
201 |
- continue |
202 |
- if parent.installed and self._in_blocker_conflict(parent): |
203 |
- # This parent could be uninstalled in order |
204 |
- # to solve a blocker conflict (bug 612772). |
205 |
- continue |
206 |
- if self._dynamic_config.digraph.has_edge(parent, existing_pkg): |
207 |
- # There is a direct circular dependency between |
208 |
- # parent and existing_pkg. This type of |
209 |
- # relationship tends to prevent updates |
210 |
- # of packages (bug 612874). Since candidate_pkg |
211 |
- # is available, we risk a missed update if we |
212 |
- # don't try to eliminate this parent from the |
213 |
- # graph. Therefore, we give candidate_pkg a |
214 |
- # chance, and assume that it will be masked |
215 |
- # by backtracking if necessary. |
216 |
- continue |
217 |
- |
218 |
- atom_set = InternalPackageSet(initial_atoms=(atom,), allow_repo=True) |
219 |
- if not atom_set.findAtomForPackage( |
220 |
- candidate_pkg, modified_use=self._pkg_use_enabled(candidate_pkg) |
221 |
- ): |
222 |
- if debug: |
223 |
- parent_atoms = [] |
224 |
- for ( |
225 |
- other_parent, |
226 |
- other_atom, |
227 |
- ) in self._dynamic_config._parent_atoms.get(existing_pkg, []): |
228 |
- if other_parent is parent: |
229 |
- parent_atoms.append(other_atom) |
230 |
- msg = ( |
231 |
- "", |
232 |
- "", |
233 |
- "check_reverse_dependencies:", |
234 |
- " candidate package does not match atom '%s': %s" |
235 |
- % (atom, candidate_pkg), |
236 |
- " parent: %s" % parent, |
237 |
- " parent atoms: %s" % " ".join(parent_atoms), |
238 |
- "", |
239 |
- ) |
240 |
- writemsg_level( |
241 |
- "\n".join(msg), noiselevel=-1, level=logging.DEBUG |
242 |
- ) |
243 |
- return False |
244 |
- return True |
245 |
- |
246 |
for replacement_parent in self._iter_similar_available( |
247 |
dep.parent, dep.parent.slot_atom, autounmask_level=autounmask_level |
248 |
): |
249 |
@@ -2397,7 +2398,9 @@ class depgraph: |
250 |
if not want_downgrade_parent: |
251 |
continue |
252 |
|
253 |
- if not check_reverse_dependencies(dep.parent, replacement_parent): |
254 |
+ if not self._slot_operator_check_reverse_dependencies( |
255 |
+ dep.parent, replacement_parent |
256 |
+ ): |
257 |
continue |
258 |
|
259 |
selected_atoms = None |
260 |
@@ -2510,8 +2513,11 @@ class depgraph: |
261 |
if atom_not_selected: |
262 |
break |
263 |
|
264 |
- if not insignificant and check_reverse_dependencies( |
265 |
- dep.child, pkg, replacement_parent=replacement_parent |
266 |
+ if ( |
267 |
+ not insignificant |
268 |
+ and self._slot_operator_check_reverse_dependencies( |
269 |
+ dep.child, pkg, replacement_parent=replacement_parent |
270 |
+ ) |
271 |
): |
272 |
|
273 |
candidate_pkg_atoms.append((pkg, unevaluated_atom or atom)) |
274 |
-- |
275 |
2.38.1.584.g0f3c55d4c2-goog |