summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2020-08-10 22:24:00 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2020-08-11 22:40:39 +0700
commit39d296eeb8cb8b0f8e09493bc8f1cb6eb5940a46 (patch)
tree740f9be1422f850164305df08f1ee4fba2e01bb0
parent078e0effb72b1078bab3d268aa5b4e374505e18a (diff)
downloadpip-39d296eeb8cb8b0f8e09493bc8f1cb6eb5940a46.tar.gz
Clean up code style and internal interface
Co-Authored-By: Pradyun Gedam <pradyunsg@gmail.com> Co-Authored-By: Chris Hunt <chrahunt@gmail.com>
-rw-r--r--src/pip/_internal/network/download.py7
-rw-r--r--src/pip/_internal/operations/prepare.py12
-rw-r--r--src/pip/_internal/resolution/resolvelib/resolver.py7
3 files changed, 14 insertions, 12 deletions
diff --git a/src/pip/_internal/network/download.py b/src/pip/_internal/network/download.py
index 0eb4fd9ce..5fd277330 100644
--- a/src/pip/_internal/network/download.py
+++ b/src/pip/_internal/network/download.py
@@ -164,11 +164,14 @@ class Downloader(object):
raise
filename = _get_http_response_filename(resp, link)
+ filepath = os.path.join(location, filename)
+
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:
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):
# type: (Iterable[Link], str) -> Iterable[Tuple[str, Tuple[str, str]]]
diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py
index 5fdbd674b..5f2a0c74f 100644
--- a/src/pip/_internal/operations/prepare.py
+++ b/src/pip/_internal/operations/prepare.py
@@ -45,7 +45,7 @@ from pip._internal.utils.unpacking import unpack_file
from pip._internal.vcs import vcs
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 pip._vendor.pkg_resources import Distribution
@@ -484,8 +484,10 @@ class RequirementPreparer(object):
return self._prepare_linked_requirement(req, parallel_builds)
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."""
+ reqs = [req for req in reqs if req.needs_more_preparation]
+
# Let's download to a temporary directory.
tmpdir = TempDirectory(kind="unpack", globally_managed=True).path
links = (req.link for req in reqs)
@@ -505,9 +507,7 @@ class RequirementPreparer(object):
with indent_log():
self._ensure_link_req_src_dir(req, download_dir, parallel_builds)
- if link.url in self._downloaded:
- local_file = File(*self._downloaded[link.url])
- else:
+ if link.url not in self._downloaded:
try:
local_file = unpack_url(
link, req.source_dir, self.downloader, download_dir,
@@ -518,6 +518,8 @@ class RequirementPreparer(object):
'Could not install requirement {} because of HTTP '
'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
# requirement.
diff --git a/src/pip/_internal/resolution/resolvelib/resolver.py b/src/pip/_internal/resolution/resolvelib/resolver.py
index 1cabe236d..031d2f107 100644
--- a/src/pip/_internal/resolution/resolvelib/resolver.py
+++ b/src/pip/_internal/resolution/resolvelib/resolver.py
@@ -160,11 +160,8 @@ class Resolver(BaseResolver):
req_set.add_named_requirement(ireq)
- self.factory.preparer.prepare_linked_requirements_more([
- req for req in req_set.all_requirements
- if req.needs_more_preparation
- ])
-
+ reqs = req_set.all_requirements
+ self.factory.preparer.prepare_linked_requirements_more(reqs)
return req_set
def get_installation_order(self, req_set):