File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ """Invokable subprocess wrapper.
2
+
3
+ Defer running a subprocess, such as by handing to an executor.
4
+
5
+ - :class:`~SubprocessCommand`: Wraps :class:`subprocess.Popen` and
6
+ :func:`subprocess.run` in a :func:`~dataclasses.dataclass`.
7
+
8
+ Before:
9
+
10
+ >>> import subprocess
11
+ >>> subprocess.run(
12
+ ... ['echo', 'hi'],
13
+ ... capture_output=True, universal_newlines=True
14
+ ... ).stdout
15
+ 'hi\\ n'
16
+
17
+ With this:
18
+
19
+ >>> cmd = SubprocessCommand(['echo', 'hi'])
20
+ >>> cmd.args
21
+ ['echo', 'hi']
22
+ >>> cmd.run(capture_output=True, universal_newlines=True).stdout
23
+ 'hi\\ n'
24
+
25
+ Tweak params before invocation:
26
+
27
+ >>> cmd = SubprocessCommand(['echo', 'hi'])
28
+ >>> cmd.args[1] = 'hello'
29
+ >>> cmd.args
30
+ ['echo', 'hello']
31
+ >>> cmd.run(capture_output=True, universal_newlines=True).stdout
32
+ 'hello\\ n'
33
+ """
1
34
import dataclasses
2
35
import subprocess
3
36
import sys
You can’t perform that action at this time.
0 commit comments