Skip to content

chore: use subprocess.run instead of old check_*#210

Merged
takluyver merged 3 commits intopypa:mainfrom
henryiii:henryiii/chore/subprocess.run
Feb 19, 2026
Merged

chore: use subprocess.run instead of old check_*#210
takluyver merged 3 commits intopypa:mainfrom
henryiii:henryiii/chore/subprocess.run

Conversation

@henryiii
Copy link
Copy Markdown
Contributor

I noticed this was using the old subprocess.check_* methods. In modern Python, subprocess.run is recommended.

@henryiii
Copy link
Copy Markdown
Contributor Author

henryiii commented Feb 18, 2026

This removes the ability to check and see why a command failed! My version:

>>> try:
...     subprocess.run(["ruff", "invalid"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
... except subprocess.CalledProcessError as err:
...     print(err.stdout, err.stderr)
...
b'' b"error: unrecognized subcommand 'invalid'\n\nUsage: ruff [OPTIONS] <COMMAND>\n\nFor more information, try '--help'.\n"

Current version:

>>> try:
...     subprocess.run(["ruff", "invalid"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
... except subprocess.CalledProcessError as err:
...     print(err.stdout, err.stderr)
...
None None

If a command fails, users will want to know why it failed!

This was available before (though with stdout and stderr merged, I didn't do that in my example here):

>>> try:
...     subprocess.check_output(["ruff", "invalid"], stderr=subprocess.STDOUT)
... except subprocess.CalledProcessError as err:
...     print(err.stdout, err.stderr)
...
b"error: unrecognized subcommand 'invalid'\n\nUsage: ruff [OPTIONS] <COMMAND>\n\nFor more information, try '--help'.\n" None

We catch and print this all the time in build: https://github.com/search?q=repo%3Apypa%2Fbuild%20CalledProcessError&type=code

@takluyver
Copy link
Copy Markdown
Member

takluyver commented Feb 18, 2026 via email

henryiii and others added 3 commits February 18, 2026 16:37
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Pradyun Gedam <pradyunsg@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
@henryiii henryiii force-pushed the henryiii/chore/subprocess.run branch from 1c5c97d to f11cee2 Compare February 18, 2026 21:40
@takluyver takluyver added this to the 1.3 milestone Feb 19, 2026
@takluyver takluyver merged commit aabadf5 into pypa:main Feb 19, 2026
21 checks passed
@takluyver
Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants