beautiful-traceback 0.1.0__tar.gz → 0.2.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: beautiful-traceback
3
- Version: 0.1.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 Traceback
13
+ # Beautiful, Readable Python Stack Traces
14
14
 
15
- > **Note:** 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.
15
+ [![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.md)
16
+ [![Python Versions](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
16
17
 
17
18
  Human readable stacktraces for Python.
18
19
 
19
- [![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.md)
20
- [![Python Versions](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
20
+ ![Comparison of standard Python traceback vs Beautiful Traceback](comparison.webp)
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
- ![Comparison of standard Python traceback vs Beautiful Traceback](comparison.webp)
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
- Add this function to your `.zshrc` or `.bashrc`:
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 - see [LICENSE.md](LICENSE.md) for details.
274
+ [MIT License](LICENSE.md)
@@ -1,11 +1,14 @@
1
- # Beautiful Traceback
1
+ # Beautiful, Readable Python Stack Traces
2
2
 
3
- > **Note:** 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.
3
+ [![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.md)
4
+ [![Python Versions](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
4
5
 
5
6
  Human readable stacktraces for Python.
6
7
 
7
- [![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.md)
8
- [![Python Versions](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
8
+ ![Comparison of standard Python traceback vs Beautiful Traceback](comparison.webp)
9
+
10
+ > [!NOTE]
11
+ > 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.
9
12
 
10
13
  ## Quick Start
11
14
 
@@ -22,7 +25,6 @@ uv run examples/simple.py
22
25
 
23
26
  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.
24
27
 
25
- ![Comparison of standard Python traceback vs Beautiful Traceback](comparison.webp)
26
28
 
27
29
  ## Installation
28
30
 
@@ -190,7 +192,27 @@ This gives you full control over the log format while adding beautiful traceback
190
192
 
191
193
  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.
192
194
 
193
- Add this function to your `.zshrc` or `.bashrc`:
195
+ ### Using the CLI Command
196
+
197
+ The easiest way to inject beautiful-traceback into your current virtual environment:
198
+
199
+ ```bash
200
+ beautiful-traceback
201
+ ```
202
+
203
+ This command:
204
+ - Only works within virtual environments (for safety)
205
+ - Installs the `.pth` file into your current environment's site-packages
206
+ - Displays the installation path every time it runs
207
+
208
+ Output:
209
+ ```
210
+ Beautiful traceback injection installed: /path/to/.venv/lib/python3.11/site-packages/beautiful_traceback_injection.pth
211
+ ```
212
+
213
+ ### Using a Shell Function (Alternative)
214
+
215
+ Alternatively, add this function to your `.zshrc` or `.bashrc`:
194
216
 
195
217
  ```bash
196
218
  # Create a file to automatically import beautiful-traceback on startup
@@ -204,7 +226,7 @@ python-inject-beautiful-traceback() {
204
226
  def run_startup_script():
205
227
  try:
206
228
  import beautiful_traceback
207
- beautiful_traceback.install()
229
+ beautiful_traceback.install(only_tty=False)
208
230
  except ImportError:
209
231
  pass
210
232
 
@@ -237,4 +259,4 @@ Beautiful Traceback is heavily inspired by the backtrace module by [nir0s](https
237
259
 
238
260
  ## License
239
261
 
240
- MIT License - see [LICENSE.md](LICENSE.md) for details.
262
+ [MIT License](LICENSE.md)
@@ -5,7 +5,7 @@ from .formatting import LoggingFormatterMixin
5
5
 
6
6
  from ._extension import load_ipython_extension # noqa: F401
7
7
 
8
- __version__ = "0.1.0"
8
+ __version__ = "0.2.0"
9
9
 
10
10
 
11
11
  # retain typo for backward compatibility
@@ -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
  [project]
2
2
  name = "beautiful-traceback"
3
- version = "0.1.0"
3
+ version = "0.2.0"
4
4
  description = "Beautiful, readable Python tracebacks with colors and formatting"
5
5
  keywords = ["traceback", "error", "debugging", "formatting"]
6
6
  readme = "README.md"
@@ -9,6 +9,9 @@ dependencies = ["colorama>=0.4.6"]
9
9
  authors = [{ name = "Michael Bianco", email = "mike@mikebian.co" }]
10
10
  urls = { "Repository" = "https://github.com/iloveitaly/beautiful-traceback" }
11
11
 
12
+ [project.scripts]
13
+ beautiful-traceback = "beautiful_traceback.cli:main"
14
+
12
15
  [build-system]
13
16
  requires = ["uv_build>=0.8.11,<0.9.0"]
14
17
  build-backend = "uv_build"
@@ -18,9 +21,16 @@ build-backend = "uv_build"
18
21
  module-root = ""
19
22
 
20
23
  [dependency-groups]
21
- dev = ["pytest>=8.3.3"]
24
+ dev = [
25
+ "pytest>=8.3.3",
26
+ "ruff>=0.8.0",
27
+ "pyright>=1.1.380",
28
+ ]
22
29
 
23
30
  [project.entry-points.pytest11]
24
31
  beautiful_traceback = "beautiful_traceback.pytest_plugin"
25
32
 
33
+ [tool.pyright]
34
+ exclude = ["examples/", ".venv"]
35
+
26
36