failprint


Namefailprint JSON
Version 1.0.3 PyPI version JSON
download
home_pageNone
SummaryRun a command, print its output only if it fails.
upload_time2024-10-17 14:57:24
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseISC
keywords cli failure output runner
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # failprint

[![ci](https://github.com/pawamoy/failprint/workflows/ci/badge.svg)](https://github.com/pawamoy/failprint/actions?query=workflow%3Aci)
[![documentation](https://img.shields.io/badge/docs-mkdocs-708FCC.svg?style=flat)](https://pawamoy.github.io/failprint/)
[![pypi version](https://img.shields.io/pypi/v/failprint.svg)](https://pypi.org/project/failprint/)
[![gitpod](https://img.shields.io/badge/gitpod-workspace-708FCC.svg?style=flat)](https://gitpod.io/#https://github.com/pawamoy/failprint)
[![gitter](https://badges.gitter.im/join%20chat.svg)](https://app.gitter.im/#/room/#failprint:gitter.im)

Run a command, print its output only if it fails.

Tired of searching the `quiet` options of your programs
to lighten up the output of your `make check` or `make lint` commands?

Tired of finding out that standard output and error are mixed up in some of them?

Simply run your command through `failprint`.
If it succeeds, nothing is printed.
If it fails, standard error is printed.
Plus other configuration goodies :wink:

## Example

You don't want to see output when the command succeeds.

![demo](demo.svg)

The task runner [`duty`](https://github.com/pawamoy/duty) uses `failprint`,
allowing you to define tasks in Python and run them with minimalist and beautiful output:

![demo_duty](demo_duty.svg)

## Requirements

failprint requires Python 3.8 or above.

<details>
<summary>To install Python 3.8, I recommend using <a href="https://github.com/pyenv/pyenv"><code>pyenv</code></a>.</summary>

```bash
# install pyenv
git clone https://github.com/pyenv/pyenv ~/.pyenv

# setup pyenv (you should also put these three lines in .bashrc or similar)
export PATH="${HOME}/.pyenv/bin:${PATH}"
export PYENV_ROOT="${HOME}/.pyenv"
eval "$(pyenv init -)"

# install Python 3.8.17
pyenv install 3.8.17

# make it available globally
pyenv global system 3.8.17
```
</details>

## Installation

```bash
pip install failprint
```

With [`uv`](https://docs.astral.sh/uv/):

```bash
uv tool install failprint
```

## Usage

```console
% poetry run failprint -h
usage: failprint [-h] [-c {stdout,stderr,both,none}] [-f {pretty,tap}] [-y | -Y] [-p | -P] [-q | -Q] [-s | -S] [-z | -Z] [-n NUMBER]
                 [-t TITLE]
                 COMMAND [COMMAND ...]

positional arguments:
  COMMAND

optional arguments:
  -h, --help            show this help message and exit
  -c {stdout,stderr,both,none}, --capture {stdout,stderr,both,none}
                        Which output to capture. Colors are supported with 'both' only, unless the command has a 'force color'
                        option.
  -f {pretty,tap}, --format {pretty,tap}
                        Output format. Pass your own Jinja2 template as a string with '-f custom=TEMPLATE'. Available variables:
                        command, title (command or title passed with -t), code (exit status), success (boolean), failure (boolean),
                        number (command number passed with -n), output (command output), nofail (boolean), quiet (boolean), silent
                        (boolean). Available filters: indent (textwrap.indent).
  -y, --pty             Enable the use of a pseudo-terminal. PTY doesn't allow programs to use standard input.
  -Y, --no-pty          Disable the use of a pseudo-terminal. PTY doesn't allow programs to use standard input.
  -p, --progress        Print progress while running a command.
  -P, --no-progress     Don't print progress while running a command.
  -q, --quiet           Don't print the command output, even if it failed.
  -Q, --no-quiet        Print the command output when it fails.
  -s, --silent          Don't print anything.
  -S, --no-silent       Print output as usual.
  -z, --zero, --nofail  Don't fail. Always return a success (0) exit code.
  -Z, --no-zero, --strict
                        Return the original exit code.
  -n NUMBER, --number NUMBER
                        Command number. Useful for the 'tap' format.
  -t TITLE, --title TITLE
                        Command title. Default is the command itself.
```

```python
from failprint.runners import run

cmd = "echo hello"

exit_code = run(
    cmd,            # str, list of str, or Python callable
    args=None,      # args for callable
    kwargs=None,    # kwargs for callable
    number=1,       # command number, useful for tap format
    capture=None,   # stdout, stderr, both, none, True or False
    title=None,     # command title
    fmt=None,       # pretty, tap, or custom="MY_CUSTOM_FORMAT"
    pty=False,      # use a PTY
    progress=True,  # print the "progress" template before running the command
    nofail=False,   # always return zero
    quiet=False,    # don't print output when the command fails
    silent=False,   # don't print anything
)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "failprint",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "cli, failure, output, runner",
    "author": null,
    "author_email": "=?utf-8?q?Timoth=C3=A9e_Mazzucotelli?= <dev@pawamoy.fr>",
    "download_url": "https://files.pythonhosted.org/packages/28/dd/1bbef53dc84e1545420cde660b3abd89b17ee0192cc2d7c0ac7696a4ea5c/failprint-1.0.3.tar.gz",
    "platform": null,
    "description": "# failprint\n\n[![ci](https://github.com/pawamoy/failprint/workflows/ci/badge.svg)](https://github.com/pawamoy/failprint/actions?query=workflow%3Aci)\n[![documentation](https://img.shields.io/badge/docs-mkdocs-708FCC.svg?style=flat)](https://pawamoy.github.io/failprint/)\n[![pypi version](https://img.shields.io/pypi/v/failprint.svg)](https://pypi.org/project/failprint/)\n[![gitpod](https://img.shields.io/badge/gitpod-workspace-708FCC.svg?style=flat)](https://gitpod.io/#https://github.com/pawamoy/failprint)\n[![gitter](https://badges.gitter.im/join%20chat.svg)](https://app.gitter.im/#/room/#failprint:gitter.im)\n\nRun a command, print its output only if it fails.\n\nTired of searching the `quiet` options of your programs\nto lighten up the output of your `make check` or `make lint` commands?\n\nTired of finding out that standard output and error are mixed up in some of them?\n\nSimply run your command through `failprint`.\nIf it succeeds, nothing is printed.\nIf it fails, standard error is printed.\nPlus other configuration goodies :wink:\n\n## Example\n\nYou don't want to see output when the command succeeds.\n\n![demo](demo.svg)\n\nThe task runner [`duty`](https://github.com/pawamoy/duty) uses `failprint`,\nallowing you to define tasks in Python and run them with minimalist and beautiful output:\n\n![demo_duty](demo_duty.svg)\n\n## Requirements\n\nfailprint requires Python 3.8 or above.\n\n<details>\n<summary>To install Python 3.8, I recommend using <a href=\"https://github.com/pyenv/pyenv\"><code>pyenv</code></a>.</summary>\n\n```bash\n# install pyenv\ngit clone https://github.com/pyenv/pyenv ~/.pyenv\n\n# setup pyenv (you should also put these three lines in .bashrc or similar)\nexport PATH=\"${HOME}/.pyenv/bin:${PATH}\"\nexport PYENV_ROOT=\"${HOME}/.pyenv\"\neval \"$(pyenv init -)\"\n\n# install Python 3.8.17\npyenv install 3.8.17\n\n# make it available globally\npyenv global system 3.8.17\n```\n</details>\n\n## Installation\n\n```bash\npip install failprint\n```\n\nWith [`uv`](https://docs.astral.sh/uv/):\n\n```bash\nuv tool install failprint\n```\n\n## Usage\n\n```console\n% poetry run failprint -h\nusage: failprint [-h] [-c {stdout,stderr,both,none}] [-f {pretty,tap}] [-y | -Y] [-p | -P] [-q | -Q] [-s | -S] [-z | -Z] [-n NUMBER]\n                 [-t TITLE]\n                 COMMAND [COMMAND ...]\n\npositional arguments:\n  COMMAND\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -c {stdout,stderr,both,none}, --capture {stdout,stderr,both,none}\n                        Which output to capture. Colors are supported with 'both' only, unless the command has a 'force color'\n                        option.\n  -f {pretty,tap}, --format {pretty,tap}\n                        Output format. Pass your own Jinja2 template as a string with '-f custom=TEMPLATE'. Available variables:\n                        command, title (command or title passed with -t), code (exit status), success (boolean), failure (boolean),\n                        number (command number passed with -n), output (command output), nofail (boolean), quiet (boolean), silent\n                        (boolean). Available filters: indent (textwrap.indent).\n  -y, --pty             Enable the use of a pseudo-terminal. PTY doesn't allow programs to use standard input.\n  -Y, --no-pty          Disable the use of a pseudo-terminal. PTY doesn't allow programs to use standard input.\n  -p, --progress        Print progress while running a command.\n  -P, --no-progress     Don't print progress while running a command.\n  -q, --quiet           Don't print the command output, even if it failed.\n  -Q, --no-quiet        Print the command output when it fails.\n  -s, --silent          Don't print anything.\n  -S, --no-silent       Print output as usual.\n  -z, --zero, --nofail  Don't fail. Always return a success (0) exit code.\n  -Z, --no-zero, --strict\n                        Return the original exit code.\n  -n NUMBER, --number NUMBER\n                        Command number. Useful for the 'tap' format.\n  -t TITLE, --title TITLE\n                        Command title. Default is the command itself.\n```\n\n```python\nfrom failprint.runners import run\n\ncmd = \"echo hello\"\n\nexit_code = run(\n    cmd,            # str, list of str, or Python callable\n    args=None,      # args for callable\n    kwargs=None,    # kwargs for callable\n    number=1,       # command number, useful for tap format\n    capture=None,   # stdout, stderr, both, none, True or False\n    title=None,     # command title\n    fmt=None,       # pretty, tap, or custom=\"MY_CUSTOM_FORMAT\"\n    pty=False,      # use a PTY\n    progress=True,  # print the \"progress\" template before running the command\n    nofail=False,   # always return zero\n    quiet=False,    # don't print output when the command fails\n    silent=False,   # don't print anything\n)\n```\n",
    "bugtrack_url": null,
    "license": "ISC",
    "summary": "Run a command, print its output only if it fails.",
    "version": "1.0.3",
    "project_urls": {
        "Changelog": "https://pawamoy.github.io/failprint/changelog",
        "Discussions": "https://github.com/pawamoy/failprint/discussions",
        "Documentation": "https://pawamoy.github.io/failprint",
        "Funding": "https://github.com/sponsors/pawamoy",
        "Gitter": "https://gitter.im/failprint/community",
        "Homepage": "https://pawamoy.github.io/failprint",
        "Issues": "https://github.com/pawamoy/failprint/issues",
        "Repository": "https://github.com/pawamoy/failprint"
    },
    "split_keywords": [
        "cli",
        " failure",
        " output",
        " runner"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f5f34b44a648f0f080735579d8f7532e45a0aadf8b7d43c0090d1e9f597fefaf",
                "md5": "9de5c061d309e0f9b0beb9a58709d165",
                "sha256": "5c2c211b09d31cc5366ce0b65879f84e33b367d245c7f91d51d9ce9e998a4ff7"
            },
            "downloads": -1,
            "filename": "failprint-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9de5c061d309e0f9b0beb9a58709d165",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 18074,
            "upload_time": "2024-10-17T14:57:23",
            "upload_time_iso_8601": "2024-10-17T14:57:23.192972Z",
            "url": "https://files.pythonhosted.org/packages/f5/f3/4b44a648f0f080735579d8f7532e45a0aadf8b7d43c0090d1e9f597fefaf/failprint-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "28dd1bbef53dc84e1545420cde660b3abd89b17ee0192cc2d7c0ac7696a4ea5c",
                "md5": "e069d6230bc5331c02c23a99412c9374",
                "sha256": "21af2e1d8da6db1d35d5ce0c1e3b8554e36bcc90339b874e6142d4c41add9b64"
            },
            "downloads": -1,
            "filename": "failprint-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "e069d6230bc5331c02c23a99412c9374",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 43779,
            "upload_time": "2024-10-17T14:57:24",
            "upload_time_iso_8601": "2024-10-17T14:57:24.534622Z",
            "url": "https://files.pythonhosted.org/packages/28/dd/1bbef53dc84e1545420cde660b3abd89b17ee0192cc2d7c0ac7696a4ea5c/failprint-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-17 14:57:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pawamoy",
    "github_project": "failprint",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "failprint"
}
        
Elapsed time: 0.33170s