2
2
3
3
import itertools
4
4
import sys
5
- from signal import SIGINT , default_int_handler , signal
5
+ from signal import SIGINT , default_int_handler , signal , Signals
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
17
+ from typing import Any , Dict , List , Iterator
18
+ from types import FrameType
18
19
19
20
try :
20
21
from pip ._vendor import colorama
25
26
26
27
27
28
def _select_progress_class (preferred , fallback ):
29
+ # type: (Bar, Bar) -> Bar
28
30
encoding = getattr (preferred .file , "encoding" , None )
29
31
30
32
# If we don't know what encoding this file is in, then we'll just assume
@@ -73,10 +75,11 @@ class InterruptibleMixin(object):
73
75
"""
74
76
75
77
def __init__ (self , * args , ** kwargs ):
78
+ # type: (List[Any], Dict[Any, Any]) -> None
76
79
"""
77
80
Save the original SIGINT handler for later.
78
81
"""
79
- super (InterruptibleMixin , self ).__init__ (* args , ** kwargs )
82
+ super (InterruptibleMixin , self ).__init__ (* args , ** kwargs ) # type: ignore
80
83
81
84
self .original_handler = signal (SIGINT , self .handle_sigint )
82
85
@@ -89,29 +92,32 @@ def __init__(self, *args, **kwargs):
89
92
self .original_handler = default_int_handler
90
93
91
94
def finish (self ):
95
+ # type: () -> None
92
96
"""
93
97
Restore the original SIGINT handler after finishing.
94
98
95
99
This should happen regardless of whether the progress display finishes
96
100
normally, or gets interrupted.
97
101
"""
98
- super (InterruptibleMixin , self ).finish ()
102
+ super (InterruptibleMixin , self ).finish () # type: ignore
99
103
signal (SIGINT , self .original_handler )
100
104
101
105
def handle_sigint (self , signum , frame ):
106
+ # type: (Signals, FrameType) -> None
102
107
"""
103
108
Call self.finish() before delegating to the original SIGINT handler.
104
109
105
110
This handler should only be in place while the progress display is
106
111
active.
107
112
"""
108
113
self .finish ()
109
- self .original_handler (signum , frame )
114
+ self .original_handler (signum , frame ) # type: ignore
110
115
111
116
112
117
class SilentBar (Bar ):
113
118
114
119
def update (self ):
120
+ # type: () -> None
115
121
pass
116
122
117
123
@@ -126,27 +132,31 @@ class BlueEmojiBar(IncrementalBar):
126
132
class DownloadProgressMixin (object ):
127
133
128
134
def __init__ (self , * args , ** kwargs ):
129
- super (DownloadProgressMixin , self ).__init__ (* args , ** kwargs )
130
- self .message = (" " * (get_indentation () + 2 )) + self .message
135
+ # 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
131
138
132
139
@property
133
140
def downloaded (self ):
134
- return format_size (self .index )
141
+ # type: () -> str
142
+ return format_size (self .index ) # type: ignore
135
143
136
144
@property
137
145
def download_speed (self ):
146
+ # type: () -> str
138
147
# Avoid zero division errors...
139
- if self .avg == 0.0 :
148
+ if self .avg == 0.0 : # type: ignore
140
149
return "..."
141
- return format_size (1 / self .avg ) + "/s"
150
+ return format_size (1 / self .avg ) + "/s" # type: ignore
142
151
143
152
@property
144
153
def pretty_eta (self ):
145
- if self .eta :
146
- return "eta {}" .format (self .eta_td )
154
+ # type: () -> str
155
+ if self .eta : # type: ignore
156
+ return "eta {}" .format (self .eta_td ) # type: ignore
147
157
return ""
148
158
149
- def iter (self , it ):
159
+ def iter (self , it ): # type: ignore
150
160
for x in it :
151
161
yield x
152
162
self .next (len (x ))
@@ -156,22 +166,23 @@ def iter(self, it):
156
166
class WindowsMixin (object ):
157
167
158
168
def __init__ (self , * args , ** kwargs ):
169
+ # type: (List[Any], Dict[Any, Any]) -> None
159
170
# The Windows terminal does not support the hide/show cursor ANSI codes
160
171
# even with colorama. So we'll ensure that hide_cursor is False on
161
172
# Windows.
162
173
# This call needs to go before the super() call, so that hide_cursor
163
174
# is set in time. The base progress bar class writes the "hide cursor"
164
175
# code to the terminal in its init, so if we don't set this soon
165
176
# enough, we get a "hide" with no corresponding "show"...
166
- if WINDOWS and self .hide_cursor :
177
+ if WINDOWS and self .hide_cursor : # type: ignore
167
178
self .hide_cursor = False
168
179
169
- super (WindowsMixin , self ).__init__ (* args , ** kwargs )
180
+ super (WindowsMixin , self ).__init__ (* args , ** kwargs ) # type: ignore
170
181
171
182
# Check if we are running on Windows and we have the colorama module,
172
183
# if we do then wrap our file with it.
173
184
if WINDOWS and colorama :
174
- self .file = colorama .AnsiToWin32 (self .file )
185
+ self .file = colorama .AnsiToWin32 (self .file ) # type: ignore
175
186
# The progress code expects to be able to call self.file.isatty()
176
187
# but the colorama.AnsiToWin32() object doesn't have that, so we'll
177
188
# add it.
@@ -223,12 +234,13 @@ class DownloadProgressSpinner(WindowsMixin, InterruptibleMixin,
223
234
file = sys .stdout
224
235
suffix = "%(downloaded)s %(download_speed)s"
225
236
226
- def next_phase (self ):
237
+ def next_phase (self ): # type: ignore
227
238
if not hasattr (self , "_phaser" ):
228
239
self ._phaser = itertools .cycle (self .phases )
229
240
return next (self ._phaser )
230
241
231
242
def update (self ):
243
+ # type: () -> None
232
244
message = self .message % self
233
245
phase = self .next_phase ()
234
246
suffix = self .suffix % self
@@ -252,7 +264,7 @@ def update(self):
252
264
}
253
265
254
266
255
- def DownloadProgressProvider (progress_bar , max = None ):
267
+ def DownloadProgressProvider (progress_bar , max = None ): # type: ignore
256
268
if max is None or max == 0 :
257
269
return BAR_TYPES [progress_bar ][1 ]().iter
258
270
else :
0 commit comments