|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import codecs |
4 | | -import functools |
5 | 4 | import io |
6 | 5 | import logging |
7 | 6 | import os |
|
14 | 13 | import warnings |
15 | 14 | from multiprocessing import Pipe |
16 | 15 | from threading import Thread |
| 16 | +from typing import Callable, Optional |
17 | 17 |
|
18 | 18 | # |
19 | 19 | # run() - A function to synchronously run an external process, supporting |
@@ -300,36 +300,21 @@ def _windows_resolve(command, path=None): |
300 | 300 | return command |
301 | 301 |
|
302 | 302 |
|
303 | | -def _deprecate_argument_calling(f): |
304 | | - @functools.wraps(f) |
305 | | - def wrapper(*args, **kwargs): |
306 | | - if len(args) > 1: |
307 | | - warnings.warn( |
308 | | - "Calling procrunner.run() with unnamed arguments (apart from " |
309 | | - "the command) is deprecated. Use keyword arguments instead.", |
310 | | - DeprecationWarning, |
311 | | - stacklevel=2, |
312 | | - ) |
313 | | - return f(*args, **kwargs) |
314 | | - |
315 | | - return wrapper |
316 | | - |
317 | | - |
318 | | -@_deprecate_argument_calling |
319 | 303 | def run( |
320 | 304 | command, |
321 | | - timeout=None, |
| 305 | + *, |
| 306 | + timeout: Optional[float] = None, |
322 | 307 | debug=None, |
323 | | - stdin=None, |
324 | | - print_stdout=True, |
325 | | - print_stderr=True, |
326 | | - callback_stdout=None, |
327 | | - callback_stderr=None, |
328 | | - environment=None, |
329 | | - environment_override=None, |
330 | | - win32resolve=True, |
331 | | - working_directory=None, |
332 | | - raise_timeout_exception=False, |
| 308 | + stdin: Optional[bytes] = None, |
| 309 | + print_stdout: bool = True, |
| 310 | + print_stderr: bool = True, |
| 311 | + callback_stdout: Optional[Callable] = None, |
| 312 | + callback_stderr: Optional[Callable] = None, |
| 313 | + environment: Optional[dict[str, str]] = None, |
| 314 | + environment_override: Optional[dict[str, str]] = None, |
| 315 | + win32resolve: bool = True, |
| 316 | + working_directory: Optional[str] = None, |
| 317 | + raise_timeout_exception: bool = False, |
333 | 318 | ) -> subprocess.CompletedProcess: |
334 | 319 | """ |
335 | 320 | Run an external process. |
@@ -437,7 +422,7 @@ def run( |
437 | 422 | if stdin is not None: |
438 | 423 | notifyee, notifier = Pipe(False) |
439 | 424 | thread_pipe_pool.append(notifyee) |
440 | | - stdin = _NonBlockingStreamWriter( |
| 425 | + _NonBlockingStreamWriter( |
441 | 426 | p.stdin, data=stdin, debug=debug, notify=notifier.close |
442 | 427 | ) |
443 | 428 |
|
@@ -531,14 +516,17 @@ def run( |
531 | 516 | "Process ended after %.1f seconds with exit code %d", runtime, p.returncode |
532 | 517 | ) |
533 | 518 |
|
534 | | - stdout = stdout.get_output() |
535 | | - stderr = stderr.get_output() |
| 519 | + output_stdout = stdout.get_output() |
| 520 | + output_stderr = stderr.get_output() |
536 | 521 |
|
537 | | - if timeout_encountered and raise_timeout_exception: |
| 522 | + if timeout is not None and timeout_encountered and raise_timeout_exception: |
538 | 523 | raise subprocess.TimeoutExpired( |
539 | | - cmd=command, timeout=timeout, output=stdout, stderr=stderr |
| 524 | + cmd=command, timeout=timeout, output=output_stdout, stderr=output_stderr |
540 | 525 | ) |
541 | 526 |
|
542 | 527 | return subprocess.CompletedProcess( |
543 | | - args=command, returncode=p.returncode, stdout=stdout, stderr=stderr |
| 528 | + args=command, |
| 529 | + returncode=p.returncode, |
| 530 | + stdout=output_stdout, |
| 531 | + stderr=output_stderr, |
544 | 532 | ) |
0 commit comments