@@ -179,16 +179,10 @@ def get_preference(
179179 # free, so we always do it first to avoid needless work if it fails.
180180 requires_python = identifier == REQUIRES_PYTHON_IDENTIFIER
181181
182- # Prefer the causes of backtracking on the assumption that the problem
183- # resolving the dependency tree is related to the failures that caused
184- # the backtracking
185- backtrack_cause = self .is_backtrack_cause (identifier , backtrack_causes )
186-
187182 return (
188183 not requires_python ,
189184 not direct ,
190185 not pinned ,
191- not backtrack_cause ,
192186 inferred_depth ,
193187 requested_order ,
194188 not unfree ,
@@ -243,20 +237,27 @@ def get_dependencies(self, candidate: Candidate) -> Sequence[Requirement]:
243237 with_requires = not self ._ignore_dependencies
244238 return [r for r in candidate .iter_dependencies (with_requires ) if r is not None ]
245239
246- @staticmethod
247- def is_backtrack_cause (
248- identifier : str , backtrack_causes : Sequence ["PreferenceInformation" ]
249- ) -> bool :
250- for backtrack_cause in backtrack_causes :
251- if identifier == backtrack_cause .requirement .name :
252- return True
253- if backtrack_cause .parent and identifier == backtrack_cause .parent .name :
254- return True
255- return False
256-
257240 def filter_unsatisfied_names (
258241 self ,
259242 unsatisfied_names : Iterable [str ],
260243 causes : Sequence ["PreferenceInformation" ],
261244 ) -> Iterable [str ]:
245+ """
246+ Prefer backtracking on unsatisfied names that are causes
247+ """
248+ if not causes :
249+ return unsatisfied_names
250+
251+ # Extract the causes and parents names
252+ causes_names = set ()
253+ for cause in causes :
254+ causes_names .add (cause .requirement .name )
255+ if cause .parent :
256+ causes_names .add (cause .parent .name )
257+
258+ unsatisfied_causes_names = set (unsatisfied_names ) & causes_names
259+
260+ if unsatisfied_causes_names :
261+ return unsatisfied_causes_names
262+
262263 return unsatisfied_names
0 commit comments