Skip to content

Commit aabadf5

Browse files
authored
Merge pull request #210 from henryiii/henryiii/chore/subprocess.run
chore: use subprocess.run instead of old check_*
2 parents 3de7fad + f11cee2 commit aabadf5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/pyproject_hooks/_impl.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import os
33
import sys
44
import tempfile
5+
import subprocess
56
from contextlib import contextmanager
67
from os.path import abspath
78
from os.path import join as pjoin
8-
from subprocess import STDOUT, check_call, check_output
99
from typing import TYPE_CHECKING, Any, Iterator, Mapping, Optional, Sequence
1010
import warnings
1111

@@ -82,13 +82,13 @@ def default_subprocess_runner(
8282
) -> None:
8383
"""The default method of calling the wrapper subprocess.
8484
85-
This uses :func:`subprocess.check_call` under the hood.
85+
This uses :func:`subprocess.run` under the hood.
8686
"""
8787
env = os.environ.copy()
8888
if extra_environ:
8989
env.update(extra_environ)
9090

91-
check_call(cmd, cwd=cwd, env=env)
91+
subprocess.run(cmd, cwd=cwd, env=env, check=True)
9292

9393

9494
def quiet_subprocess_runner(
@@ -98,13 +98,21 @@ def quiet_subprocess_runner(
9898
) -> None:
9999
"""Call the subprocess while suppressing output.
100100
101-
This uses :func:`subprocess.check_output` under the hood.
101+
This uses :func:`subprocess.run` with `stdout=PIPE, stderr=STDOUT` under the hood.
102102
"""
103103
env = os.environ.copy()
104104
if extra_environ:
105105
env.update(extra_environ)
106106

107-
check_output(cmd, cwd=cwd, env=env, stderr=STDOUT)
107+
# Capturing output in case it fails (available on the exception object)
108+
subprocess.run(
109+
cmd,
110+
cwd=cwd,
111+
env=env,
112+
stdout=subprocess.PIPE,
113+
stderr=subprocess.STDOUT,
114+
check=True,
115+
)
108116

109117

110118
def norm_and_check(source_tree: str, requested: str) -> str:

0 commit comments

Comments
 (0)