beautiful-traceback 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- beautiful_traceback/__init__.py +1 -1
- beautiful_traceback/cli.py +73 -0
- beautiful_traceback/formatting.py +2 -2
- {beautiful_traceback-0.1.0.dist-info → beautiful_traceback-0.2.0.dist-info}/METADATA +31 -9
- beautiful_traceback-0.2.0.dist-info/RECORD +12 -0
- beautiful_traceback-0.2.0.dist-info/entry_points.txt +6 -0
- beautiful_traceback-0.1.0.dist-info/RECORD +0 -11
- beautiful_traceback-0.1.0.dist-info/entry_points.txt +0 -3
- {beautiful_traceback-0.1.0.dist-info → beautiful_traceback-0.2.0.dist-info}/WHEEL +0 -0
beautiful_traceback/__init__.py
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""CLI commands for beautiful-traceback installation and configuration."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def inject_pth() -> None:
|
|
8
|
+
"""
|
|
9
|
+
Inject beautiful-traceback into the current Python environment via .pth file.
|
|
10
|
+
|
|
11
|
+
Creates a .pth file in site-packages that automatically imports beautiful_traceback
|
|
12
|
+
on interpreter startup. Only works within virtual environments.
|
|
13
|
+
"""
|
|
14
|
+
if not _is_in_venv():
|
|
15
|
+
print("Error: Not running in a virtual environment", file=sys.stderr)
|
|
16
|
+
print(
|
|
17
|
+
"Beautiful traceback pth injection only works in virtual environments",
|
|
18
|
+
file=sys.stderr,
|
|
19
|
+
)
|
|
20
|
+
sys.exit(1)
|
|
21
|
+
|
|
22
|
+
site_packages = _get_site_packages()
|
|
23
|
+
pth_file = site_packages / "beautiful_traceback_injection.pth"
|
|
24
|
+
py_file = site_packages / "_beautiful_traceback_injection.py"
|
|
25
|
+
|
|
26
|
+
_create_injection_files(py_file, pth_file)
|
|
27
|
+
|
|
28
|
+
print(f"Beautiful traceback injection installed: {pth_file}")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _is_in_venv() -> bool:
|
|
32
|
+
"""Check if running in a virtual environment."""
|
|
33
|
+
return hasattr(sys, "real_prefix") or (
|
|
34
|
+
hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _get_site_packages() -> Path:
|
|
39
|
+
"""Get the site-packages directory for the current Python environment."""
|
|
40
|
+
import site
|
|
41
|
+
|
|
42
|
+
site_packages_list = site.getsitepackages()
|
|
43
|
+
|
|
44
|
+
if not site_packages_list:
|
|
45
|
+
print("Error: Could not find site-packages directory", file=sys.stderr)
|
|
46
|
+
sys.exit(1)
|
|
47
|
+
|
|
48
|
+
return Path(site_packages_list[0])
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _create_injection_files(py_file: Path, pth_file: Path) -> None:
|
|
52
|
+
"""Create the Python injection file and .pth file."""
|
|
53
|
+
py_content = """def run_startup_script():
|
|
54
|
+
try:
|
|
55
|
+
import beautiful_traceback
|
|
56
|
+
beautiful_traceback.install(only_tty=False)
|
|
57
|
+
except ImportError:
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
run_startup_script()
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
py_file.write_text(py_content)
|
|
64
|
+
pth_file.write_text("import _beautiful_traceback_injection\n")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def main() -> None:
|
|
68
|
+
"""Main CLI entrypoint."""
|
|
69
|
+
inject_pth()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if __name__ == "__main__":
|
|
73
|
+
main()
|
|
@@ -460,7 +460,7 @@ def exc_to_traceback_str(
|
|
|
460
460
|
|
|
461
461
|
cur_exc_value: BaseException = exc_value
|
|
462
462
|
cur_traceback: types.TracebackType = traceback
|
|
463
|
-
|
|
463
|
+
|
|
464
464
|
# Track seen exceptions to prevent infinite loops from circular references
|
|
465
465
|
seen_exceptions: typ.Set[int] = set()
|
|
466
466
|
|
|
@@ -471,7 +471,7 @@ def exc_to_traceback_str(
|
|
|
471
471
|
# Circular reference detected, break the loop
|
|
472
472
|
break
|
|
473
473
|
seen_exceptions.add(exc_id)
|
|
474
|
-
|
|
474
|
+
|
|
475
475
|
next_cause = getattr(cur_exc_value, "__cause__", None)
|
|
476
476
|
next_context = getattr(cur_exc_value, "__context__", None)
|
|
477
477
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: beautiful-traceback
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Beautiful, readable Python tracebacks with colors and formatting
|
|
5
5
|
Keywords: traceback,error,debugging,formatting
|
|
6
6
|
Author: Michael Bianco
|
|
@@ -10,14 +10,17 @@ Requires-Python: >=3.9
|
|
|
10
10
|
Project-URL: Repository, https://github.com/iloveitaly/beautiful-traceback
|
|
11
11
|
Description-Content-Type: text/markdown
|
|
12
12
|
|
|
13
|
-
# Beautiful
|
|
13
|
+
# Beautiful, Readable Python Stack Traces
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
[](LICENSE.md)
|
|
16
|
+
[](https://www.python.org/downloads/)
|
|
16
17
|
|
|
17
18
|
Human readable stacktraces for Python.
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+

|
|
21
|
+
|
|
22
|
+
> [!NOTE]
|
|
23
|
+
> This is a fork of the [pretty-traceback](https://github.com/mbarkhau/pretty-traceback) repo with simplified development and improvements for better integration with FastAPI, [structlog](https://github.com/iloveitaly/structlog-config), IPython, pytest, and more. This project is used in [python-starter-template](https://github.com/iloveitaly/python-starter-template) to provide better debugging experience in production environments.
|
|
21
24
|
|
|
22
25
|
## Quick Start
|
|
23
26
|
|
|
@@ -34,7 +37,6 @@ uv run examples/simple.py
|
|
|
34
37
|
|
|
35
38
|
Beautiful 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.
|
|
36
39
|
|
|
37
|
-

|
|
38
40
|
|
|
39
41
|
## Installation
|
|
40
42
|
|
|
@@ -202,7 +204,27 @@ This gives you full control over the log format while adding beautiful traceback
|
|
|
202
204
|
|
|
203
205
|
You can enable beautiful-traceback across all Python projects without modifying any source code by using a `.pth` file. Python automatically executes import statements in `.pth` files during interpreter startup, making this perfect for development environments.
|
|
204
206
|
|
|
205
|
-
|
|
207
|
+
### Using the CLI Command
|
|
208
|
+
|
|
209
|
+
The easiest way to inject beautiful-traceback into your current virtual environment:
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
beautiful-traceback
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
This command:
|
|
216
|
+
- Only works within virtual environments (for safety)
|
|
217
|
+
- Installs the `.pth` file into your current environment's site-packages
|
|
218
|
+
- Displays the installation path every time it runs
|
|
219
|
+
|
|
220
|
+
Output:
|
|
221
|
+
```
|
|
222
|
+
Beautiful traceback injection installed: /path/to/.venv/lib/python3.11/site-packages/beautiful_traceback_injection.pth
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Using a Shell Function (Alternative)
|
|
226
|
+
|
|
227
|
+
Alternatively, add this function to your `.zshrc` or `.bashrc`:
|
|
206
228
|
|
|
207
229
|
```bash
|
|
208
230
|
# Create a file to automatically import beautiful-traceback on startup
|
|
@@ -216,7 +238,7 @@ python-inject-beautiful-traceback() {
|
|
|
216
238
|
def run_startup_script():
|
|
217
239
|
try:
|
|
218
240
|
import beautiful_traceback
|
|
219
|
-
beautiful_traceback.install()
|
|
241
|
+
beautiful_traceback.install(only_tty=False)
|
|
220
242
|
except ImportError:
|
|
221
243
|
pass
|
|
222
244
|
|
|
@@ -249,4 +271,4 @@ Beautiful Traceback is heavily inspired by the backtrace module by [nir0s](https
|
|
|
249
271
|
|
|
250
272
|
## License
|
|
251
273
|
|
|
252
|
-
MIT License
|
|
274
|
+
[MIT License](LICENSE.md)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
beautiful_traceback/__init__.py,sha256=onuaATNEzmniuSLwhI7ec-3enL8XaQ2wmXS5o2l4qxc,462
|
|
2
|
+
beautiful_traceback/_extension.py,sha256=klyo3XL4q3-Wdy4Lt6JYdh-Cfh_SkRCI7jCcQCwfWTM,311
|
|
3
|
+
beautiful_traceback/cli.py,sha256=rcoEkeBQvipWHhVTPgd5yRfNNzSDmxNaReP8K2o9eYM,2030
|
|
4
|
+
beautiful_traceback/common.py,sha256=IIg46wUk5e0syCrkI2HfLPwv8zi8mQ5AIPgb1998lAY,585
|
|
5
|
+
beautiful_traceback/formatting.py,sha256=nN1wv2scW0tJw2VJyisqlaaT-MM_mOuo2sY5w_cdoTM,15093
|
|
6
|
+
beautiful_traceback/hook.py,sha256=6vYpqA-mD4G32HkX5WSyCMzkvMwB4RXP6wbVEIU6oaY,2078
|
|
7
|
+
beautiful_traceback/parsing.py,sha256=lVqOty6X9MqTfo-lTIQjI_zVxUqRhYEVjyGhkW8wps8,2954
|
|
8
|
+
beautiful_traceback/pytest_plugin.py,sha256=vdRgvycWeG9wwh9tK4921ugW9aHx0Zib1Or7mU9Khw0,2315
|
|
9
|
+
beautiful_traceback-0.2.0.dist-info/WHEEL,sha256=Pi5uDq5Fdo_Rr-HD5h9BiPn9Et29Y9Sh8NhcJNnFU1c,79
|
|
10
|
+
beautiful_traceback-0.2.0.dist-info/entry_points.txt,sha256=EXsu7N89wqDpZPEwLHgYVncZJ3y-lbCFZC5fKBZZDac,138
|
|
11
|
+
beautiful_traceback-0.2.0.dist-info/METADATA,sha256=UNpYywFmNYvVgjrYOj8DD-6hkIcVX58XVnTrRCbvrNk,8558
|
|
12
|
+
beautiful_traceback-0.2.0.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
beautiful_traceback/__init__.py,sha256=XW0PVUTOPa6qFDhvE8oPWikOcL8Xbfgv_BLuFdkVhCI,462
|
|
2
|
-
beautiful_traceback/_extension.py,sha256=klyo3XL4q3-Wdy4Lt6JYdh-Cfh_SkRCI7jCcQCwfWTM,311
|
|
3
|
-
beautiful_traceback/common.py,sha256=IIg46wUk5e0syCrkI2HfLPwv8zi8mQ5AIPgb1998lAY,585
|
|
4
|
-
beautiful_traceback/formatting.py,sha256=FilxU_holFyBvVKd2VHTtqQ4sRfUlfxSIYwHLtadR3M,15105
|
|
5
|
-
beautiful_traceback/hook.py,sha256=6vYpqA-mD4G32HkX5WSyCMzkvMwB4RXP6wbVEIU6oaY,2078
|
|
6
|
-
beautiful_traceback/parsing.py,sha256=lVqOty6X9MqTfo-lTIQjI_zVxUqRhYEVjyGhkW8wps8,2954
|
|
7
|
-
beautiful_traceback/pytest_plugin.py,sha256=vdRgvycWeG9wwh9tK4921ugW9aHx0Zib1Or7mU9Khw0,2315
|
|
8
|
-
beautiful_traceback-0.1.0.dist-info/WHEEL,sha256=Pi5uDq5Fdo_Rr-HD5h9BiPn9Et29Y9Sh8NhcJNnFU1c,79
|
|
9
|
-
beautiful_traceback-0.1.0.dist-info/entry_points.txt,sha256=m99Hs6ia_rvyRu-ruwKwVCjob50f-wvLVtztWyi47a8,68
|
|
10
|
-
beautiful_traceback-0.1.0.dist-info/METADATA,sha256=w0nVy_HVr836OK_I1jY1fosVLAXM_3MOgm5992CvmQc,8020
|
|
11
|
-
beautiful_traceback-0.1.0.dist-info/RECORD,,
|
|
File without changes
|