summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2023-01-13 10:43:32 -0500
committerJason R. Coombs <jaraco@jaraco.com>2023-01-13 10:43:32 -0500
commit2ba18b2e9e2a70579a2713f49fa34044eb8dae8f (patch)
tree9f666939812d302d26329a50c8a8613faa2069e5
parent583836fd4110a03ac45a0e26ae58f54046de124b (diff)
downloadpython-setuptools-git-2ba18b2e9e2a70579a2713f49fa34044eb8dae8f.tar.gz
Extract method for resolving the dist. Fixes complexity lint.
-rw-r--r--pkg_resources/__init__.py67
1 files changed, 36 insertions, 31 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index d59226af..79b17619 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -720,8 +720,7 @@ class WorkingSet:
keys2.append(dist.key)
self._added_new(dist)
- # FIXME: 'WorkingSet.resolve' is too complex (11)
- def resolve(self, requirements, env=None, installer=None, # noqa: C901
+ def resolve(self, requirements, env=None, installer=None,
replace_conflicting=False, extras=None):
"""List all distributions needed to (recursively) meet `requirements`
@@ -771,33 +770,9 @@ class WorkingSet:
if not req_extras.markers_pass(req, extras):
continue
- dist = best.get(req.key)
- if dist is None:
- # Find the best distribution and add it to the map
- dist = self.by_key.get(req.key)
- if dist is None or (dist not in req and replace_conflicting):
- ws = self
- if env is None:
- if dist is None:
- env = Environment(self.entries)
- else:
- # Use an empty environment and workingset to avoid
- # any further conflicts with the conflicting
- # distribution
- env = Environment([])
- ws = WorkingSet([])
- dist = best[req.key] = env.best_match(
- req, ws, installer,
- replace_conflicting=replace_conflicting
- )
- if dist is None:
- requirers = required_by.get(req, None)
- raise DistributionNotFound(req, requirers)
- to_activate.append(dist)
- if dist not in req:
- # Oops, the "best" so far conflicts with a dependency
- dependent_req = required_by[req]
- raise VersionConflict(dist, req).with_context(dependent_req)
+ dist = self._resolve_dist(
+ req, best, replace_conflicting, env, installer, required_by, to_activate
+ )
# push the new requirements onto the stack
new_requirements = dist.requires(req.extras)[::-1]
@@ -813,8 +788,38 @@ class WorkingSet:
# return list of distros to activate
return to_activate
- def find_plugins(
- self, plugin_env, full_env=None, installer=None, fallback=True):
+ def _resolve_dist(
+ self, req, best, replace_conflicting, env, installer, required_by, to_activate
+ ):
+ dist = best.get(req.key)
+ if dist is None:
+ # Find the best distribution and add it to the map
+ dist = self.by_key.get(req.key)
+ if dist is None or (dist not in req and replace_conflicting):
+ ws = self
+ if env is None:
+ if dist is None:
+ env = Environment(self.entries)
+ else:
+ # Use an empty environment and workingset to avoid
+ # any further conflicts with the conflicting
+ # distribution
+ env = Environment([])
+ ws = WorkingSet([])
+ dist = best[req.key] = env.best_match(
+ req, ws, installer, replace_conflicting=replace_conflicting
+ )
+ if dist is None:
+ requirers = required_by.get(req, None)
+ raise DistributionNotFound(req, requirers)
+ to_activate.append(dist)
+ if dist not in req:
+ # Oops, the "best" so far conflicts with a dependency
+ dependent_req = required_by[req]
+ raise VersionConflict(dist, req).with_context(dependent_req)
+ return dist
+
+ def find_plugins(self, plugin_env, full_env=None, installer=None, fallback=True):
"""Find all activatable distributions in `plugin_env`
Example usage::