Skip to main content

pretty_subprocess

Wrapper around subprocess.run that shows the joined command when an exception is raised.

Usage

import pretty_subprocess

result = pretty_subprocess.run(['ls', '-l', '/no/such dir'], check=True)

run(*args, **kwargs) -> subprocess.CompletedProcess

A drop-in replacement for subprocess.run. All positional and keyword arguments are passed through unchanged, and the CompletedProcess is returned as usual.

If subprocess.run raises an exception (e.g. CalledProcessError with check=True, FileNotFoundError for a missing executable, TimeoutExpired), a note with the command is attached to the exception via add_note and the original exception is re-raised. The command is shown as:

  • the string itself, if the command was passed as a single string, bytes or path, or
  • a shell-quoted string built with shlex.join, if it was passed as a sequence. Items that are bytes or path-like (e.g. pathlib.Path) are converted to strings.

The command may be passed positionally or as the args= keyword.

The note appears in the traceback, so the failing command can be copied and run directly in a shell:

Traceback (most recent call last):
  ...
subprocess.CalledProcessError: Command '['ls', '-l', '/no/such dir']' returned non-zero exit status 2.
Command: ls -l '/no/such dir'

Requires Python 3.12 or later.

Metadata

Release files for pretty-subprocess 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pretty-subprocess 1.0
File Size Uploaded Provenance
pretty_subprocess-1.0.tar.gz 3.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pretty-subprocess 1.0
File Interpreter ABI Platform
pretty_subprocess-1.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.4 kB

Release files / pretty_subprocess-1.0.tar.gz

Download URL pretty_subprocess-1.0.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0addf7f589a410d8263e7039ba267f0dfc1dbc8d632b5b7e1227989834ef7f65
BLAKE2b-256 checksum
How to use checksums
263a98736af243e14d81262963a4e1b4eba0b9676c68c22da5d46812414b3917
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / pretty_subprocess-1.0-py3-none-any.whl

Download URL pretty_subprocess-1.0-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d8693803516f21deb33414abe99dfb6d182596dd59e2a0a16c37f36372d12d1
BLAKE2b-256 checksum
How to use checksums
932579aa22b5a745e88d7d49c67a85e1bd963a8e57a6813b684ff970c7a9c93e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for pretty-subprocess 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.

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page