subprocess-check
Provides a wrapper that traces sub-process output, if captured.
Uses
Easier debugging when capturing output in a sub-process call
Before:
import subprocess
result = subprocess.run(
"echo error message >&2 && exit 1", shell=True, capture_output=True, check=True
)
Since the stderr output of the sub-process has been captured, we only see the command and exit code:
$ python t.py
Traceback (most recent call last):
File "t.py", line 3, in <module>
result = subprocess.run(
File "lib/python3.8/subprocess.py", line 512, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'echo error message >&2 && exit 1' returned non-zero exit status 1.
After:
import subprocess
from subprocess_check import output_in_errors
with output_in_errors():
result = subprocess.run(
"echo error message >&2 && exit 1", shell=True, capture_output=True, check=True
)
The stdout/stderr is traced right next to the exit code and command:
$ python t.py
Traceback (most recent call last):
File "t.py", line 6, in <module>
result = subprocess.run(
File "lib/python3.8/site-packages/subprocess_check/_util.py", line 108, in wrap_subprocess_exception
raise CalledProcessErrorWithOutput(exc_value).with_traceback(tb) from None
File "lib/python3.8/subprocess.py", line 512, in run
raise CalledProcessError(retcode, process.args,
subprocess_check._util.CalledProcessErrorWithOutput: Command 'echo error message >&2 && exit 1' returned non-zero exit status 1. Output captured:
stdout: None
stderr:
error message
Alternatives
- Manual error handling/formatting:
- ➕ customizable formatting
- ➕ no dependencies
- ➖ ad-hoc code may not be tested as thoroughly
- Don't capture stderr:
- ➕ no dependencies
- ➖ output to terminal in non-error case may be verbose, if sub-process stderr outputs regardless
- ➖ if the error is re-raised after other operations, which output corresponds to the failed sub-process may not be nearby, or obvious
- Wrap subprocess.run instead of using a context manager
- ➕ no need to pass
capture_output=True, check=True - ➖ IDEs do not understand "transparent function wrappers" well, so autocomplete and type hints are compromised
- ➕ no need to pass
Metadata
Release files for subprocess-check 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| subprocess-check-0.1.0.tar.gz | 5.8 kB | Without provenance | Details for subprocess-check-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| subprocess_check-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for subprocess_check-0.1.0-py3-none-any.whl |
Total release size: 10.4 kB
Release files / subprocess-check-0.1.0.tar.gz
| Download URL | subprocess-check-0.1.0.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6b06e8439b3d642d7f5fcc9ada1ab78065c6557f89ea8f3beb9a36e67dc0eaf
|
|
BLAKE2b-256 checksum How to use checksums |
de2ff931b8fa4164a0e0d9e430438c29f0f9a6d9952068b4c12d09657cfd1de8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.6
|
Release files / subprocess_check-0.1.0-py3-none-any.whl
| Download URL | subprocess_check-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d7878caa4c5d017611f307d6845a43e6c1a1b97b7600e178f781b69974e6429e
|
|
BLAKE2b-256 checksum How to use checksums |
e7a9f064d45a7842bd8bb5089b29fd7ee06b5592fcc695676f960e9d4f155414
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.6
|
Security for subprocess-check 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.