pretty-traceback


Namepretty-traceback JSON
Version 2023.1020 PyPI version JSON
download
home_pagehttps://github.com/mbarkhau/pretty-traceback
SummaryHuman readable stacktraces.
upload_time2023-09-07 19:04:12
maintainer
docs_urlNone
authorManuel Barkhau
requires_python>=2.7
licenseMIT
keywords traceback stacktrace pretty
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # [Pretty Traceback][repo_ref]

Human readable stacktraces for Python.

Project/Repo:

[![MIT License][license_img]][license_ref]
[![Supported Python Versions][pyversions_img]][pyversions_ref]
[![CalVer 2023.1020][version_img]][version_ref]
[![PyPI Version][pypi_img]][pypi_ref]
[![PyPI Downloads][downloads_img]][downloads_ref]

Code Quality/CI:

[![GitHub Build Status][github_build_img]][github_build_ref]
[![GitLab Build Status][gitlab_build_img]][gitlab_build_ref]
[![Type Checked with mypy][mypy_img]][mypy_ref]
[![Code Coverage][codecov_img]][codecov_ref]
[![Code Style: sjfmt][style_img]][style_ref]


## Overview

Pretty Traceback groups together what belongs together, adds coloring and alignment. All of this makes it easier for you to see patterns and filter out the signal from the noise. This tabular format is best viewed in a wide terminal.

In other words, get this 😍

<div align="center">
<p align="center">
  <img alt="logo" src="https://github.com/mbarkhau/pretty-traceback/raw/master/example_tb4.png">
</p>
</div>

Instead of this 🤮

```
Traceback (most recent call last):
  File "test/test_formatting.py", line 199, in <module>
    main()
  File "test/test_formatting.py", line 190, in main
    run_pingpong()
  File "test/test_formatting.py", line 161, in run_pingpong
    sched3.run()
  File "/home/mbarkhau/miniconda3/envs/pretty-traceback_py38/lib/python3.8/sched.py", line 151, in run
    action(*argument, **kwargs)
  File "/home/mbarkhau/miniconda3/envs/pretty-traceback_py38/lib/python3.8/sched.py", line 151, in run
    action(*argument, **kwargs)
  File "/home/mbarkhau/miniconda3/envs/pretty-traceback_py38/lib/python3.8/sched.py", line 151, in run
    action(*argument, **kwargs)
  File "test/test_formatting.py", line 151, in _ping
    _pong(depth + 1)
  File "test/test_formatting.py", line 129, in _pong
    _ping(depth + 1)
  File "test/test_formatting.py", line 136, in _ping
    sp.check_output(["command_that", "doesnt", "exist"])
  File "/home/mbarkhau/miniconda3/envs/pretty-traceback_py38/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/home/mbarkhau/miniconda3/envs/pretty-traceback_py38/lib/python3.8/subprocess.py", line 489, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/home/mbarkhau/miniconda3/envs/pretty-traceback_py38/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/mbarkhau/miniconda3/envs/pretty-traceback_py38/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'command_that'
```

If your terminal is wide enough, the long paths are preserved.

<div align="center">
<p align="center">
  <img alt="logo" src="https://github.com/mbarkhau/pretty-traceback/raw/master/example_tb5.png">
</p>
</div>


## Usage

Add the following to your `__main__.py` or the equivalent module which is your entry point.

```python
try:
    import pretty_traceback
    pretty_traceback.install()
except ImportError:
    pass    # no need to fail because of missing dev dependency
```

Please do not add this code e.g. to your `__init__.py` or any other module that your users may import. They may not want you to mess with how their tracebacks are printed.

If you do feel the overwhelming desire to import the `pretty_traceback` in code that others might import, consider using the `envvar` argument, which will cause the install function to effectively be a noop unless you set `ENABLE_PRETTY_TRACEBACK=1`.

```python
try:
    import pretty_traceback
    pretty_traceback.install(envvar='ENABLE_PRETTY_TRACEBACK')
except ImportError:
    pass    # no need to fail because of missing dev dependency
```

Note, that the hook is only installed if the existing hook is the default. Any existing hooks that were installed before the call of `pretty_traceback.install` will be left in place.


## LoggingFormatter

A `logging.Formatter` subclass is also available (e.g. for integration with `flask`).

```python
import os
from flask.logging import default_handler

try:
    if os.getenv('FLASK_DEBUG') == "1":
        import pretty_traceback
        default_handler.setFormatter(pretty_traceback.LoggingFormatter())
except ImportError:
    pass    # no need to fail because of missing dev dependency
```


## More Examples

