mirror of https://github.com/pypa/pip
Clean up code style and internal interface
Co-Authored-By: Pradyun Gedam <pradyunsg@gmail.com> Co-Authored-By: Chris Hunt <chrahunt@gmail.com>
This commit is contained in:
parent
078e0effb7
commit
39d296eeb8
|
@ -164,11 +164,14 @@ class Downloader(object):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
filename = _get_http_response_filename(resp, link)
|
filename = _get_http_response_filename(resp, link)
|
||||||
|
filepath = os.path.join(location, filename)
|
||||||
|
|
||||||
chunks = _prepare_download(resp, link, self._progress_bar)
|
chunks = _prepare_download(resp, link, self._progress_bar)
|
||||||
with open(os.path.join(location, filename), 'wb') as content_file:
|
with open(filepath, 'wb') as content_file:
|
||||||
for chunk in chunks:
|
for chunk in chunks:
|
||||||
content_file.write(chunk)
|
content_file.write(chunk)
|
||||||
return content_file.name, resp.headers.get('Content-Type', '')
|
content_type = resp.headers.get('Content-Type', '')
|
||||||
|
return filepath, content_type
|
||||||
|
|
||||||
def download_many(self, links, location):
|
def download_many(self, links, location):
|
||||||
# type: (Iterable[Link], str) -> Iterable[Tuple[str, Tuple[str, str]]]
|
# type: (Iterable[Link], str) -> Iterable[Tuple[str, Tuple[str, str]]]
|
||||||
|
|
|
@ -45,7 +45,7 @@ from pip._internal.utils.unpacking import unpack_file
|
||||||
from pip._internal.vcs import vcs
|
from pip._internal.vcs import vcs
|
||||||
|
|
||||||
if MYPY_CHECK_RUNNING:
|
if MYPY_CHECK_RUNNING:
|
||||||
from typing import Callable, Dict, List, Optional, Tuple
|
from typing import Callable, Dict, Iterable, List, Optional, Tuple
|
||||||
|
|
||||||
from mypy_extensions import TypedDict
|
from mypy_extensions import TypedDict
|
||||||
from pip._vendor.pkg_resources import Distribution
|
from pip._vendor.pkg_resources import Distribution
|
||||||
|
@ -484,8 +484,10 @@ class RequirementPreparer(object):
|
||||||
return self._prepare_linked_requirement(req, parallel_builds)
|
return self._prepare_linked_requirement(req, parallel_builds)
|
||||||
|
|
||||||
def prepare_linked_requirements_more(self, reqs, parallel_builds=False):
|
def prepare_linked_requirements_more(self, reqs, parallel_builds=False):
|
||||||
# type: (List[InstallRequirement], bool) -> None
|
# type: (Iterable[InstallRequirement], bool) -> None
|
||||||
"""Prepare a linked requirement more, if needed."""
|
"""Prepare a linked requirement more, if needed."""
|
||||||
|
reqs = [req for req in reqs if req.needs_more_preparation]
|
||||||
|
|
||||||
# Let's download to a temporary directory.
|
# Let's download to a temporary directory.
|
||||||
tmpdir = TempDirectory(kind="unpack", globally_managed=True).path
|
tmpdir = TempDirectory(kind="unpack", globally_managed=True).path
|
||||||
links = (req.link for req in reqs)
|
links = (req.link for req in reqs)
|
||||||
|
@ -505,9 +507,7 @@ class RequirementPreparer(object):
|
||||||
|
|
||||||
with indent_log():
|
with indent_log():
|
||||||
self._ensure_link_req_src_dir(req, download_dir, parallel_builds)
|
self._ensure_link_req_src_dir(req, download_dir, parallel_builds)
|
||||||
if link.url in self._downloaded:
|
if link.url not in self._downloaded:
|
||||||
local_file = File(*self._downloaded[link.url])
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
local_file = unpack_url(
|
local_file = unpack_url(
|
||||||
link, req.source_dir, self.downloader, download_dir,
|
link, req.source_dir, self.downloader, download_dir,
|
||||||
|
@ -518,6 +518,8 @@ class RequirementPreparer(object):
|
||||||
'Could not install requirement {} because of HTTP '
|
'Could not install requirement {} because of HTTP '
|
||||||
'error {} for URL {}'.format(req, exc, link)
|
'error {} for URL {}'.format(req, exc, link)
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
local_file = File(*self._downloaded[link.url])
|
||||||
|
|
||||||
# For use in later processing, preserve the file path on the
|
# For use in later processing, preserve the file path on the
|
||||||
# requirement.
|
# requirement.
|
||||||
|
|
|
@ -160,11 +160,8 @@ class Resolver(BaseResolver):
|
||||||
|
|
||||||
req_set.add_named_requirement(ireq)
|
req_set.add_named_requirement(ireq)
|
||||||
|
|
||||||
self.factory.preparer.prepare_linked_requirements_more([
|
reqs = req_set.all_requirements
|
||||||
req for req in req_set.all_requirements
|
self.factory.preparer.prepare_linked_requirements_more(reqs)
|
||||||
if req.needs_more_preparation
|
|
||||||
])
|
|
||||||
|
|
||||||
return req_set
|
return req_set
|
||||||
|
|
||||||
def get_installation_order(self, req_set):
|
def get_installation_order(self, req_set):
|
||||||
|
|
Loading…
Reference in New Issue