16
16
import threading
17
17
from textwrap import dedent
18
18
19
- from git .compat import (
20
- defenc ,
21
- force_bytes ,
22
- safe_decode ,
23
- is_posix ,
24
- is_win ,
19
+ from git .compat import defenc , force_bytes , safe_decode
20
+ from git .exc import (
21
+ CommandError ,
22
+ GitCommandError ,
23
+ GitCommandNotFound ,
24
+ UnsafeOptionError ,
25
+ UnsafeProtocolError ,
25
26
)
26
- from git .exc import CommandError
27
- from git .util import is_cygwin_git , cygpath , expand_path , remove_password_if_present , patch_env
28
-
29
- from .exc import GitCommandError , GitCommandNotFound , UnsafeOptionError , UnsafeProtocolError
30
- from .util import (
27
+ from git .util import (
31
28
LazyMixin ,
29
+ cygpath ,
30
+ expand_path ,
31
+ is_cygwin_git ,
32
+ patch_env ,
33
+ remove_password_if_present ,
32
34
stream_copy ,
33
35
)
34
36
@@ -179,14 +181,13 @@ def pump_stream(
179
181
t .start ()
180
182
threads .append (t )
181
183
182
- ## FIXME: Why Join?? Will block if `stdin` needs feeding...
183
- #
184
+ # FIXME: Why join? Will block if stdin needs feeding...
184
185
for t in threads :
185
186
t .join (timeout = kill_after_timeout )
186
187
if t .is_alive ():
187
188
if isinstance (process , Git .AutoInterrupt ):
188
189
process ._terminate ()
189
- else : # Don't want to deal with the other case
190
+ else : # Don't want to deal with the other case.
190
191
raise RuntimeError (
191
192
"Thread join() timed out in cmd.handle_process_output()."
192
193
f" kill_after_timeout={ kill_after_timeout } seconds"
@@ -196,11 +197,11 @@ def pump_stream(
196
197
"error: process killed because it timed out." f" kill_after_timeout={ kill_after_timeout } seconds"
197
198
)
198
199
if not decode_streams and isinstance (p_stderr , BinaryIO ):
199
- # Assume stderr_handler needs binary input
200
+ # Assume stderr_handler needs binary input.
200
201
error_str = cast (str , error_str )
201
202
error_str = error_str .encode ()
202
203
# We ignore typing on the next line because mypy does not like
203
- # the way we inferred that stderr takes str or bytes
204
+ # the way we inferred that stderr takes str or bytes.
204
205
stderr_handler (error_str ) # type: ignore
205
206
206
207
if finalizer :
@@ -227,14 +228,12 @@ def dict_to_slots_and__excluded_are_none(self: object, d: Mapping[str, Any], exc
227
228
## -- End Utilities -- @}
228
229
229
230
230
- # value of Windows process creation flag taken from MSDN
231
- CREATE_NO_WINDOW = 0x08000000
232
-
233
- ## CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards,
234
- # see https://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal
235
- PROC_CREATIONFLAGS = (
236
- CREATE_NO_WINDOW | subprocess .CREATE_NEW_PROCESS_GROUP if is_win else 0 # type: ignore[attr-defined]
237
- ) # mypy error if not Windows.
231
+ if os .name == "nt" :
232
+ # CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards. See:
233
+ # https://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal
234
+ PROC_CREATIONFLAGS = subprocess .CREATE_NO_WINDOW | subprocess .CREATE_NEW_PROCESS_GROUP
235
+ else :
236
+ PROC_CREATIONFLAGS = 0
238
237
239
238
240
239
class Git (LazyMixin ):
@@ -550,7 +549,7 @@ def _terminate(self) -> None:
550
549
# For some reason, providing None for stdout/stderr still prints something. This is why
551
550
# we simply use the shell and redirect to nul. Slower than CreateProcess. The question
552
551
# is whether we really want to see all these messages. It's annoying no matter what.
553
- if is_win :
552
+ if os . name == "nt" :
554
553
call (
555
554
("TASKKILL /F /T /PID %s 2>nul 1>nul" % str (proc .pid )),
556
555
shell = True ,
@@ -966,7 +965,7 @@ def execute(
966
965
if inline_env is not None :
967
966
env .update (inline_env )
968
967
969
- if is_win :
968
+ if os . name == "nt" :
970
969
cmd_not_found_exception = OSError
971
970
if kill_after_timeout is not None :
972
971
raise GitCommandError (
@@ -998,11 +997,11 @@ def execute(
998
997
env = env ,
999
998
cwd = cwd ,
1000
999
bufsize = - 1 ,
1001
- stdin = istream or DEVNULL ,
1000
+ stdin = ( istream or DEVNULL ) ,
1002
1001
stderr = PIPE ,
1003
1002
stdout = stdout_sink ,
1004
1003
shell = shell ,
1005
- close_fds = is_posix , # Unsupported on Windows.
1004
+ close_fds = ( os . name == "posix" ) , # Unsupported on Windows.
1006
1005
universal_newlines = universal_newlines ,
1007
1006
creationflags = PROC_CREATIONFLAGS ,
1008
1007
** subprocess_kwargs ,
@@ -1072,7 +1071,7 @@ def kill_process(pid: int) -> None:
1072
1071
)
1073
1072
if not universal_newlines :
1074
1073
stderr_value = stderr_value .encode (defenc )
1075
- # strip trailing "\n"
1074
+ # Strip trailing "\n".
1076
1075
if stdout_value .endswith (newline ) and strip_newline_in_stdout : # type: ignore
1077
1076
stdout_value = stdout_value [:- 1 ]
1078
1077
if stderr_value .endswith (newline ): # type: ignore
@@ -1146,11 +1145,11 @@ def update_environment(self, **kwargs: Any) -> Dict[str, Union[str, None]]:
1146
1145
"""
1147
1146
old_env = {}
1148
1147
for key , value in kwargs .items ():
1149
- # set value if it is None
1148
+ # Set value if it is None.
1150
1149
if value is not None :
1151
1150
old_env [key ] = self ._environment .get (key )
1152
1151
self ._environment [key ] = value
1153
- # remove key from environment if its value is None
1152
+ # Remove key from environment if its value is None.
1154
1153
elif key in self ._environment :
1155
1154
old_env [key ] = self ._environment [key ]
1156
1155
del self ._environment [key ]
@@ -1329,7 +1328,8 @@ def _parse_object_header(self, header_line: str) -> Tuple[str, str, int]:
1329
1328
:return: (hex_sha, type_string, size_as_int)
1330
1329
1331
1330
:raise ValueError: If the header contains indication for an error due to
1332
- incorrect input sha"""
1331
+ incorrect input sha
1332
+ """
1333
1333
tokens = header_line .split ()
1334
1334
if len (tokens ) != 3 :
1335
1335
if not tokens :
0 commit comments