Enhanced warning output using Rich with icons and colors.
Project description
xwarning
xwarning is a Python module that enhances the default warnings system using Rich, providing beautiful, color-coded warning messages with icons.
Features
- Emoji-based warning indicators
- Rich-colored terminal output
- Drop-in replacement for
warnings.warn() - Built-in support for common warning types:
DeprecationWarningUserWarningFutureWarningRuntimeWarningSyntaxWarningImportWarningUnicodeWarning- Generic
Warning
- Optional file logging:
- If
log_fileis a string, logs to the specified filename - If
True, logs to system temp directory (Windows) or/var/log(Linux)
- If
- Fully configurable:
- Toggle icons on/off
- Toggle colors on/off
Installation
pip install xwarning
Usage
>> from xwarning import warn, warning, configure
# Simple usage you can use 'warn' similar as 'warning'
>> warn("This is deprecated warning !", type="deprecated")
>> warn("This is user warning !", type="user")
>> warn("This is future warning !", type="future")
>> warn("This is runtime warning !", type="runtime")
>> warn("This is syntax warning !", type="syntax")
>> warn("This is import warning !", type="import")
>> warn("This is unicode warning !", type="unicode")
>> warn("This is general warning !", type="general")
>> configure(show_icon=False, show_color=True)
# Logging to file
>> log_path = "warnings.log"
>> configure(log_file=log_path)
>> warn(f"This will go to the log file! with log file name '{log_path}'", type="user")
>> log_path = True
>> configure(log_file=log_path)
>> warn(f"This will go to the log file! with log file name as bool in temp or /var/log directory", type="user")
# Extra instance
>> printer1 = WarningPrinter()
>> printer1.configure(show_icon=False, log_file=True)
>> printer1.warn("this user warning with printer1", type="user")
>> printer2 = WarningPrinter()
>> printer2.configure(show_icon=True, show_color=False)
>> printer2.warn("this runtime warning with printer2", type="runtime")
>> printer1.filterwarnings("ignore", category=UserWarning)
>> printer1.warn("This not will appear as a user warning with `filterwarning`", type="user")
>> printer1.warn("This will appear as a runtime warning without `filterwarning`", type="runtime")
Example Output
🛑 DEPRECATED: This is deprecated
⚠️ USER: This is a user warning!
License
MIT License. See LICENSE for details.
author
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
xwarning-0.14.tar.gz
(6.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xwarning-0.14.tar.gz.
File metadata
- Download URL: xwarning-0.14.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a8ca492bb476dd36d8db5ecebd2504178eb0b5520581b8d5fa4f57dca24d8de
|
|
| MD5 |
ccb6bc0d6c3a078b0513267586bda2bb
|
|
| BLAKE2b-256 |
23d6b8fdc603946bb4408577808a7c4ff6497ea1e10e9a48221625a084095ee6
|
File details
Details for the file xwarning-0.14-py3-none-any.whl.
File metadata
- Download URL: xwarning-0.14-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
325426390d4884bb5d369a6c881418ff25554d2450107d14797e8ea1e4587121
|
|
| MD5 |
0990651728e7fc202b3567343e506ad7
|
|
| BLAKE2b-256 |
faf04711610650db37f0cdacee595af185aef5eb40c2c002cc4455820b237fdc
|