|
24 | 24 |
|
25 | 25 | console_encoding = sys.stdout.encoding |
26 | 26 |
|
| 27 | +PIPE_NOT_SET_ERR = ( |
| 28 | + "File descriptor is None, which should not happen as we set PIPE as default" |
| 29 | +) |
| 30 | + |
27 | 31 |
|
28 | 32 | def console_to_str(s: bytes) -> str: |
29 | 33 | """From pypa/pip project, pip.backwardwardcompat. License MIT.""" |
@@ -226,12 +230,23 @@ def progress_cb(output: t.AnyStr, timestamp: datetime.datetime) -> None: |
226 | 230 | if callback and callable(callback): |
227 | 231 | callback(output="\r", timestamp=datetime.datetime.now()) |
228 | 232 |
|
229 | | - lines = filter(None, (line.strip() for line in proc.stdout.readlines())) |
230 | | - all_output = console_to_str(b"\n".join(lines)) |
| 233 | + if proc.stdout is None: |
| 234 | + raise RuntimeError(PIPE_NOT_SET_ERR) |
| 235 | + |
| 236 | + stdout_lines: list[bytes] = [ |
| 237 | + line.strip() for line in proc.stdout.readlines() if line |
| 238 | + ] |
| 239 | + all_output = [console_to_str(b"\n".join(stdout_lines))] |
| 240 | + |
231 | 241 | if code: |
232 | | - stderr_lines = filter(None, (line.strip() for line in proc.stderr.readlines())) |
233 | | - all_output = console_to_str(b"".join(stderr_lines)) |
| 242 | + if proc.stderr is None: |
| 243 | + raise RuntimeError(PIPE_NOT_SET_ERR) |
| 244 | + stderr_lines: list[bytes] = [ |
| 245 | + line.strip() for line in proc.stderr.readlines() if line |
| 246 | + ] |
| 247 | + all_output = [console_to_str(b"".join(stderr_lines))] |
| 248 | + |
234 | 249 | output = "".join(all_output) |
235 | 250 | if code != 0 and check_returncode: |
236 | | - raise exc.CommandError(output=output, returncode=code, cmd=args) |
| 251 | + raise exc.CommandError(output=output, returncode=code, cmd=str(args)) |
237 | 252 | return output |
0 commit comments