Skip to content

Commit 2ba18b2

Browse files
committed
Extract method for resolving the dist. Fixes complexity lint.
1 parent 583836f commit 2ba18b2

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

pkg_resources/__init__.py

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,7 @@ def add(self, dist, entry=None, insert=True, replace=False):
720720
keys2.append(dist.key)
721721
self._added_new(dist)
722722

723-
# FIXME: 'WorkingSet.resolve' is too complex (11)
724-
def resolve(self, requirements, env=None, installer=None, # noqa: C901
723+
def resolve(self, requirements, env=None, installer=None,
725724
replace_conflicting=False, extras=None):
726725
"""List all distributions needed to (recursively) meet `requirements`
727726
@@ -771,33 +770,9 @@ def resolve(self, requirements, env=None, installer=None, # noqa: C901
771770
if not req_extras.markers_pass(req, extras):
772771
continue
773772

774-
dist = best.get(req.key)
775-
if dist is None:
776-
# Find the best distribution and add it to the map
777-
dist = self.by_key.get(req.key)
778-
if dist is None or (dist not in req and replace_conflicting):
779-
ws = self
780-
if env is None:
781-
if dist is None:
782-
env = Environment(self.entries)
783-
else:
784-
# Use an empty environment and workingset to avoid
785-
# any further conflicts with the conflicting
786-
# distribution
787-
env = Environment([])
788-
ws = WorkingSet([])
789-
dist = best[req.key] = env.best_match(
790-
req, ws, installer,
791-
replace_conflicting=replace_conflicting
792-
)
793-
if dist is None:
794-
requirers = required_by.get(req, None)
795-
raise DistributionNotFound(req, requirers)
796-
to_activate.append(dist)
797-
if dist not in req:
798-
# Oops, the "best" so far conflicts with a dependency
799-
dependent_req = required_by[req]
800-
raise VersionConflict(dist, req).with_context(dependent_req)
773+
dist = self._resolve_dist(
774+
req, best, replace_conflicting, env, installer, required_by, to_activate
775+
)
801776

802777
# push the new requirements onto the stack
803778
new_requirements = dist.requires(req.extras)[::-1]
@@ -813,8 +788,38 @@ def resolve(self, requirements, env=None, installer=None, # noqa: C901
813788
# return list of distros to activate
814789
return to_activate
815790

816-
def find_plugins(
817-
self, plugin_env, full_env=None, installer=None, fallback=True):
791+
def _resolve_dist(
792+
self, req, best, replace_conflicting, env, installer, required_by, to_activate
793+
):
794+
dist = best.get(req.key)
795+
if dist is None:
796+
# Find the best distribution and add it to the map
797+
dist = self.by_key.get(req.key)
798+
if dist is None or (dist not in req and replace_conflicting):
799+
ws = self
800+
if env is None:
801+
if dist is None:
802+
env = Environment(self.entries)
803+
else:
804+
# Use an empty environment and workingset to avoid
805+
# any further conflicts with the conflicting
806+
# distribution
807+
env = Environment([])
808+
ws = WorkingSet([])
809+
dist = best[req.key] = env.best_match(
810+
req, ws, installer, replace_conflicting=replace_conflicting
811+
)
812+
if dist is None:
813+
requirers = required_by.get(req, None)
814+
raise DistributionNotFound(req, requirers)
815+
to_activate.append(dist)
816+
if dist not in req:
817+
# Oops, the "best" so far conflicts with a dependency
818+
dependent_req = required_by[req]
819+
raise VersionConflict(dist, req).with_context(dependent_req)
820+
return dist
821+
822+
def find_plugins(self, plugin_env, full_env=None, installer=None, fallback=True):
818823
"""Find all activatable distributions in `plugin_env`
819824
820825
Example usage::

0 commit comments

Comments
 (0)