Object-oriented commandline
Install
$ pip install spall
Development
$ pip install spall
Usage
Import Subprocess from spall
>>> from spall import Subprocess
Instantiate individual executables
>>> cat = Subprocess("cat")
>>> echo = Subprocess("echo")
>>> fails = Subprocess("false")
Default is to return returncode and print stdout and stderr to console
>>> returncode = echo.call("Hello, world")
Hello, world
>>> returncode
0
Capture stdout with the capture keyword argument
>>> echo.call("Hello, world", capture=True)
0
Stdout is consumed by calling stdout() which returns a list
>>> echo.stdout()
['Hello, world']
>>> echo.stdout()
[]
Stdout is accrued until stdout() is called
>>> echo.call("Hello, world", capture=True)
0
>>> echo.call("Goodbye, world", capture=True)
0
>>> echo.stdout()
['Hello, world', 'Goodbye, world']
>>> echo.stdout()
[]
Pipe stdout to file with the file keyword argument
>>> import os
>>> import tempfile
>>>
>>> tmp = tempfile.NamedTemporaryFile(delete=False)
>>> echo.call("Hello, world", file=tmp.name)
0
>>> returncode = cat.call(tmp.name)
Hello, world
>>> returncode
0
>>> os.remove(tmp.name)
# redirect to /dev/null
>>> echo.call("Hello, world", file=os.devnull)
0
Failing command will raise a subprocess.CalledProcessError
>>> import contextlib
>>> from subprocess import CalledProcessError
>>>
>>> with contextlib.redirect_stderr(None):
... try:
... returncode = fails.call()
... except CalledProcessError as err:
... str(err)
"Command 'false' returned non-zero exit status 1."
>>> returncode
0
This, however, will not
>>> with contextlib.redirect_stderr(None):
... fails.call(suppress=True)
1
All the keyword arguments above can be set as the default for the instantiated object
>>> echo = Subprocess("echo", capture=True)
>>> echo.call("Hello, world")
0
>>> echo.stdout()
['Hello, world']
Which can then be overridden
>>> returncode = echo.call("Hello, world", capture=False)
Hello, world
>>> returncode
0
>>> echo.stdout()
[]
Metadata
Release files for spall 0.6.1
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 |
|---|---|---|---|---|
| spall-0.6.1.tar.gz | 5.8 kB | Without provenance | Details for spall-0.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spall-0.6.1-py3-none-any.whl | Python 3 | none | any | Details for spall-0.6.1-py3-none-any.whl |
Total release size: 12.2 kB
Release files / spall-0.6.1.tar.gz
| Download URL | spall-0.6.1.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
83002b2b60a7fd49c2a9108938d099fbf975048a4e0349f06c1a3c589de2bfcb
|
|
BLAKE2b-256 checksum How to use checksums |
1d6bdc82a52870f09ef73b0b8ed1b47e5fb6cb57aae7c75bd7864ab19a42671f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.8.13 Darwin/22.6.0
|
Release files / spall-0.6.1-py3-none-any.whl
| Download URL | spall-0.6.1-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a0174d6c8fdc13d7198c6c981c3a4eeb79898e4794b6ba3c35d4272ece0e1bb1
|
|
BLAKE2b-256 checksum How to use checksums |
4f522ea47d92752782bbf397b77437126db52193e47ef69c83cd91ab0f7e6cd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.8.13 Darwin/22.6.0
|
Security for spall 0.6.1
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.