Automatic installation of Rich's traceback handler
Project description
rich-tracebacks
rich-tracebacks automates the installation of Rich's traceback handler in Python programs. Compared to Rich's own sanctioned method of automatically installing its traceback handler, rich-tracebacks is markedly simpler and agnostic to your virtual environment.
Installation
pip install rich-tracebacks
Usage
Enabling
Set the RICH_TRACEBACKS
environment variable. The value of the variable doesn't matter, but we'll use 1
as an
example.
export RICH_TRACEBACKS=1
That's it. Rich's traceback handler will be automatically installed each time you run your program.
Disabling
Unset the RICH_TRACEBACKS
environment variable.
unset RICH_TRACEBACKS
Configuration
You can configure the traceback handler with
its supported options
by creating an rt_config.py
file at your project's root. The file should contain a dictionary named config
that maps option names to their intended values. For example:
# rt_config.py
config = {
"show_locals": True,
"width": 120,
"theme": "monokai",
...
}
Options that are not defined in rt_config.py
will fall back to their default values. If rt_config.py
does not exist, all options will fall back to their default values.
A note on the suppress
option
Rich's traceback handler supports a suppress
option to which you can pass an iterable of modules and paths to be
excluded from tracebacks. To suppress a module, you would normally need to import the module and then pass the
module object to the suppress
option. For example:
import loctocat
from rich.traceback import install
install(suppress=[loctocat])
With rich-tracebacks, you also have the option of simply passing the module's name as a string. For example:
# rt_config.py
config = {
"suppress": ["loctocat"],
...
}
rich-tracebacks will do the work of importing the module for you and passing the module object to Rich. Names it can't import will be passed to Rich as literal strings, which will in turn treat them as paths.
FAQ
Q: I use PyCharm and rich-tracebacks doesn't seem to be working if my program calls sys.excepthook
while I'm using the debugger, please help.
A: Congratulations on encountering this ridiculously niche isssue. Setting the RICH_TRACEBACKS_PYCHARM
environment
variable in the relevant run configuration will apply a very much experimental fix for this issue. If it doesn't work,
open an issue and I will try to help you as best I can.
License
rich-tracebacks is licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file rich_tracebacks-1.2.1.tar.gz
.
File metadata
- Download URL: rich_tracebacks-1.2.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.11.1 Linux/5.15.0-1024-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0613d0510254d27f11c5e8148388118e001f075e77b932ccdfc8967e2e69186b |
|
MD5 | 253e08f526ceca0042d535f5ee2775b4 |
|
BLAKE2b-256 | 3382fe355aa934083bdd84b6f942904359f2a55d01a498e7f2004e4044fdc4f4 |
File details
Details for the file rich_tracebacks-1.2.1-py3-none-any.whl
.
File metadata
- Download URL: rich_tracebacks-1.2.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.11.1 Linux/5.15.0-1024-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bba596aa753e045c6acd26f977b14f5e6ba2e3a86d928789393c361b72c6dac |
|
MD5 | c6ee149f0c5cb0c5b5011f3743856a39 |
|
BLAKE2b-256 | 7f287ef45111078f5875ab6081caf528e9c397814797961672d80a3d886af652 |