2
2
3
3
import itertools
4
4
import sys
5
- from signal import SIGINT , default_int_handler , signal , Signals
5
+ from signal import SIGINT , Signals , default_int_handler , signal
6
6
7
7
from pip ._vendor import six
8
8
from pip ._vendor .progress .bar import Bar , FillingCirclesBar , IncrementalBar
14
14
from pip ._internal .utils .typing import MYPY_CHECK_RUNNING
15
15
16
16
if MYPY_CHECK_RUNNING :
17
- from typing import Any , Dict , List , Iterator
17
+ from typing import Any , Dict , List
18
18
from types import FrameType
19
19
20
20
try :
@@ -79,7 +79,10 @@ def __init__(self, *args, **kwargs):
79
79
"""
80
80
Save the original SIGINT handler for later.
81
81
"""
82
- super (InterruptibleMixin , self ).__init__ (* args , ** kwargs ) # type: ignore
82
+ super (InterruptibleMixin , self ).__init__ ( # type: ignore
83
+ * args ,
84
+ ** kwargs
85
+ )
83
86
84
87
self .original_handler = signal (SIGINT , self .handle_sigint )
85
88
@@ -99,19 +102,18 @@ def finish(self):
99
102
This should happen regardless of whether the progress display finishes
100
103
normally, or gets interrupted.
101
104
"""
102
- super (InterruptibleMixin , self ).finish () # type: ignore
105
+ super (InterruptibleMixin , self ).finish () # type: ignore
103
106
signal (SIGINT , self .original_handler )
104
107
105
- def handle_sigint (self , signum , frame ):
106
- # type: (Signals, FrameType) -> None
108
+ def handle_sigint (self , signum , frame ): # type: ignore
107
109
"""
108
110
Call self.finish() before delegating to the original SIGINT handler.
109
111
110
112
This handler should only be in place while the progress display is
111
113
active.
112
114
"""
113
115
self .finish ()
114
- self .original_handler (signum , frame ) # type: ignore
116
+ self .original_handler (signum , frame )
115
117
116
118
117
119
class SilentBar (Bar ):
@@ -133,30 +135,35 @@ class DownloadProgressMixin(object):
133
135
134
136
def __init__ (self , * args , ** kwargs ):
135
137
# type: (List[Any], Dict[Any, Any]) -> None
136
- super (DownloadProgressMixin , self ).__init__ (* args , ** kwargs ) # type: ignore
137
- self .message = (" " * (get_indentation () + 2 )) + self .message # type: str
138
+ super (DownloadProgressMixin , self ).__init__ ( # type: ignore
139
+ * args ,
140
+ ** kwargs
141
+ )
142
+ self .message = (" " * (
143
+ get_indentation () + 2
144
+ )) + self .message # type: str
138
145
139
146
@property
140
147
def downloaded (self ):
141
148
# type: () -> str
142
- return format_size (self .index ) # type: ignore
149
+ return format_size (self .index ) # type: ignore
143
150
144
151
@property
145
152
def download_speed (self ):
146
153
# type: () -> str
147
154
# Avoid zero division errors...
148
- if self .avg == 0.0 : # type: ignore
155
+ if self .avg == 0.0 : # type: ignore
149
156
return "..."
150
- return format_size (1 / self .avg ) + "/s" # type: ignore
157
+ return format_size (1 / self .avg ) + "/s" # type: ignore
151
158
152
159
@property
153
160
def pretty_eta (self ):
154
161
# type: () -> str
155
- if self .eta : # type: ignore
156
- return "eta {}" .format (self .eta_td ) # type: ignore
162
+ if self .eta : # type: ignore
163
+ return "eta {}" .format (self .eta_td ) # type: ignore
157
164
return ""
158
165
159
- def iter (self , it ): # type: ignore
166
+ def iter (self , it ): # type: ignore
160
167
for x in it :
161
168
yield x
162
169
self .next (len (x ))
@@ -174,15 +181,15 @@ def __init__(self, *args, **kwargs):
174
181
# is set in time. The base progress bar class writes the "hide cursor"
175
182
# code to the terminal in its init, so if we don't set this soon
176
183
# enough, we get a "hide" with no corresponding "show"...
177
- if WINDOWS and self .hide_cursor : # type: ignore
184
+ if WINDOWS and self .hide_cursor : # type: ignore
178
185
self .hide_cursor = False
179
186
180
- super (WindowsMixin , self ).__init__ (* args , ** kwargs ) # type: ignore
187
+ super (WindowsMixin , self ).__init__ (* args , ** kwargs ) # type: ignore
181
188
182
189
# Check if we are running on Windows and we have the colorama module,
183
190
# if we do then wrap our file with it.
184
191
if WINDOWS and colorama :
185
- self .file = colorama .AnsiToWin32 (self .file ) # type: ignore
192
+ self .file = colorama .AnsiToWin32 (self .file ) # type: ignore
186
193
# The progress code expects to be able to call self.file.isatty()
187
194
# but the colorama.AnsiToWin32() object doesn't have that, so we'll
188
195
# add it.
@@ -234,7 +241,7 @@ class DownloadProgressSpinner(WindowsMixin, InterruptibleMixin,
234
241
file = sys .stdout
235
242
suffix = "%(downloaded)s %(download_speed)s"
236
243
237
- def next_phase (self ): # type: ignore
244
+ def next_phase (self ): # type: ignore
238
245
if not hasattr (self , "_phaser" ):
239
246
self ._phaser = itertools .cycle (self .phases )
240
247
return next (self ._phaser )
@@ -264,7 +271,7 @@ def update(self):
264
271
}
265
272
266
273
267
- def DownloadProgressProvider (progress_bar , max = None ): # type: ignore
274
+ def DownloadProgressProvider (progress_bar , max = None ): # type: ignore
268
275
if max is None or max == 0 :
269
276
return BAR_TYPES [progress_bar ][1 ]().iter
270
277
else :
0 commit comments