Skip to content

Commit

Permalink
Refactor in preparation for issue #1139 fix. (#4644)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjerdonek authored and dstufft committed Aug 9, 2017
1 parent 9986c0f commit d5402d3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 55 deletions.
Empty file.
12 changes: 3 additions & 9 deletions pip/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
DirectoryUrlHashUnsupported, HashUnpinned, InstallationError,
PreviousBuildDirError, VcsHashUnsupported
)
from pip.utils import display_path, dist_in_usersite, normalize_path
from pip.utils import display_path, normalize_path
from pip.utils.hashes import MissingHashes
from pip.utils.logging import indent_log
from pip.vcs import vcs
Expand Down Expand Up @@ -164,8 +164,7 @@ def prepare_requirement(self, req, resolver):
# satisfied_by is only evaluated by calling _check_skip_installed,
# so it must be None here.
assert req.satisfied_by is None
if not resolver.ignore_installed:
skip_reason = resolver._check_skip_installed(req)
skip_reason = resolver._check_skip_installed(req)

if req.satisfied_by:
return self._prepare_installed_requirement(
Expand Down Expand Up @@ -302,12 +301,7 @@ def _prepare_linked_requirement(self, req, resolver):
resolver.ignore_installed
)
if should_modify:
# don't uninstall conflict if user install and
# conflict is not user install
if not (resolver.use_user_site and
not dist_in_usersite(req.satisfied_by)):
req.conflicts_with = req.satisfied_by
req.satisfied_by = None
resolver._set_req_to_reinstall(req)
else:
logger.info(
'Requirement already satisfied (use '
Expand Down
83 changes: 37 additions & 46 deletions pip/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ def _is_upgrade_allowed(self, req):
assert self.upgrade_strategy == "only-if-needed"
return req.is_direct

def _set_req_to_reinstall(self, req):
"""
Set a requirement to be installed.
"""
# Don't uninstall the conflict if doing a user install and the
# conflict is not a user install.
if not self.use_user_site or dist_in_usersite(req.satisfied_by):
req.conflicts_with = req.satisfied_by
req.satisfied_by = None

# XXX: Stop passing requirement_set for options
def _check_skip_installed(self, req_to_install):
"""Check if req_to_install should be skipped.
Expand All @@ -133,55 +143,36 @@ def _check_skip_installed(self, req_to_install):
:return: A text reason for why it was skipped, or None.
"""
# Check whether to upgrade/reinstall this req or not.
req_to_install.check_if_exists()
if req_to_install.satisfied_by:
upgrade_allowed = self._is_upgrade_allowed(req_to_install)

# Is the best version is installed.
best_installed = False

if upgrade_allowed:
# For link based requirements we have to pull the
# tree down and inspect to assess the version #, so
# its handled way down.
should_check_possibility_for_upgrade = not (
self.force_reinstall or req_to_install.link
)
if should_check_possibility_for_upgrade:
try:
self.finder.find_requirement(
req_to_install, upgrade_allowed)
except BestVersionAlreadyInstalled:
best_installed = True
except DistributionNotFound:
# No distribution found, so we squash the
# error - it will be raised later when we
# re-try later to do the install.
# Why don't we just raise here?
pass

if not best_installed:
# don't uninstall conflict if user install and
# conflict is not user install
if not (self.use_user_site and not
dist_in_usersite(req_to_install.satisfied_by)):
req_to_install.conflicts_with = \
req_to_install.satisfied_by
req_to_install.satisfied_by = None

# Figure out a nice message to say why we're skipping this.
if best_installed:
skip_reason = 'already up-to-date'
elif self.upgrade_strategy == "only-if-needed":
skip_reason = 'not upgraded as not directly required'
else:
skip_reason = 'already satisfied'
if self.ignore_installed:
return None

return skip_reason
else:
req_to_install.check_if_exists()
if not req_to_install.satisfied_by:
return None

if not self._is_upgrade_allowed(req_to_install):
if self.upgrade_strategy == "only-if-needed":
return 'not upgraded as not directly required'
return 'already satisfied'

# Check for the possibility of an upgrade. For link-based
# requirements we have to pull the tree down and inspect to assess
# the version #, so it's handled way down.
if not (self.force_reinstall or req_to_install.link):
try:
self.finder.find_requirement(req_to_install, upgrade=True)
except BestVersionAlreadyInstalled:
# Then the best version is installed.
return 'already up-to-date'
except DistributionNotFound:
# No distribution found, so we squash the error. It will
# be raised later when we re-try later to do the install.
# Why don't we just raise here?
pass

self._set_req_to_reinstall(req_to_install)
return None

def _resolve_one(self, requirement_set, req_to_install):
"""Prepare a single requirements file.
Expand Down

0 comments on commit d5402d3

Please sign in to comment.