Skip to content

Commit 2b81c43

Browse files
authored
Deprecate the debug= parameter (#63)
2 parents abb67e6 + 469afdb commit 2b81c43

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

HISTORY.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ History
88
list as the first argument) is now deprecated. As a number of arguments
99
will be removed in a future version the use of unnamed arguments will
1010
cause future confusion. `Use explicit keyword arguments instead (#62). <https://github.com/DiamondLightSource/python-procrunner/pull/62>`_
11+
* The run() function debug argument has been deprecated. This is only
12+
only used to debug the NonBlockingStream* classes. Those are due to be
13+
replaced in a future release, so the argument will no longer serve a
14+
purpose. Debugging information remains available via standard logging
15+
mechanisms.
1116

1217
2.1.0 (2020-09-05)
1318
------------------

procrunner/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ def __init__(self, stream, data, debug=False, notify=None):
210210
self._buffer = data
211211
self._buffer_len = len(data)
212212
self._buffer_pos = 0
213-
self._debug = debug
214213
self._max_block_len = 4096
215214
self._stream = stream
216215
self._terminated = False
@@ -433,7 +432,7 @@ def wrapper(*args, **kwargs):
433432
def run(
434433
command,
435434
timeout=None,
436-
debug=False,
435+
debug=None,
437436
stdin=None,
438437
print_stdout=True,
439438
print_stderr=True,
@@ -453,7 +452,7 @@ def run(
453452
454453
:param array command: Command line to be run, specified as array.
455454
:param timeout: Terminate program execution after this many seconds.
456-
:param boolean debug: Enable further debug messages.
455+
:param boolean debug: Enable further debug messages. (deprecated)
457456
:param stdin: Optional bytestring that is passed to command stdin.
458457
:param boolean print_stdout: Pass stdout through to sys.stdout.
459458
:param boolean print_stderr: Pass stderr through to sys.stderr.
@@ -487,6 +486,10 @@ def run(
487486
else:
488487
assert sys.platform != "win32", "stdin argument not supported on Windows"
489488
stdin_pipe = subprocess.PIPE
489+
if debug is not None:
490+
warnings.warn(
491+
"Use of the debug parameter is deprecated", DeprecationWarning, stacklevel=3
492+
)
490493

491494
start_time = timeit.default_timer()
492495
if timeout is not None:
@@ -495,7 +498,7 @@ def run(
495498
warnings.warn(
496499
"Using procrunner with timeout and without raise_timeout_exception set is deprecated",
497500
DeprecationWarning,
498-
stacklevel=2,
501+
stacklevel=3,
499502
)
500503

501504
if environment is not None:

tests/test_procrunner.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_run_command_aborts_after_timeout(
4242
task = ["___"]
4343

4444
with pytest.raises(RuntimeError):
45-
procrunner.run(task, timeout=-1, debug=False, raise_timeout_exception=True)
45+
procrunner.run(task, timeout=-1, raise_timeout_exception=True)
4646

4747
assert mock_subprocess.Popen.called
4848
assert mock_process.terminate.called
@@ -84,7 +84,6 @@ def streamreader_processing(*args, **kwargs):
8484
actual = procrunner.run(
8585
command,
8686
timeout=0.5,
87-
debug=False,
8887
callback_stdout=mock.sentinel.callback_stdout,
8988
callback_stderr=mock.sentinel.callback_stderr,
9089
working_directory=mock.sentinel.cwd,
@@ -99,14 +98,14 @@ def streamreader_processing(*args, **kwargs):
9998
mock.call(
10099
stream_stdout,
101100
output=mock.ANY,
102-
debug=mock.ANY,
101+
debug=None,
103102
notify=mock.ANY,
104103
callback=mock.sentinel.callback_stdout,
105104
),
106105
mock.call(
107106
stream_stderr,
108107
output=mock.ANY,
109-
debug=mock.ANY,
108+
debug=None,
110109
notify=mock.ANY,
111110
callback=mock.sentinel.callback_stderr,
112111
),
@@ -128,12 +127,21 @@ def streamreader_processing(*args, **kwargs):
128127
def test_default_process_environment_is_parent_environment(mock_subprocess):
129128
mock_subprocess.Popen.side_effect = NotImplementedError() # cut calls short
130129
with pytest.raises(NotImplementedError):
131-
procrunner.run(
132-
[mock.Mock()], timeout=-1, debug=False, raise_timeout_exception=True
133-
)
130+
procrunner.run([mock.Mock()], timeout=-1, raise_timeout_exception=True)
134131
assert mock_subprocess.Popen.call_args[1]["env"] == os.environ
135132

136133

134+
@mock.patch("procrunner.subprocess")
135+
def test_using_debug_parameter_raises_warning(mock_subprocess):
136+
mock_subprocess.Popen.side_effect = NotImplementedError() # cut calls short
137+
with pytest.warns(DeprecationWarning, match="debug"):
138+
with pytest.raises(NotImplementedError):
139+
procrunner.run([mock.Mock()], debug=True)
140+
with pytest.warns(DeprecationWarning, match="debug"):
141+
with pytest.raises(NotImplementedError):
142+
procrunner.run([mock.Mock()], debug=False)
143+
144+
137145
@mock.patch("procrunner.subprocess")
138146
def test_pass_custom_environment_to_process(mock_subprocess):
139147
mock_subprocess.Popen.side_effect = NotImplementedError() # cut calls short
@@ -143,7 +151,6 @@ def test_pass_custom_environment_to_process(mock_subprocess):
143151
procrunner.run(
144152
[mock.Mock()],
145153
timeout=-1,
146-
debug=False,
147154
environment=copy.copy(mock_env),
148155
raise_timeout_exception=True,
149156
)
@@ -160,7 +167,6 @@ def test_pass_custom_environment_to_process_and_add_another_value(mock_subproces
160167
procrunner.run(
161168
[mock.Mock()],
162169
timeout=-1,
163-
debug=False,
164170
environment=copy.copy(mock_env1),
165171
environment_override=copy.copy(mock_env2),
166172
raise_timeout_exception=True,
@@ -178,7 +184,6 @@ def test_use_default_process_environment_and_add_another_value(mock_subprocess):
178184
procrunner.run(
179185
[mock.Mock()],
180186
timeout=-1,
181-
debug=False,
182187
environment_override=copy.copy(mock_env2),
183188
raise_timeout_exception=True,
184189
)
@@ -207,7 +212,6 @@ def test_use_default_process_environment_and_override_a_value(mock_subprocess):
207212
procrunner.run(
208213
[mock.Mock()],
209214
timeout=-1,
210-
debug=False,
211215
environment_override={
212216
random_environment_variable: "X" + random_environment_value
213217
},

0 commit comments

Comments
 (0)