Skip to content

Commit 98e8b90

Browse files
committed
add types for subprocess32
1 parent e806643 commit 98e8b90

File tree

3 files changed

+204
-4
lines changed

3 files changed

+204
-4
lines changed

cwltool/singularity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from .pathmapper import PathMapper, ensure_writable
1313
from .process import (UnsupportedRequirement)
1414
from .utils import docker_windows_path_adjust
15-
if os.name == 'posix' and sys.version_info[0] < 3:
16-
import subprocess32 as subprocess # type: ignore
15+
if sys.version_info[0] < 3:
16+
import subprocess32 as subprocess
1717
else:
1818
import subprocess # type: ignore
1919

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@
5858
'six >= 1.8.0',
5959
],
6060
extras_require={
61-
':python_version<"3" and platform_system=="Linux"': [ 'subprocess32' ],
62-
':python_version<"3"': [ 'pathlib2' ],
61+
':python_version<"3" and platform_system=="Linux"':
62+
['subprocess32 == 3.5.0rc1'],
63+
':python_version<"3"': ['pathlib2'],
6364
'deps': ["galaxy-lib >= 17.09.3"]
6465
},
6566
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4',

typeshed/2and3/subprocess32.pyi

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# Stubs for subprocess32 3.5.0-rc1
2+
# adapted from
3+
# https://github.com/python/typeshed/blob/8e62a79970227aa331f8070e64151002b7dfddea/stdlib/3/subprocess.pyi
4+
# From the subprocess32 README
5+
# > Timeout support backported from Python 3.3 is included.
6+
# > The run() API from Python 3.5 was backported
7+
# > Otherwise features are frozen at the 3.2 level.
8+
9+
import sys
10+
from typing import Sequence, Any, Mapping, Callable, Tuple, IO, Optional, Union, List, Type, Text
11+
from types import TracebackType
12+
13+
# We prefer to annotate inputs to methods (eg subprocess.check_call) with these
14+
# union types. However, outputs (eg check_call return) and class attributes
15+
# (eg TimeoutError.cmd) we prefer to annotate with Any, so the caller does not
16+
# have to use an assertion to confirm which type.
17+
#
18+
# For example:
19+
#
20+
# try:
21+
# x = subprocess.check_output(["ls", "-l"])
22+
# reveal_type(x) # Any, but morally is _TXT
23+
# except TimeoutError as e:
24+
# reveal_type(e.cmd) # Any, but morally is _CMD
25+
_FILE = Union[None, int, IO[Any]]
26+
_TXT = Union[bytes, Text]
27+
_PATH = Union[bytes, Text]
28+
_CMD = Union[_TXT, Sequence[_PATH]]
29+
_ENV = Union[Mapping[bytes, _TXT], Mapping[Text, _TXT]]
30+
31+
class CompletedProcess:
32+
# morally: _CMD
33+
args = ... # type: Any
34+
returncode = ... # type: int
35+
# morally: Optional[_TXT]
36+
stdout = ... # type: Any
37+
stderr = ... # type: Any
38+
def __init__(self, args: _CMD,
39+
returncode: int,
40+
stdout: Optional[_TXT] = ...,
41+
stderr: Optional[_TXT] = ...) -> None: ...
42+
def check_returncode(self) -> None: ...
43+
44+
# Nearly same args as Popen.__init__ except for timeout, input, and check
45+
def run(args: _CMD,
46+
timeout: Optional[float] = ...,
47+
input: Optional[_TXT] = ...,
48+
check: bool = ...,
49+
bufsize: int = ...,
50+
executable: _PATH = ...,
51+
stdin: _FILE = ...,
52+
stdout: _FILE = ...,
53+
stderr: _FILE = ...,
54+
preexec_fn: Callable[[], Any] = ...,
55+
close_fds: bool = ...,
56+
shell: bool = ...,
57+
cwd: Optional[_PATH] = ...,
58+
env: Optional[_ENV] = ...,
59+
universal_newlines: bool = ...,
60+
startupinfo: Any = ...,
61+
creationflags: int = ...,
62+
restore_signals: bool = ...,
63+
start_new_session: bool = ...,
64+
pass_fds: Any = ...) -> CompletedProcess: ...
65+
66+
def call(args: _CMD,
67+
bufsize: int = ...,
68+
executable: _PATH = ...,
69+
stdin: _FILE = ...,
70+
stdout: _FILE = ...,
71+
stderr: _FILE = ...,
72+
preexec_fn: Callable[[], Any] = ...,
73+
close_fds: bool = ...,
74+
shell: bool = ...,
75+
cwd: Optional[_PATH] = ...,
76+
env: Optional[_ENV] = ...,
77+
universal_newlines: bool = ...,
78+
startupinfo: Any = ...,
79+
creationflags: int = ...,
80+
restore_signals: bool = ...,
81+
start_new_session: bool = ...,
82+
pass_fds: Any = ...,
83+
timeout: float = ...) -> int: ...
84+
85+
def check_call(args: _CMD,
86+
bufsize: int = ...,
87+
executable: _PATH = ...,
88+
stdin: _FILE = ...,
89+
stdout: _FILE = ...,
90+
stderr: _FILE = ...,
91+
preexec_fn: Callable[[], Any] = ...,
92+
close_fds: bool = ...,
93+
shell: bool = ...,
94+
cwd: Optional[_PATH] = ...,
95+
env: Optional[_ENV] = ...,
96+
universal_newlines: bool = ...,
97+
startupinfo: Any = ...,
98+
creationflags: int = ...,
99+
restore_signals: bool = ...,
100+
start_new_session: bool = ...,
101+
pass_fds: Any = ...,
102+
timeout: float = ...) -> int: ...
103+
104+
def check_output(args: _CMD,
105+
bufsize: int = ...,
106+
executable: _PATH = ...,
107+
stdin: _FILE = ...,
108+
stderr: _FILE = ...,
109+
preexec_fn: Callable[[], Any] = ...,
110+
close_fds: bool = ...,
111+
shell: bool = ...,
112+
cwd: Optional[_PATH] = ...,
113+
env: Optional[_ENV] = ...,
114+
universal_newlines: bool = ...,
115+
startupinfo: Any = ...,
116+
creationflags: int = ...,
117+
restore_signals: bool = ...,
118+
start_new_session: bool = ...,
119+
pass_fds: Any = ...,
120+
timeout: float = ...,
121+
) -> Any: ... # morally: -> _TXT
122+
123+
124+
PIPE = ... # type: int
125+
STDOUT = ... # type: int
126+
class SubprocessError(Exception): ...
127+
class TimeoutExpired(SubprocessError):
128+
# morally: _CMD
129+
cmd = ... # type: Any
130+
timeout = ... # type: float
131+
# morally: Optional[_TXT]
132+
output = ... # type: Any
133+
stdout = ... # type: Any
134+
stderr = ... # type: Any
135+
136+
137+
class CalledProcessError(Exception):
138+
returncode = 0
139+
# morally: _CMD
140+
cmd = ... # type: Any
141+
# morally: Optional[_TXT]
142+
output = ... # type: Any
143+
144+
stdout = ... # type: Any
145+
stderr = ... # type: Any
146+
147+
def __init__(self,
148+
returncode: int,
149+
cmd: _CMD,
150+
output: Optional[_TXT] = ...,
151+
stderr: Optional[_TXT] = ...) -> None: ...
152+
153+
class Popen:
154+
args = ... # type: _CMD
155+
stdin = ... # type: IO[Any]
156+
stdout = ... # type: IO[Any]
157+
stderr = ... # type: IO[Any]
158+
pid = 0
159+
returncode = 0
160+
161+
162+
def __init__(self,
163+
args: _CMD,
164+
bufsize: int = ...,
165+
executable: Optional[_PATH] = ...,
166+
stdin: Optional[_FILE] = ...,
167+
stdout: Optional[_FILE] = ...,
168+
stderr: Optional[_FILE] = ...,
169+
preexec_fn: Optional[Callable[[], Any]] = ...,
170+
close_fds: bool = ...,
171+
shell: bool = ...,
172+
cwd: Optional[_PATH] = ...,
173+
env: Optional[_ENV] = ...,
174+
universal_newlines: bool = ...,
175+
startupinfo: Optional[Any] = ...,
176+
creationflags: int = ...,
177+
restore_signals: bool = ...,
178+
start_new_session: bool = ...,
179+
pass_fds: Any = ...) -> None: ...
180+
181+
def poll(self) -> int: ...
182+
def wait(self, timeout: Optional[float] = ...) -> int: ...
183+
# Return str/bytes
184+
def communicate(self,
185+
input: Optional[_TXT] = ...,
186+
timeout: Optional[float] = ...,
187+
# morally: -> Tuple[Optional[_TXT], Optional[_TXT]]
188+
) -> Tuple[Any, Any]: ...
189+
def send_signal(self, signal: int) -> None: ...
190+
def terminate(self) -> None: ...
191+
def kill(self) -> None: ...
192+
def __enter__(self) -> 'Popen': ...
193+
def __exit__(self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> bool: ...
194+
195+
# The result really is always a str.
196+
def getstatusoutput(cmd: _TXT) -> Tuple[int, str]: ...
197+
def getoutput(cmd: _TXT) -> str: ...
198+
199+
def list2cmdline(seq: Sequence[str]) -> str: ... # undocumented

0 commit comments

Comments
 (0)