@@ -766,8 +766,7 @@ def add(self, dist, entry=None, insert=True, replace=False):
766
766
keys2 .append (dist .key )
767
767
self ._added_new (dist )
768
768
769
- # FIXME: 'WorkingSet.resolve' is too complex (11)
770
- def resolve ( # noqa: C901
769
+ def resolve (
771
770
self ,
772
771
requirements ,
773
772
env = None ,
@@ -823,32 +822,9 @@ def resolve( # noqa: C901
823
822
if not req_extras .markers_pass (req , extras ):
824
823
continue
825
824
826
- dist = best .get (req .key )
827
- if dist is None :
828
- # Find the best distribution and add it to the map
829
- dist = self .by_key .get (req .key )
830
- if dist is None or (dist not in req and replace_conflicting ):
831
- ws = self
832
- if env is None :
833
- if dist is None :
834
- env = Environment (self .entries )
835
- else :
836
- # Use an empty environment and workingset to avoid
837
- # any further conflicts with the conflicting
838
- # distribution
839
- env = Environment ([])
840
- ws = WorkingSet ([])
841
- dist = best [req .key ] = env .best_match (
842
- req , ws , installer , replace_conflicting = replace_conflicting
843
- )
844
- if dist is None :
845
- requirers = required_by .get (req , None )
846
- raise DistributionNotFound (req , requirers )
847
- to_activate .append (dist )
848
- if dist not in req :
849
- # Oops, the "best" so far conflicts with a dependency
850
- dependent_req = required_by [req ]
851
- raise VersionConflict (dist , req ).with_context (dependent_req )
825
+ dist = self ._resolve_dist (
826
+ req , best , replace_conflicting , env , installer , required_by , to_activate
827
+ )
852
828
853
829
# push the new requirements onto the stack
854
830
new_requirements = dist .requires (req .extras )[::- 1 ]
@@ -864,6 +840,37 @@ def resolve( # noqa: C901
864
840
# return list of distros to activate
865
841
return to_activate
866
842
843
+ def _resolve_dist (
844
+ self , req , best , replace_conflicting , env , installer , required_by , to_activate
845
+ ):
846
+ dist = best .get (req .key )
847
+ if dist is None :
848
+ # Find the best distribution and add it to the map
849
+ dist = self .by_key .get (req .key )
850
+ if dist is None or (dist not in req and replace_conflicting ):
851
+ ws = self
852
+ if env is None :
853
+ if dist is None :
854
+ env = Environment (self .entries )
855
+ else :
856
+ # Use an empty environment and workingset to avoid
857
+ # any further conflicts with the conflicting
858
+ # distribution
859
+ env = Environment ([])
860
+ ws = WorkingSet ([])
861
+ dist = best [req .key ] = env .best_match (
862
+ req , ws , installer , replace_conflicting = replace_conflicting
863
+ )
864
+ if dist is None :
865
+ requirers = required_by .get (req , None )
866
+ raise DistributionNotFound (req , requirers )
867
+ to_activate .append (dist )
868
+ if dist not in req :
869
+ # Oops, the "best" so far conflicts with a dependency
870
+ dependent_req = required_by [req ]
871
+ raise VersionConflict (dist , req ).with_context (dependent_req )
872
+ return dist
873
+
867
874
def find_plugins (self , plugin_env , full_env = None , installer = None , fallback = True ):
868
875
"""Find all activatable distributions in `plugin_env`
869
876
0 commit comments