Package: pretty-traceback
Pretty TracebackHuman readable stacktraces for Python.Project/Repo:Code Quality/CI:OverviewPretty 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 😍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.UsageAdd the following to your__main__.pyor the equivalent module which is your entry point.try:importpretty_tracebackpretty_traceback.install()exceptImportError:pass# no need to fail because of missing dev dependencyPlease do not add this code e.g. to your__init__.pyor 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 thepretty_tracebackin code that others might import, consider using theenvvarargument, which will cause the install function to effectively be a noop unless you setENABLE_PRETTY_TRACEBACK=1.try:importpretty_tracebackpretty_traceback.install(envvar='ENABLE_PRETTY_TRACEBACK')exceptImportError:pass# no need to fail because of missing dev dependencyNote, that the hook is only installed if the existing hook is the default. Any existing hooks that were installed before the call ofpretty_traceback.installwill be left in place.LoggingFormatterAlogging.Formattersubclass is also available (e.g. for integration withflask).importosfromflask.loggingimportdefault_handlertry:ifos.getenv('FLASK_DEBUG')=="1":importpretty_tracebackdefault_handler.setFormatter(pretty_traceback.LoggingFormatter())exceptImportError:pass# no need to fail because of missing dev dependencyMore ExamplesAlternativesPretty Traceback is heavily inspired by the backtrace module bynir0sbut there are many others (sorted by github stars):https://github.com/qix-/better-exceptionshttps://github.com/cknd/stackprinterhttps://github.com/onelivesleft/PrettyErrorshttps://github.com/skorokithakis/tbvaccinehttps://github.com/aroberge/friendly-tracebackhttps://github.com/HallerPatrick/froschhttps://github.com/nir0s/backtracehttps://github.com/staticshock/colored-traceback.pyhttps://github.com/chillaranand/ptbhttps://github.com/laurb9/rich-tracebackhttps://github.com/willmcgugan/rich#tracebacksContributorsNamerolesinceuntilManuel Barkhau (mbarkhau@gmail.com)author/maintainer2020-08-Changelog forhttps://github.com/mbarkhau/pretty-traceback2023.1020Fix: Prevent errors in non-tty environmentsgh#82023.1019Update: Append lineno to filename so it can be parsed by editors/IDEs.gh#82022.1018Add final newline to output. Seegh#32021.1017Fix highlight in wide mode2020.1016Shorten tracebacks forRecursionError2020.1012Improve alias selection2020.1011Fix github #1: Invalid path handling for./script.py2020.1010Fix gitlab #5: Only show aliases that were actually used.Fix gitlab #5: Better alignment on narrow terminals.2020.1009Fix gitlab #3: Corner case where exception hasNoneas context.Fix gitlab #2: Improve formatting when line overflows.2020.1008Addpretty_traceback.LoggingFormatter2020.1006Add wide mode.2020.1005Update formatting to work better with recursive calls.Add tests2020.1001Initial release