spall
=====
.. image:: https://img.shields.io/badge/License-MIT-yellow.svg
:target: https://opensource.org/licenses/MIT
:alt: License
.. image:: https://img.shields.io/pypi/v/spall
:target: https://pypi.org/project/spall/
:alt: PyPI
.. image:: https://github.com/jshwi/spall/actions/workflows/build.yaml/badge.svg
:target: https://github.com/jshwi/spall/actions/workflows/build.yaml
:alt: Build
.. image:: https://github.com/jshwi/spall/actions/workflows/codeql-analysis.yml/badge.svg
:target: https://github.com/jshwi/spall/actions/workflows/codeql-analysis.yml
:alt: CodeQL
.. image:: https://results.pre-commit.ci/badge/github/jshwi/spall/master.svg
:target: https://results.pre-commit.ci/latest/github/jshwi/spall/master
:alt: pre-commit.ci status
.. image:: https://codecov.io/gh/jshwi/spall/branch/master/graph/badge.svg
:target: https://codecov.io/gh/jshwi/spall
:alt: codecov.io
.. image:: https://img.shields.io/badge/python-3.8-blue.svg
:target: https://www.python.org/downloads/release/python-380
:alt: python3.8
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
:alt: Black
.. image:: https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336
:target: https://pycqa.github.io/isort/
:alt: isort
.. image:: https://img.shields.io/badge/%20formatter-docformatter-fedcba.svg
:target: https://github.com/PyCQA/docformatter
:alt: docformatter
.. image:: https://img.shields.io/badge/linting-pylint-yellowgreen
:target: https://github.com/PyCQA/pylint
:alt: pylint
.. image:: https://img.shields.io/badge/security-bandit-yellow.svg
:target: https://github.com/PyCQA/bandit
:alt: Security Status
.. image:: https://snyk.io/test/github/jshwi/spall/badge.svg
:target: https://snyk.io/test/github/jshwi/spall/badge.svg
:alt: Known Vulnerabilities
.. image:: https://snyk.io/advisor/python/spall/badge.svg
:target: https://snyk.io/advisor/python/spall
:alt: spall
Object-oriented commandline
---------------------------
Install
-------
.. code-block:: console
$ pip install spall
Development
-----------
.. code-block:: console
$ pip install spall
Usage
-----
Import ``Subprocess`` from ``spall``
.. code-block:: python
>>> from spall import Subprocess
Instantiate individual executables
.. code-block:: python
>>> cat = Subprocess("cat")
>>> echo = Subprocess("echo")
>>> fails = Subprocess("false")
Default is to return returncode and print stdout and stderr to console
.. code-block:: python
>>> returncode = echo.call("Hello, world")
Hello, world
>>> returncode
0
Capture stdout with the ``capture`` keyword argument
.. code-block:: python
>>> echo.call("Hello, world", capture=True)
0
Stdout is consumed by calling ``stdout()`` which returns a list
.. code-block:: python
>>> echo.stdout()
['Hello, world']
>>> echo.stdout()
[]
Stdout is accrued until ``stdout()`` is called
.. code-block:: python
>>> 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
.. code-block:: python
>>> 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``
.. code-block:: python
>>> 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
.. code-block:: python
>>> 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
.. code-block:: python
>>> echo = Subprocess("echo", capture=True)
>>> echo.call("Hello, world")
0
>>> echo.stdout()
['Hello, world']
Which can then be overridden
.. code-block:: python
>>> returncode = echo.call("Hello, world", capture=False)
Hello, world
>>> returncode
0
>>> echo.stdout()
[]
Raw data
{
"_id": null,
"home_page": "https://pypi.org/project/spall/",
"name": "spall",
"maintainer": "jshwi",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "stephen@jshwisolutions.com",
"keywords": "commandline,oop,popen,run,subprocess",
"author": "jshwi",
"author_email": "stephen@jshwisolutions.com",
"download_url": "https://files.pythonhosted.org/packages/1d/6b/dc82a52870f09ef73b0b8ed1b47e5fb6cb57aae7c75bd7864ab19a42671f/spall-0.6.1.tar.gz",
"platform": null,
"description": "spall\n=====\n.. image:: https://img.shields.io/badge/License-MIT-yellow.svg\n :target: https://opensource.org/licenses/MIT\n :alt: License\n.. image:: https://img.shields.io/pypi/v/spall\n :target: https://pypi.org/project/spall/\n :alt: PyPI\n.. image:: https://github.com/jshwi/spall/actions/workflows/build.yaml/badge.svg\n :target: https://github.com/jshwi/spall/actions/workflows/build.yaml\n :alt: Build\n.. image:: https://github.com/jshwi/spall/actions/workflows/codeql-analysis.yml/badge.svg\n :target: https://github.com/jshwi/spall/actions/workflows/codeql-analysis.yml\n :alt: CodeQL\n.. image:: https://results.pre-commit.ci/badge/github/jshwi/spall/master.svg\n :target: https://results.pre-commit.ci/latest/github/jshwi/spall/master\n :alt: pre-commit.ci status\n.. image:: https://codecov.io/gh/jshwi/spall/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/jshwi/spall\n :alt: codecov.io\n.. image:: https://img.shields.io/badge/python-3.8-blue.svg\n :target: https://www.python.org/downloads/release/python-380\n :alt: python3.8\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n :target: https://github.com/psf/black\n :alt: Black\n.. image:: https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336\n :target: https://pycqa.github.io/isort/\n :alt: isort\n.. image:: https://img.shields.io/badge/%20formatter-docformatter-fedcba.svg\n :target: https://github.com/PyCQA/docformatter\n :alt: docformatter\n.. image:: https://img.shields.io/badge/linting-pylint-yellowgreen\n :target: https://github.com/PyCQA/pylint\n :alt: pylint\n.. image:: https://img.shields.io/badge/security-bandit-yellow.svg\n :target: https://github.com/PyCQA/bandit\n :alt: Security Status\n.. image:: https://snyk.io/test/github/jshwi/spall/badge.svg\n :target: https://snyk.io/test/github/jshwi/spall/badge.svg\n :alt: Known Vulnerabilities\n.. image:: https://snyk.io/advisor/python/spall/badge.svg\n :target: https://snyk.io/advisor/python/spall\n :alt: spall\n\nObject-oriented commandline\n---------------------------\n\n\nInstall\n-------\n\n.. code-block:: console\n\n $ pip install spall\n\nDevelopment\n-----------\n\n.. code-block:: console\n\n $ pip install spall\n\nUsage\n-----\n\nImport ``Subprocess`` from ``spall``\n\n.. code-block:: python\n\n >>> from spall import Subprocess\n\nInstantiate individual executables\n\n.. code-block:: python\n\n >>> cat = Subprocess(\"cat\")\n >>> echo = Subprocess(\"echo\")\n >>> fails = Subprocess(\"false\")\n\n\nDefault is to return returncode and print stdout and stderr to console\n\n.. code-block:: python\n\n >>> returncode = echo.call(\"Hello, world\")\n Hello, world\n >>> returncode\n 0\n\nCapture stdout with the ``capture`` keyword argument\n\n.. code-block:: python\n\n >>> echo.call(\"Hello, world\", capture=True)\n 0\n\nStdout is consumed by calling ``stdout()`` which returns a list\n\n.. code-block:: python\n\n >>> echo.stdout()\n ['Hello, world']\n >>> echo.stdout()\n []\n\nStdout is accrued until ``stdout()`` is called\n\n.. code-block:: python\n\n >>> echo.call(\"Hello, world\", capture=True)\n 0\n >>> echo.call(\"Goodbye, world\", capture=True)\n 0\n >>> echo.stdout()\n ['Hello, world', 'Goodbye, world']\n >>> echo.stdout()\n []\n\nPipe stdout to file with the ``file`` keyword argument\n\n.. code-block:: python\n\n >>> import os\n >>> import tempfile\n >>>\n >>> tmp = tempfile.NamedTemporaryFile(delete=False)\n >>> echo.call(\"Hello, world\", file=tmp.name)\n 0\n >>> returncode = cat.call(tmp.name)\n Hello, world\n >>> returncode\n 0\n >>> os.remove(tmp.name)\n\n # redirect to /dev/null\n >>> echo.call(\"Hello, world\", file=os.devnull)\n 0\n\nFailing command will raise a ``subprocess.CalledProcessError``\n\n.. code-block:: python\n\n >>> import contextlib\n >>> from subprocess import CalledProcessError\n >>>\n >>> with contextlib.redirect_stderr(None):\n ... try:\n ... returncode = fails.call()\n ... except CalledProcessError as err:\n ... str(err)\n \"Command 'false' returned non-zero exit status 1.\"\n >>> returncode\n 0\n\nThis, however, will not\n\n.. code-block:: python\n\n >>> with contextlib.redirect_stderr(None):\n ... fails.call(suppress=True)\n 1\n\nAll the keyword arguments above can be set as the default for the instantiated object\n\n.. code-block:: python\n\n >>> echo = Subprocess(\"echo\", capture=True)\n >>> echo.call(\"Hello, world\")\n 0\n >>> echo.stdout()\n ['Hello, world']\n\nWhich can then be overridden\n\n.. code-block:: python\n\n >>> returncode = echo.call(\"Hello, world\", capture=False)\n Hello, world\n >>> returncode\n 0\n >>> echo.stdout()\n []\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Object-oriented commandline",
"version": "0.6.1",
"project_urls": {
"Documentation": "https://spall.readthedocs.io/en/latest",
"Homepage": "https://pypi.org/project/spall/",
"Repository": "https://github.com/jshwi/spall"
},
"split_keywords": [
"commandline",
"oop",
"popen",
"run",
"subprocess"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4f522ea47d92752782bbf397b77437126db52193e47ef69c83cd91ab0f7e6cd2",
"md5": "3f2da8925b18399a090ace629af0734a",
"sha256": "a0174d6c8fdc13d7198c6c981c3a4eeb79898e4794b6ba3c35d4272ece0e1bb1"
},
"downloads": -1,
"filename": "spall-0.6.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3f2da8925b18399a090ace629af0734a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 6317,
"upload_time": "2023-09-10T02:28:28",
"upload_time_iso_8601": "2023-09-10T02:28:28.370988Z",
"url": "https://files.pythonhosted.org/packages/4f/52/2ea47d92752782bbf397b77437126db52193e47ef69c83cd91ab0f7e6cd2/spall-0.6.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1d6bdc82a52870f09ef73b0b8ed1b47e5fb6cb57aae7c75bd7864ab19a42671f",
"md5": "ec9e724ead3d2dfc1486b5b38321102f",
"sha256": "83002b2b60a7fd49c2a9108938d099fbf975048a4e0349f06c1a3c589de2bfcb"
},
"downloads": -1,
"filename": "spall-0.6.1.tar.gz",
"has_sig": false,
"md5_digest": "ec9e724ead3d2dfc1486b5b38321102f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 5834,
"upload_time": "2023-09-10T02:28:30",
"upload_time_iso_8601": "2023-09-10T02:28:30.106808Z",
"url": "https://files.pythonhosted.org/packages/1d/6b/dc82a52870f09ef73b0b8ed1b47e5fb6cb57aae7c75bd7864ab19a42671f/spall-0.6.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-10 02:28:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jshwi",
"github_project": "spall",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "spall"
}