<div align="center">
<p align="center">
  <img alt="logo" src="https://github.com/mbarkhau/pretty-traceback/raw/master/example_tb0.png">
</p>
</div>

<div align="center">
<p align="center">
  <img alt="logo" src="https://github.com/mbarkhau/pretty-traceback/raw/master/example_tb3.png">
</p>
</div>

<div align="center">
<p align="center">
  <img alt="logo" src="https://github.com/mbarkhau/pretty-traceback/raw/master/example_tb_wide.png">
</p>
</div>



## Alternatives

Pretty Traceback is heavily inspired by the backtrace module by [nir0s](https://github.com/nir0s/backtrace) but there are many others (sorted by github stars):

- https://github.com/qix-/better-exceptions                 <!-- 03800 -->
- https://github.com/cknd/stackprinter                      <!-- 01000 -->
- https://github.com/onelivesleft/PrettyErrors              <!-- 00873 -->
- https://github.com/skorokithakis/tbvaccine                <!-- 00365 -->
- https://github.com/aroberge/friendly-traceback            <!-- 00164 -->
- https://github.com/HallerPatrick/frosch                   <!-- 00158 -->
- https://github.com/nir0s/backtrace                        <!-- 00079 -->
- https://github.com/staticshock/colored-traceback.py       <!-- 00039 -->
- https://github.com/chillaranand/ptb                       <!-- 00006 -->
- https://github.com/laurb9/rich-traceback                  <!-- 00002 -->
- https://github.com/willmcgugan/rich#tracebacks            <!-- 14000 -->

[repo_ref]: https://github.com/mbarkhau/pretty-traceback

[github_build_img]: https://github.com/mbarkhau/pretty-traceback/workflows/CI/badge.svg
[github_build_ref]: https://github.com/mbarkhau/pretty-traceback/actions?query=workflow%3ACI

[gitlab_build_img]: https://gitlab.com/mbarkhau/pretty-traceback/badges/master/pipeline.svg
[gitlab_build_ref]: https://gitlab.com/mbarkhau/pretty-traceback/pipelines

[codecov_img]: https://gitlab.com/mbarkhau/pretty-traceback/badges/master/coverage.svg
[codecov_ref]: https://mbarkhau.gitlab.io/pretty-traceback/cov

[license_img]: https://img.shields.io/badge/License-MIT-blue.svg
[license_ref]: https://gitlab.com/mbarkhau/pretty-traceback/blob/master/LICENSE

[mypy_img]: https://img.shields.io/badge/mypy-checked-green.svg
[mypy_ref]: https://mbarkhau.gitlab.io/pretty-traceback/mypycov

[style_img]: https://img.shields.io/badge/code%20style-%20sjfmt-f71.svg
[style_ref]: https://gitlab.com/mbarkhau/straitjacket/

[pypi_img]: https://img.shields.io/badge/PyPI-wheels-green.svg
[pypi_ref]: https://pypi.org/project/pretty-traceback/#files

[downloads_img]: https://pepy.tech/badge/pretty-traceback/month
[downloads_ref]: https://pepy.tech/project/pretty-traceback

[version_img]: https://img.shields.io/static/v1.svg?label=CalVer&message=2023.1020&color=blue
[version_ref]: https://pypi.org/project/bumpver/

[pyversions_img]: https://img.shields.io/pypi/pyversions/pretty-traceback.svg
[pyversions_ref]: https://pypi.python.org/pypi/pretty-traceback


## Contributors

|                 Name                |        role       |  since  | until |
|-------------------------------------|-------------------|---------|-------|
| Manuel Barkhau (mbarkhau@gmail.com) | author/maintainer | 2020-08 | -     |


# Changelog for https://github.com/mbarkhau/pretty-traceback

## 2023.1020

- Fix: Prevent errors in non-tty environments [gh#8][gh8]

[gh9]: https://github.com/mbarkhau/pretty-traceback/issues/9


## 2023.1019

- Update: Append lineno to filename so it can be parsed by editors/IDEs. [gh#8][gh8]

[gh8]: https://github.com/mbarkhau/pretty-traceback/pull/8


## 2022.1018

- Add final newline to output. See [gh#3][gh3]

[gh3]: https://github.com/mbarkhau/pretty-traceback/issues/3


## 2021.1017

- Fix highlight in wide mode


## 2020.1016

- Shorten tracebacks for `RecursionError`


## 2020.1012

- Improve alias selection


## 2020.1011

- Fix github #1: Invalid path handling for `./script.py`


## 2020.1010

- Fix gitlab #5: Only show aliases that were actually used.
- Fix gitlab #5: Better alignment on narrow terminals.


## 2020.1009

- Fix gitlab #3: Corner case where exception has `None` as context.
- Fix gitlab #2: Improve formatting when line overflows.


## 2020.1008

- Add `pretty_traceback.LoggingFormatter`


## 2020.1006

- Add wide mode.


## 2020.1005

- Update formatting to work better with recursive calls.
- Add tests


## 2020.1001

- Initial release

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mbarkhau/pretty-traceback",
    "name": "pretty-traceback",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=2.7",
    "maintainer_email": "",
    "keywords": "traceback stacktrace pretty",
    "author": "Manuel Barkhau",
    "author_email": "mbarkhau@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/33/69/83ee31c058bbd266c22b3ed0d41c0a7908dc6c65647317cefd0c04116de0/pretty-traceback-2023.1020.tar.gz",
    "platform": null,
    "description": "# [Pretty Traceback][repo_ref]\n\nHuman readable stacktraces for Python.\n\nProject/Repo:\n\n[![MIT License][license_img]][license_ref]\n[![Supported Python Versions][pyversions_img]][pyversions_ref]\n[![CalVer 2023.1020][version_img]][version_ref]\n[![PyPI Version][pypi_img]][pypi_ref]\n[![PyPI Downloads][downloads_img]][downloads_ref]\n\nCode Quality/CI:\n\n[![GitHub Build Status][github_build_img]][github_build_ref]\n[![GitLab Build Status][gitlab_build_img]][gitlab_build_ref]\n[![Type Checked with mypy][mypy_img]][mypy_ref]\n[![Code Coverage][codecov_img]][codecov_ref]\n[![Code Style: sjfmt][style_img]][style_ref]\n\n\n## Overview\n\nPretty Traceback groups together what belongs together, adds coloring and alignment. All of this makes it easier for you to see patterns and filter out the signal from the noise. This tabular format is best viewed in a wide terminal.\n\nIn other words, get this \ud83d\ude0d\n\n<div align=\"center\">\n<p align=\"center\">\n  <img alt=\"logo\" src=\"https://github.com/mbarkhau/pretty-traceback/raw/master/example_tb4.png\">\n</p>\n</div>\n\nInstead of this \ud83e\udd2e\n\n```\nTraceback (most recent call last):\n  File \"test/test_formatting.py\", line 199, in <module>\n    main()\n  File \"test/test_formatting.py\", line 190, in main\n    run_pingpong()\n  File \"test/test_formatting.py\", line 161, in run_pingpong\n    sched3.run()\n  File \"/home/mbarkhau/miniconda3/envs/pretty-traceback_py38/lib/python3.8/sched.py\", line 151, in run\n    action(*argument, **kwargs)\n  File \"/home/mbarkhau/miniconda3/envs/pretty-traceback_py38/lib/python3.8/sched.py\", line 151, in run\n    action(*argument, **kwargs)\n  File \"/home/mbarkhau/miniconda3/envs/pretty-traceback_py38/lib/python3.8/sched.py\", line 151, in run\n    action(*argument, **kwargs)\n  File \"test/test_formatting.py\", line 151, in _ping\n    _pong(depth + 1)\n  File \"test/test_formatting.py\", line 129, in _pong\n    _ping(depth + 1)\n  File \"test/test_formatting.py\", line 136, in _ping\n    sp.check_output([\"command_that\", \"doesnt\", \"exist\"])\n  File \"/home/mbarkhau/miniconda3/envs/pretty-traceback_py38/lib/python3.8/subprocess.py\", line 411, in check_output\n    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,\n  File \"/home/mbarkhau/miniconda3/envs/pretty-traceback_py38/lib/python3.8/subprocess.py\", line 489, in run\n    with Popen(*popenargs, **kwargs) as process:\n  File \"/home/mbarkhau/miniconda3/envs/pretty-traceback_py38/lib/python3.8/subprocess.py\", line 854, in __init__\n    self._execute_child(args, executable, preexec_fn, close_fds,\n  File \"/home/mbarkhau/miniconda3/envs/pretty-traceback_py38/lib/python3.8/subprocess.py\", line 1702, in _execute_child\n    raise child_exception_type(errno_num, err_msg, err_filename)\nFileNotFoundError: [Errno 2] No such file or directory: 'command_that'\n```\n\nIf your terminal is wide enough, the long paths are preserved.\n\n<div align=\"center\">\n<p align=\"center\">\n  <img alt=\"logo\" src=\"https://github.com/mbarkhau/pretty-traceback/raw/master/example_tb5.png\">\n</p>\n</div>\n\n\n## Usage\n\nAdd the following to your `__main__.py` or the equivalent module which is your entry point.\n\n```python\ntry:\n    import pretty_traceback\n    pretty_traceback.install()\nexcept ImportError:\n    pass    # no need to fail because of missing dev dependency\n```\n\nPlease do not add this code e.g. to your `__init__.py` or any other module that your users may import. They may not want you to mess with how their tracebacks are printed.\n\nIf you do feel the overwhelming desire to import the `pretty_traceback` in code that others might import, consider using the `envvar` argument, which will cause the install function to effectively be a noop unless you set `ENABLE_PRETTY_TRACEBACK=1`.\n\n```python\ntry:\n    import pretty_traceback\n    pretty_traceback.install(envvar='ENABLE_PRETTY_TRACEBACK')\nexcept ImportError:\n    pass    # no need to fail because of missing dev dependency\n```\n\nNote, that the hook is only installed if the existing hook is the default. Any existing hooks that were installed before the call of `pretty_traceback.install` will be left in place.\n\n\n## LoggingFormatter\n\nA `logging.Formatter` subclass is also available (e.g. for integration with `flask`).\n\n```python\nimport os\nfrom flask.logging import default_handler\n\ntry:\n    if os.getenv('FLASK_DEBUG') == \"1\":\n        import pretty_traceback\n        default_handler.setFormatter(pretty_traceback.LoggingFormatter())\nexcept ImportError:\n    pass    # no need to fail because of missing dev dependency\n```\n\n\n## More Examples\n\n<div align=\"center\">\n<p align=\"center\">\n  <img alt=\"logo\" src=\"https://github.com/mbarkhau/pretty-traceback/raw/master/example_tb0.png\">\n</p>\n</div>\n\n<div align=\"center\">\n<p align=\"center\">\n  <img alt=\"logo\" src=\"https://github.com/mbarkhau/pretty-traceback/raw/master/example_tb3.png\">\n</p>\n</div>\n\n<div align=\"center\">\n<p align=\"center\">\n  <img alt=\"logo\" src=\"https://github.com/mbarkhau/pretty-traceback/raw/master/example_tb_wide.png\">\n</p>\n</div>\n\n\n\n## Alternatives\n\nPretty Traceback is heavily inspired by the backtrace module by [nir0s](https://github.com/nir0s/backtrace) but there are many others (sorted by github stars):\n\n- https://github.com/qix-/better-exceptions                 <!-- 03800 -->\n- https://github.com/cknd/stackprinter                      <!-- 01000 -->\n- https://github.com/onelivesleft/PrettyErrors              <!-- 00873 -->\n- https://github.com/skorokithakis/tbvaccine                <!-- 00365 -->\n- https://github.com/aroberge/friendly-traceback            <!-- 00164 -->\n- https://github.com/HallerPatrick/frosch                   <!-- 00158 -->\n- https://github.com/nir0s/backtrace                        <!-- 00079 -->\n- https://github.com/staticshock/colored-traceback.py       <!-- 00039 -->\n- https://github.com/chillaranand/ptb                       <!-- 00006 -->\n- https://github.com/laurb9/rich-traceback                  <!-- 00002 -->\n- https://github.com/willmcgugan/rich#tracebacks            <!-- 14000 -->\n\n[repo_ref]: https://github.com/mbarkhau/pretty-traceback\n\n[github_build_img]: https://github.com/mbarkhau/pretty-traceback/workflows/CI/badge.svg\n[github_build_ref]: https://github.com/mbarkhau/pretty-traceback/actions?query=workflow%3ACI\n\n[gitlab_build_img]: https://gitlab.com/mbarkhau/pretty-traceback/badges/master/pipeline.svg\n[gitlab_build_ref]: https://gitlab.com/mbarkhau/pretty-traceback/pipelines\n\n[codecov_img]: https://gitlab.com/mbarkhau/pretty-traceback/badges/master/coverage.svg\n[codecov_ref]: https://mbarkhau.gitlab.io/pretty-traceback/cov\n\n[license_img]: https://img.shields.io/badge/License-MIT-blue.svg\n[license_ref]: https://gitlab.com/mbarkhau/pretty-traceback/blob/master/LICENSE\n\n[mypy_img]: https://img.shields.io/badge/mypy-checked-green.svg\n[mypy_ref]: https://mbarkhau.gitlab.io/pretty-traceback/mypycov\n\n[style_img]: https://img.shields.io/badge/code%20style-%20sjfmt-f71.svg\n[style_ref]: https://gitlab.com/mbarkhau/straitjacket/\n\n[pypi_img]: https://img.shields.io/badge/PyPI-wheels-green.svg\n[pypi_ref]: https://pypi.org/project/pretty-traceback/#files\n\n[downloads_img]: https://pepy.tech/badge/pretty-traceback/month\n[downloads_ref]: https://pepy.tech/project/pretty-traceback\n\n[version_img]: https://img.shields.io/static/v1.svg?label=CalVer&message=2023.1020&color=blue\n[version_ref]: https://pypi.org/project/bumpver/\n\n[pyversions_img]: https://img.shields.io/pypi/pyversions/pretty-traceback.svg\n[pyversions_ref]: https://pypi.python.org/pypi/pretty-traceback\n\n\n## Contributors\n\n|                 Name                |        role       |  since  | until |\n|-------------------------------------|-------------------|---------|-------|\n| Manuel Barkhau (mbarkhau@gmail.com) | author/maintainer | 2020-08 | -     |\n\n\n# Changelog for https://github.com/mbarkhau/pretty-traceback\n\n## 2023.1020\n\n- Fix: Prevent errors in non-tty environments [gh#8][gh8]\n\n[gh9]: https://github.com/mbarkhau/pretty-traceback/issues/9\n\n\n## 2023.1019\n\n- Update: Append lineno to filename so it can be parsed by editors/IDEs. [gh#8][gh8]\n\n[gh8]: https://github.com/mbarkhau/pretty-traceback/pull/8\n\n\n## 2022.1018\n\n- Add final newline to output. See [gh#3][gh3]\n\n[gh3]: https://github.com/mbarkhau/pretty-traceback/issues/3\n\n\n## 2021.1017\n\n- Fix highlight in wide mode\n\n\n## 2020.1016\n\n- Shorten tracebacks for `RecursionError`\n\n\n## 2020.1012\n\n- Improve alias selection\n\n\n## 2020.1011\n\n- Fix github #1: Invalid path handling for `./script.py`\n\n\n## 2020.1010\n\n- Fix gitlab #5: Only show aliases that were actually used.\n- Fix gitlab #5: Better alignment on narrow terminals.\n\n\n## 2020.1009\n\n- Fix gitlab #3: Corner case where exception has `None` as context.\n- Fix gitlab #2: Improve formatting when line overflows.\n\n\n## 2020.1008\n\n- Add `pretty_traceback.LoggingFormatter`\n\n\n## 2020.1006\n\n- Add wide mode.\n\n\n## 2020.1005\n\n- Update formatting to work better with recursive calls.\n- Add tests\n\n\n## 2020.1001\n\n- Initial release\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Human readable stacktraces.",
    "version": "2023.1020",
    "project_urls": {
        "Homepage": "https://github.com/mbarkhau/pretty-traceback"
    },
    "split_keywords": [
        "traceback",
        "stacktrace",
        "pretty"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ca6f8a06583b5a70ff6cb4cdc4fe4baf121d9cf439c0391791ccd3ae776e530f",
                "md5": "3ce08df4767e79564cab9d1b22c938a9",
                "sha256": "164c05835635463c93c01b85fc33594d71547f4b1ece416168c6891f1d99cc2c"
            },
            "downloads": -1,
            "filename": "pretty_traceback-2023.1020-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3ce08df4767e79564cab9d1b22c938a9",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=2.7",
            "size": 12186,
            "upload_time": "2023-09-07T19:04:10",
            "upload_time_iso_8601": "2023-09-07T19:04:10.502339Z",
            "url": "https://files.pythonhosted.org/packages/ca/6f/8a06583b5a70ff6cb4cdc4fe4baf121d9cf439c0391791ccd3ae776e530f/pretty_traceback-2023.1020-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "336983ee31c058bbd266c22b3ed0d41c0a7908dc6c65647317cefd0c04116de0",
                "md5": "48c764569bf520e19e0b34f99a004965",
                "sha256": "d40249eb2c03ec839d4d085155a7ae00e2e8c4915f66f4739046461876dd7280"
            },
            "downloads": -1,
            "filename": "pretty-traceback-2023.1020.tar.gz",
            "has_sig": false,
            "md5_digest": "48c764569bf520e19e0b34f99a004965",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.7",
            "size": 17986,
            "upload_time": "2023-09-07T19:04:12",
            "upload_time_iso_8601": "2023-09-07T19:04:12.237099Z",
            "url": "https://files.pythonhosted.org/packages/33/69/83ee31c058bbd266c22b3ed0d41c0a7908dc6c65647317cefd0c04116de0/pretty-traceback-2023.1020.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-07 19:04:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mbarkhau",
    "github_project": "pretty-traceback",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pretty-traceback"
}
        
Elapsed time: 0.11656s