1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

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

View file

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