@@ -124,6 +124,15 @@ def _http_get_download(session: PipSession, link: Link) -> Response:
124
124
def _download (
125
125
link : Link , location : str , session : PipSession , progress_bar : str
126
126
) -> Tuple [str , str ]:
127
+ """
128
+ Common download logic across Downloader and BatchDownloader classes
129
+
130
+ :param link: The Link object to be downloaded
131
+ :param location: path to download to
132
+ :param session: PipSession object
133
+ :param progress_bar: creates a `rich` progress bar is set to "on"
134
+ :return: the path to the downloaded file and the content-type
135
+ """
127
136
try :
128
137
resp = _http_get_download (session , link )
129
138
except NetworkConnectionError as e :
@@ -174,6 +183,12 @@ def _sequential_download(
174
183
def _download_parallel (
175
184
self , links : Iterable [Link ], location : str , max_workers : int
176
185
) -> Iterable [Tuple [Link , Tuple [str , str ]]]:
186
+
187
+ """
188
+ Wraps the _sequential_download method in a ThreadPoolExecutor. `rich`
189
+ progress bar doesn't support naive parallelism, hence the progress bar
190
+ is disabled for parallel downloads. For more info see PR #12388
191
+ """
177
192
with ThreadPoolExecutor (max_workers = max_workers ) as pool :
178
193
_download_parallel = partial (
179
194
self ._sequential_download , location = location , progress_bar = "off"
@@ -188,7 +203,6 @@ def __call__(
188
203
links = list (links )
189
204
max_workers = self ._session .parallel_downloads
190
205
if max_workers == 1 or len (links ) == 1 :
191
- # TODO: set minimum number of links to perform parallel download
192
206
for link in links :
193
207
yield self ._sequential_download (link , location , self ._progress_bar )
194
208
else :
0 commit comments