Move dependency data into resolver

This commit is contained in:
Pradyun Gedam 2017-12-16 19:24:57 +05:30
parent 2e5715e3bb
commit 8803a3186b
No known key found for this signature in database
GPG Key ID: DA17C4B29CB32E4B
2 changed files with 22 additions and 17 deletions

View File

@ -1,7 +1,7 @@
from __future__ import absolute_import
import logging
from collections import OrderedDict, defaultdict
from collections import OrderedDict
from pip._internal.exceptions import InstallationError
from pip._internal.utils.logging import indent_log
@ -32,9 +32,6 @@ class RequirementSet(object):
self.use_user_site = use_user_site
self.target_dir = target_dir # set from --target option
self.pycompile = pycompile
# Maps from install_req -> dependencies_of_install_req
# XXX: Move into resolver
self._dependencies = defaultdict(list)
def __str__(self):
reqs = [req for req in self.requirements.values()
@ -70,7 +67,7 @@ class RequirementSet(object):
logger.warning("Ignoring %s: markers '%s' don't match your "
"environment", install_req.name,
install_req.markers)
return []
return [], None
# This check has to come after we filter requirements with the
# environment markers.
@ -90,7 +87,7 @@ class RequirementSet(object):
if not name:
# url or path requirement w/o an egg fragment
self.unnamed_requirements.append(install_req)
return [install_req]
return [install_req], None
else:
try:
existing_req = self.get_requirement(name)
@ -136,10 +133,10 @@ class RequirementSet(object):
# Canonicalise to the already-added object for the backref
# check below.
install_req = existing_req
if parent_req_name:
parent_req = self.get_requirement(parent_req_name)
self._dependencies[parent_req].append(install_req)
return result
# We return install_req here to allow for the caller to add it to
# the dependency information for the parent package.
return result, install_req
def has_requirement(self, project_name):
name = project_name.lower()

View File

@ -11,12 +11,14 @@ for sub-dependencies
"""
import logging
from collections import defaultdict
from itertools import chain
from pip._internal.exceptions import (
BestVersionAlreadyInstalled, DistributionNotFound, HashError, HashErrors,
UnsupportedPythonVersion,
)
from pip._internal.req.req_install import InstallRequirement
from pip._internal.utils.logging import indent_log
from pip._internal.utils.misc import dist_in_usersite, ensure_dir
@ -56,6 +58,8 @@ class Resolver(object):
self.ignore_requires_python = ignore_requires_python
self.use_user_site = use_user_site
self._discovered_dependencies = defaultdict(list)
def resolve(self, requirement_set):
"""Resolve what operations need to be done
@ -270,13 +274,17 @@ class Resolver(object):
isolated=self.isolated,
wheel_cache=self.wheel_cache,
)
more_reqs.extend(
requirement_set.add_requirement(
sub_install_req,
parent_req_name=req_to_install.name,
extras_requested=extras_requested,
)
parent_req_name = req_to_install.name
to_scan_again, add_to_parent = requirement_set.add_requirement(
sub_install_req,
parent_req_name=parent_req_name,
extras_requested=extras_requested,
)
if parent_req_name and add_to_parent:
self._discovered_dependencies[parent_req_name].append(
add_to_parent
)
more_reqs.extend(to_scan_again)
with indent_log():
# We add req_to_install before its dependencies, so that we
@ -335,7 +343,7 @@ class Resolver(object):
if req.constraint:
return
ordered_reqs.add(req)
for dep in req_set._dependencies[req]:
for dep in self._discovered_dependencies[req.name]:
schedule(dep)
order.append(req)