Skip to content

Commit 8d40216

Browse files
committed
Disable calling with unnamed arguments
and enable type checking pre-commit
1 parent 1774296 commit 8d40216

File tree

4 files changed

+31
-45
lines changed

4 files changed

+31
-45
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,10 @@ repos:
4141
hooks:
4242
- id: flake8
4343
additional_dependencies: ['flake8-comprehensions==3.5.0']
44+
45+
# Type checking
46+
- repo: https://github.com/pre-commit/mirrors-mypy
47+
rev: v0.910
48+
hooks:
49+
- id: mypy
50+
files: 'src/.*\.py$'

HISTORY.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ History
88
* The run() function now returns a subprocess.CompletedProcess object,
99
which no longer allows array access operations
1010
(those were deprecated in `#60 <https://github.com/DiamondLightSource/python-procrunner/pull/60>`_)
11+
* Calling the run() function with multiple unnamed arguments is no longer supported
12+
(previously deprecated in `#62 <https://github.com/DiamondLightSource/python-procrunner/pull/62>`_)
1113

1214
2.3.1 (2021-10-25)
1315
------------------

src/procrunner/__init__.py

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import codecs
4-
import functools
54
import io
65
import logging
76
import os
@@ -14,6 +13,7 @@
1413
import warnings
1514
from multiprocessing import Pipe
1615
from threading import Thread
16+
from typing import Callable, Optional
1717

1818
#
1919
# run() - A function to synchronously run an external process, supporting
@@ -300,36 +300,21 @@ def _windows_resolve(command, path=None):
300300
return command
301301

302302

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
319303
def run(
320304
command,
321-
timeout=None,
305+
*,
306+
timeout: Optional[float] = None,
322307
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,
333318
) -> subprocess.CompletedProcess:
334319
"""
335320
Run an external process.
@@ -437,7 +422,7 @@ def run(
437422
if stdin is not None:
438423
notifyee, notifier = Pipe(False)
439424
thread_pipe_pool.append(notifyee)
440-
stdin = _NonBlockingStreamWriter(
425+
_NonBlockingStreamWriter(
441426
p.stdin, data=stdin, debug=debug, notify=notifier.close
442427
)
443428

@@ -531,14 +516,17 @@ def run(
531516
"Process ended after %.1f seconds with exit code %d", runtime, p.returncode
532517
)
533518

534-
stdout = stdout.get_output()
535-
stderr = stderr.get_output()
519+
output_stdout = stdout.get_output()
520+
output_stderr = stderr.get_output()
536521

537-
if timeout_encountered and raise_timeout_exception:
522+
if timeout is not None and timeout_encountered and raise_timeout_exception:
538523
raise subprocess.TimeoutExpired(
539-
cmd=command, timeout=timeout, output=stdout, stderr=stderr
524+
cmd=command, timeout=timeout, output=output_stdout, stderr=output_stderr
540525
)
541526

542527
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,
544532
)

tests/test_procrunner_system.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,3 @@ def test_timeout_behaviour(tmp_path):
120120
assert te.value.stderr == b""
121121
assert te.value.timeout == 0.1
122122
assert te.value.cmd == command
123-
124-
125-
def test_argument_deprecation(tmp_path):
126-
with pytest.warns(DeprecationWarning, match="keyword arguments"):
127-
result = procrunner.run(
128-
[sys.executable, "-V"],
129-
None,
130-
working_directory=tmp_path,
131-
)
132-
assert not result.returncode
133-
assert result.stderr or result.stdout

0 commit comments

Comments
 (0)