MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / cmd_output_p

Function cmd_output_p

pre_commit/util.py:162–200  ·  view source on GitHub ↗
(
            *cmd: str,
            check: bool = True,
            **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

160 self.close_r()
161
162 def cmd_output_p(
163 *cmd: str,
164 check: bool = True,
165 **kwargs: Any,
166 ) -> tuple[int, bytes, bytes | None]:
167 assert check is False
168 assert kwargs['stderr'] == subprocess.STDOUT, kwargs['stderr']
169 _setdefault_kwargs(kwargs)
170
171 try:
172 cmd = parse_shebang.normalize_cmd(cmd)
173 except parse_shebang.ExecutableNotFoundError as e:
174 return e.to_output()
175
176 with open(os.devnull) as devnull, Pty() as pty:
177 assert pty.r is not None
178 kwargs.update({'stdin': devnull, 'stdout': pty.w, 'stderr': pty.w})
179 try:
180 proc = subprocess.Popen(cmd, **kwargs)
181 except OSError as e:
182 return _oserror_to_output(e)
183
184 pty.close_w()
185
186 buf = b''
187 while True:
188 try:
189 bts = os.read(pty.r, 4096)
190 except OSError as e:
191 if e.errno == errno.EIO:
192 bts = b''
193 else:
194 raise
195 else:
196 buf += bts
197 if not bts:
198 break
199
200 return proc.wait(), buf, None
201else: # pragma: no cover
202 cmd_output_p = cmd_output_b
203

Callers

nothing calls this directly

Calls 6

_setdefault_kwargsFunction · 0.85
PtyClass · 0.85
_oserror_to_outputFunction · 0.85
to_outputMethod · 0.80
updateMethod · 0.80
close_wMethod · 0.80

Tested by

no test coverage detected