mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Cleanup link handling in req_set.
* Move the caching of find_requirement into find_requirement. * Move the decision to set / not-set link into InstallRequirement.
This commit is contained in:
parent
3bacab35e6
commit
dd3afd20ec
|
@ -420,7 +420,8 @@ class PackageFinder(object):
|
||||||
|
|
||||||
Expects req, an InstallRequirement and upgrade, a boolean
|
Expects req, an InstallRequirement and upgrade, a boolean
|
||||||
Returns an InstallationCandidate or None
|
Returns an InstallationCandidate or None
|
||||||
May raise DistributionNotFound or BestVersionAlreadyInstalled"""
|
May raise DistributionNotFound or BestVersionAlreadyInstalled
|
||||||
|
"""
|
||||||
all_versions = self._find_all_versions(req)
|
all_versions = self._find_all_versions(req)
|
||||||
# Filter out anything which doesn't match our specifier
|
# Filter out anything which doesn't match our specifier
|
||||||
|
|
||||||
|
|
|
@ -205,6 +205,15 @@ class InstallRequirement(object):
|
||||||
return '<%s object: %s editable=%r>' % (
|
return '<%s object: %s editable=%r>' % (
|
||||||
self.__class__.__name__, str(self), self.editable)
|
self.__class__.__name__, str(self), self.editable)
|
||||||
|
|
||||||
|
def populate_link(self, finder, upgrade):
|
||||||
|
"""Ensure that if a link can be found for this, that it is found.
|
||||||
|
|
||||||
|
Note that self.link may still be None - if Upgrade is False and the
|
||||||
|
requirement is already installed.
|
||||||
|
"""
|
||||||
|
if self.link is None:
|
||||||
|
self.link = finder.find_requirement(self, upgrade)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def specifier(self):
|
def specifier(self):
|
||||||
return self.req.specifier
|
return self.req.specifier
|
||||||
|
|
|
@ -66,17 +66,16 @@ class DistAbstraction(object):
|
||||||
|
|
||||||
class IsWheel(DistAbstraction):
|
class IsWheel(DistAbstraction):
|
||||||
|
|
||||||
def __init__(self, req_to_install, location, link):
|
def __init__(self, req_to_install, location):
|
||||||
super(IsWheel, self).__init__(req_to_install)
|
super(IsWheel, self).__init__(req_to_install)
|
||||||
self.location = location
|
self.location = location
|
||||||
self.link = link
|
|
||||||
|
|
||||||
def dist(self, finder):
|
def dist(self, finder):
|
||||||
return list(pkg_resources.find_distributions(self.location))[0]
|
return list(pkg_resources.find_distributions(self.location))[0]
|
||||||
|
|
||||||
def prep_for_dist(self):
|
def prep_for_dist(self):
|
||||||
# FIXME:https://github.com/pypa/pip/issues/1112
|
# FIXME:https://github.com/pypa/pip/issues/1112
|
||||||
self.req_to_install.link = self.link
|
pass
|
||||||
|
|
||||||
|
|
||||||
class IsSDist(DistAbstraction):
|
class IsSDist(DistAbstraction):
|
||||||
|
@ -301,10 +300,9 @@ class RequirementSet(object):
|
||||||
best_installed = True
|
best_installed = True
|
||||||
install = False
|
install = False
|
||||||
except DistributionNotFound as exc:
|
except DistributionNotFound as exc:
|
||||||
not_found = exc
|
# No distribution found, but its already installed
|
||||||
else:
|
# so we don't need to error.
|
||||||
# Avoid the need to call find_requirement again
|
pass
|
||||||
req_to_install.link = link
|
|
||||||
|
|
||||||
if not best_installed:
|
if not best_installed:
|
||||||
# don't uninstall conflict if user install and
|
# don't uninstall conflict if user install and
|
||||||
|
@ -370,6 +368,8 @@ class RequirementSet(object):
|
||||||
# If a checkout exists, it's unwise to keep going. version
|
# If a checkout exists, it's unwise to keep going. version
|
||||||
# inconsistencies are logged later, but do not fail the
|
# inconsistencies are logged later, but do not fail the
|
||||||
# installation.
|
# installation.
|
||||||
|
# FIXME: this won't upgrade when there's an existing
|
||||||
|
# package unpacked in `location`
|
||||||
if os.path.exists(os.path.join(location, 'setup.py')):
|
if os.path.exists(os.path.join(location, 'setup.py')):
|
||||||
raise PreviousBuildDirError(
|
raise PreviousBuildDirError(
|
||||||
"pip can't proceed with requirements '%s' due to a"
|
"pip can't proceed with requirements '%s' due to a"
|
||||||
|
@ -379,20 +379,10 @@ class RequirementSet(object):
|
||||||
"can delete this. Please delete it and try again."
|
"can delete this. Please delete it and try again."
|
||||||
% (req_to_install, location)
|
% (req_to_install, location)
|
||||||
)
|
)
|
||||||
# FIXME: this won't upgrade when there's an existing
|
req_to_install.populate_link(finder, self.upgrade)
|
||||||
# package unpacked in `location`
|
if req_to_install.link:
|
||||||
if req_to_install.link is None:
|
|
||||||
if not_found:
|
|
||||||
raise not_found
|
|
||||||
link = finder.find_requirement(
|
|
||||||
req_to_install,
|
|
||||||
upgrade=self.upgrade,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
link = req_to_install.link
|
|
||||||
if link:
|
|
||||||
try:
|
try:
|
||||||
if link.is_wheel and self.wheel_download_dir:
|
if req_to_install.link.is_wheel and self.wheel_download_dir:
|
||||||
# when doing 'pip wheel`
|
# when doing 'pip wheel`
|
||||||
download_dir = self.wheel_download_dir
|
download_dir = self.wheel_download_dir
|
||||||
do_download = True
|
do_download = True
|
||||||
|
@ -400,7 +390,7 @@ class RequirementSet(object):
|
||||||
download_dir = self.download_dir
|
download_dir = self.download_dir
|
||||||
do_download = self.is_download
|
do_download = self.is_download
|
||||||
unpack_url(
|
unpack_url(
|
||||||
link, location, download_dir,
|
req_to_install.link, location, download_dir,
|
||||||
do_download, session=self.session,
|
do_download, session=self.session,
|
||||||
)
|
)
|
||||||
except requests.HTTPError as exc:
|
except requests.HTTPError as exc:
|
||||||
|
@ -413,15 +403,15 @@ class RequirementSet(object):
|
||||||
raise InstallationError(
|
raise InstallationError(
|
||||||
'Could not install requirement %s because '
|
'Could not install requirement %s because '
|
||||||
'of HTTP error %s for URL %s' %
|
'of HTTP error %s for URL %s' %
|
||||||
(req_to_install, exc, link)
|
(req_to_install, exc, req_to_install.link)
|
||||||
)
|
)
|
||||||
if link.is_wheel:
|
if req_to_install.link.is_wheel:
|
||||||
abstract_dist = IsWheel(req_to_install, location, link)
|
abstract_dist = IsWheel(req_to_install, location)
|
||||||
req_to_install.source_dir = location
|
req_to_install.source_dir = location
|
||||||
abstract_dist.prep_for_dist()
|
abstract_dist.prep_for_dist()
|
||||||
if self.is_download:
|
if self.is_download:
|
||||||
# Make a .zip of the source_dir we already created.
|
# Make a .zip of the source_dir we already created.
|
||||||
if link.scheme in vcs.all_schemes:
|
if req_to_install.link.scheme in vcs.all_schemes:
|
||||||
req_to_install.archive(self.download_dir)
|
req_to_install.archive(self.download_dir)
|
||||||
# req_to_install.req is only avail after unpack for URL
|
# req_to_install.req is only avail after unpack for URL
|
||||||
# pkgs repeat check_if_exists to uninstall-on-upgrade
|
# pkgs repeat check_if_exists to uninstall-on-upgrade
|
||||||
|
|
Loading…
Reference in a new issue