Skip to content

Commit ef49c0a

Browse files
authored
Merge pull request #3768 from pypa/debt/lint
Extract method for resolving the dist. Fixes complexity lint.
2 parents 82eee6a + f964b01 commit ef49c0a

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

pkg_resources/__init__.py

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,7 @@ def add(self, dist, entry=None, insert=True, replace=False):
766766
keys2.append(dist.key)
767767
self._added_new(dist)
768768

769-
# FIXME: 'WorkingSet.resolve' is too complex (11)
770-
def resolve( # noqa: C901
769+
def resolve(
771770
self,
772771
requirements,
773772
env=None,
@@ -823,32 +822,9 @@ def resolve( # noqa: C901
823822
if not req_extras.markers_pass(req, extras):
824823
continue
825824

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+
)
852828

853829
# push the new requirements onto the stack
854830
new_requirements = dist.requires(req.extras)[::-1]
@@ -864,6 +840,37 @@ def resolve( # noqa: C901
864840
# return list of distros to activate
865841
return to_activate
866842

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+
867874
def find_plugins(self, plugin_env, full_env=None, installer=None, fallback=True):
868875
"""Find all activatable distributions in `plugin_env`
869876

0 commit comments

Comments
 (0)