debug-dojo 0.3.0__tar.gz → 0.3.1__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.
- {debug_dojo-0.3.0 → debug_dojo-0.3.1}/HISTORY.md +14 -2
- {debug_dojo-0.3.0 → debug_dojo-0.3.1}/PKG-INFO +42 -23
- {debug_dojo-0.3.0 → debug_dojo-0.3.1}/README.md +22 -19
- debug_dojo-0.3.1/dojo.toml +7 -0
- {debug_dojo-0.3.0 → debug_dojo-0.3.1}/pyproject.toml +20 -4
- debug_dojo-0.3.1/ruff.toml +19 -0
- debug_dojo-0.3.1/src/debug_dojo/__init__.py +23 -0
- {debug_dojo-0.3.0 → debug_dojo-0.3.1}/src/debug_dojo/__main__.py +2 -2
- debug_dojo-0.3.1/src/debug_dojo/_cli.py +101 -0
- debug_dojo-0.3.0/src/debug_dojo/compareres.py → debug_dojo-0.3.1/src/debug_dojo/_compareres.py +3 -1
- debug_dojo-0.3.1/src/debug_dojo/_config.py +117 -0
- debug_dojo-0.3.1/src/debug_dojo/_installers.py +138 -0
- debug_dojo-0.3.1/src/debug_dojo/install.py +7 -0
- debug_dojo-0.3.1/uv.lock +2083 -0
- debug_dojo-0.3.0/ruff.toml +0 -20
- debug_dojo-0.3.0/src/debug_dojo/__init__.py +0 -21
- debug_dojo-0.3.0/src/debug_dojo/_cli.py +0 -76
- debug_dojo-0.3.0/src/debug_dojo/all.py +0 -5
- debug_dojo-0.3.0/src/debug_dojo/installers.py +0 -81
- debug_dojo-0.3.0/uv.lock +0 -247
- {debug_dojo-0.3.0 → debug_dojo-0.3.1}/.gitignore +0 -0
- {debug_dojo-0.3.0 → debug_dojo-0.3.1}/.python-version +0 -0
- {debug_dojo-0.3.0 → debug_dojo-0.3.1}/LICENCE +0 -0
- {debug_dojo-0.3.0 → debug_dojo-0.3.1}/examples/test_target.py +0 -0
- {debug_dojo-0.3.0 → debug_dojo-0.3.1}/logo/logo_black.png +0 -0
- {debug_dojo-0.3.0 → debug_dojo-0.3.1}/logo/logo_white.png +0 -0
- {debug_dojo-0.3.0 → debug_dojo-0.3.1}/src/debug_dojo/py.typed +0 -0
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## v0.3.0 (2025-07-20)
|
|
2
|
+
|
|
3
|
+
*release tag*: [v0.3.0]
|
|
4
|
+
|
|
5
|
+
### What's Changed
|
|
6
|
+
|
|
7
|
+
- New logo for the project.
|
|
8
|
+
- Typer used for CLI implementation.
|
|
9
|
+
- Dojo is configured via `dojo.toml` or `pyproject.toml`.
|
|
10
|
+
|
|
11
|
+
#### Fixes
|
|
12
|
+
|
|
13
|
+
- Fixed documentation and history.
|
|
14
|
+
|
|
1
15
|
## v0.2.0 (2025-07-20)
|
|
2
16
|
|
|
3
17
|
*release tag*: [v0.2.0]
|
|
@@ -21,5 +35,3 @@
|
|
|
21
35
|
|
|
22
36
|
- Initial module to install debugging tools.
|
|
23
37
|
- Debug mode utilities for PuDB, rich tracebacks, and object inspection.
|
|
24
|
-
|
|
25
|
-
#### Fixes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: debug-dojo
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Debbugging dojo for Python developers
|
|
5
5
|
Project-URL: Homepage, https://github.com/bwrob/debug-dojo
|
|
6
6
|
Project-URL: Documentation, https://github.com/bwrob/debug-dojo/blob/main/README.md
|
|
@@ -20,8 +20,12 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
20
20
|
Classifier: Topic :: Software Development :: Debuggers
|
|
21
21
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
22
|
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: debugpy>=1.8.0
|
|
24
|
+
Requires-Dist: ipdb>=0.13.0
|
|
23
25
|
Requires-Dist: pudb>=2020.1
|
|
24
|
-
Requires-Dist:
|
|
26
|
+
Requires-Dist: pydantic>=2.11.7
|
|
27
|
+
Requires-Dist: rich>=12.0.0
|
|
28
|
+
Requires-Dist: tomlkit>=0.13.3
|
|
25
29
|
Requires-Dist: typer>=0.15.0
|
|
26
30
|
Description-Content-Type: text/markdown
|
|
27
31
|
|
|
@@ -36,13 +40,13 @@ Description-Content-Type: text/markdown
|
|
|
36
40
|
[](https://pypi.org/project/debug-dojo)
|
|
37
41
|
[](https://pypi.org/pypi/debug-dojo/)
|
|
38
42
|
|
|
39
|
-
**debug-dojo** is a Python package providing utilities for enhanced debugging and inspection in the terminal. It leverages [`rich`](https://github.com/Textualize/rich) for beautiful output and offers helpers for side-by-side object comparison, improved tracebacks from `rich`, and easy integration with
|
|
43
|
+
**debug-dojo** is a Python package providing utilities for enhanced debugging and inspection in the terminal. It leverages [`rich`](https://github.com/Textualize/rich) for beautiful output and offers helpers for side-by-side object comparison, improved tracebacks from `rich`, and easy integration with different debuggers. All tools can be installed at once or individually, allowing for flexible debugging setups.
|
|
40
44
|
|
|
41
45
|
## Features
|
|
42
46
|
|
|
43
47
|
- **Convenient CLI** Quickly run your code with debugging tools enabled.
|
|
44
48
|
- **Simple API:** Install all tools or only what you need.
|
|
45
|
-
- **
|
|
49
|
+
- **Debugger integration:** Quickly enable Debugpy, PuDB, PDB, or IPDB as your default debugger.
|
|
46
50
|
- **Rich tracebacks:** Get readable, colorized tracebacks for easier debugging.
|
|
47
51
|
- **Side-by-side object inspection:** Visually compare Python objects, their attributes, and methods in the terminal.
|
|
48
52
|
|
|
@@ -56,12 +60,21 @@ Run your Python script with debugging tools enabled using the `debug-dojo` comma
|
|
|
56
60
|
dojo my_script.py
|
|
57
61
|
```
|
|
58
62
|
|
|
59
|
-
|
|
63
|
+
You can optionally set configuration file and verbose mode:
|
|
64
|
+
|
|
65
|
+
```console
|
|
66
|
+
dojo --config dojo.toml --verbose my_script.py
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### From the code
|
|
60
70
|
|
|
61
71
|
In the `PuDB` style, you can install all debugging tools and enter the debugging mode with a single command:
|
|
62
72
|
|
|
63
73
|
```python
|
|
64
|
-
import debug_dojo.
|
|
74
|
+
import debug_dojo.install; b()
|
|
75
|
+
|
|
76
|
+
object_1 = {"foo": 1, "bar": 2}
|
|
77
|
+
object_2 = [1, 2, 3]
|
|
65
78
|
|
|
66
79
|
p(object_1) # Pretty print an object with Rich
|
|
67
80
|
i(object_1) # Inspect an object
|
|
@@ -75,27 +88,21 @@ Where:
|
|
|
75
88
|
- `i(object_1)` to inspect an object using Rich.
|
|
76
89
|
- `c(object_1, object_2)` to compare two objects side-by-side.
|
|
77
90
|
|
|
78
|
-
|
|
91
|
+
## Configuration
|
|
79
92
|
|
|
80
|
-
|
|
81
|
-
from debug_dojo import install_inspect, use_pudb, use_rich_traceback
|
|
93
|
+
You can configure the debugging tools using a `dojo.toml` or `pyproject.toml` file. The configuration allows you to specify which debugger to use, enable or disable features, and set other options.
|
|
82
94
|
|
|
83
|
-
|
|
84
|
-
use_pudb() # Set up PuDB as the debugger
|
|
85
|
-
use_rich_traceback() # Enable Rich tracebacks
|
|
86
|
-
```
|
|
95
|
+
**Example `dojo.toml`:**
|
|
87
96
|
|
|
88
|
-
|
|
97
|
+
```toml
|
|
98
|
+
debugger = "ipdb"
|
|
89
99
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
b = [1, 2, 3]
|
|
95
|
-
inspect_objects_side_by_side(a, b)
|
|
100
|
+
[features]
|
|
101
|
+
rich_inspect = true
|
|
102
|
+
rich_print = true
|
|
103
|
+
comparer = false
|
|
96
104
|
```
|
|
97
105
|
|
|
98
|
-
|
|
99
106
|
## Installation
|
|
100
107
|
|
|
101
108
|
The package is available on PyPI and can be installed using standard Python package management tools.
|
|
@@ -128,6 +135,20 @@ basedpyright src/debug_dojo
|
|
|
128
135
|
|
|
129
136
|
## Changelog
|
|
130
137
|
|
|
138
|
+
## v0.3.0 (2025-07-20)
|
|
139
|
+
|
|
140
|
+
*release tag*: [v0.3.0]
|
|
141
|
+
|
|
142
|
+
### What's Changed
|
|
143
|
+
|
|
144
|
+
- New logo for the project.
|
|
145
|
+
- Typer used for CLI implementation.
|
|
146
|
+
- Dojo is configured via `dojo.toml` or `pyproject.toml`.
|
|
147
|
+
|
|
148
|
+
#### Fixes
|
|
149
|
+
|
|
150
|
+
- Fixed documentation and history.
|
|
151
|
+
|
|
131
152
|
## v0.2.0 (2025-07-20)
|
|
132
153
|
|
|
133
154
|
*release tag*: [v0.2.0]
|
|
@@ -151,5 +172,3 @@ basedpyright src/debug_dojo
|
|
|
151
172
|
|
|
152
173
|
- Initial module to install debugging tools.
|
|
153
174
|
- Debug mode utilities for PuDB, rich tracebacks, and object inspection.
|
|
154
|
-
|
|
155
|
-
#### Fixes
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
[](https://pypi.org/project/debug-dojo)
|
|
10
10
|
[](https://pypi.org/pypi/debug-dojo/)
|
|
11
11
|
|
|
12
|
-
**debug-dojo** is a Python package providing utilities for enhanced debugging and inspection in the terminal. It leverages [`rich`](https://github.com/Textualize/rich) for beautiful output and offers helpers for side-by-side object comparison, improved tracebacks from `rich`, and easy integration with
|
|
12
|
+
**debug-dojo** is a Python package providing utilities for enhanced debugging and inspection in the terminal. It leverages [`rich`](https://github.com/Textualize/rich) for beautiful output and offers helpers for side-by-side object comparison, improved tracebacks from `rich`, and easy integration with different debuggers. All tools can be installed at once or individually, allowing for flexible debugging setups.
|
|
13
13
|
|
|
14
14
|
## Features
|
|
15
15
|
|
|
16
16
|
- **Convenient CLI** Quickly run your code with debugging tools enabled.
|
|
17
17
|
- **Simple API:** Install all tools or only what you need.
|
|
18
|
-
- **
|
|
18
|
+
- **Debugger integration:** Quickly enable Debugpy, PuDB, PDB, or IPDB as your default debugger.
|
|
19
19
|
- **Rich tracebacks:** Get readable, colorized tracebacks for easier debugging.
|
|
20
20
|
- **Side-by-side object inspection:** Visually compare Python objects, their attributes, and methods in the terminal.
|
|
21
21
|
|
|
@@ -29,12 +29,21 @@ Run your Python script with debugging tools enabled using the `debug-dojo` comma
|
|
|
29
29
|
dojo my_script.py
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
You can optionally set configuration file and verbose mode:
|
|
33
|
+
|
|
34
|
+
```console
|
|
35
|
+
dojo --config dojo.toml --verbose my_script.py
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### From the code
|
|
33
39
|
|
|
34
40
|
In the `PuDB` style, you can install all debugging tools and enter the debugging mode with a single command:
|
|
35
41
|
|
|
36
42
|
```python
|
|
37
|
-
import debug_dojo.
|
|
43
|
+
import debug_dojo.install; b()
|
|
44
|
+
|
|
45
|
+
object_1 = {"foo": 1, "bar": 2}
|
|
46
|
+
object_2 = [1, 2, 3]
|
|
38
47
|
|
|
39
48
|
p(object_1) # Pretty print an object with Rich
|
|
40
49
|
i(object_1) # Inspect an object
|
|
@@ -48,27 +57,21 @@ Where:
|
|
|
48
57
|
- `i(object_1)` to inspect an object using Rich.
|
|
49
58
|
- `c(object_1, object_2)` to compare two objects side-by-side.
|
|
50
59
|
|
|
51
|
-
|
|
60
|
+
## Configuration
|
|
52
61
|
|
|
53
|
-
|
|
54
|
-
from debug_dojo import install_inspect, use_pudb, use_rich_traceback
|
|
62
|
+
You can configure the debugging tools using a `dojo.toml` or `pyproject.toml` file. The configuration allows you to specify which debugger to use, enable or disable features, and set other options.
|
|
55
63
|
|
|
56
|
-
|
|
57
|
-
use_pudb() # Set up PuDB as the debugger
|
|
58
|
-
use_rich_traceback() # Enable Rich tracebacks
|
|
59
|
-
```
|
|
64
|
+
**Example `dojo.toml`:**
|
|
60
65
|
|
|
61
|
-
|
|
66
|
+
```toml
|
|
67
|
+
debugger = "ipdb"
|
|
62
68
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
b = [1, 2, 3]
|
|
68
|
-
inspect_objects_side_by_side(a, b)
|
|
69
|
+
[features]
|
|
70
|
+
rich_inspect = true
|
|
71
|
+
rich_print = true
|
|
72
|
+
comparer = false
|
|
69
73
|
```
|
|
70
74
|
|
|
71
|
-
|
|
72
75
|
## Installation
|
|
73
76
|
|
|
74
77
|
The package is available on PyPI and can be installed using standard Python package management tools.
|
|
@@ -6,10 +6,14 @@
|
|
|
6
6
|
]
|
|
7
7
|
requires-python = ">=3.10"
|
|
8
8
|
dependencies = [
|
|
9
|
+
"debugpy>=1.8.0",
|
|
10
|
+
"ipdb>=0.13.0",
|
|
9
11
|
"pudb>=2020.1",
|
|
10
|
-
"
|
|
12
|
+
"pydantic>=2.11.7",
|
|
13
|
+
"rich>=12.0.0",
|
|
14
|
+
"tomlkit>=0.13.3",
|
|
11
15
|
"typer>=0.15.0",
|
|
12
|
-
|
|
16
|
+
]
|
|
13
17
|
license = 'MIT'
|
|
14
18
|
license-files = ['LICENSE']
|
|
15
19
|
keywords = [
|
|
@@ -32,7 +36,7 @@
|
|
|
32
36
|
"Topic :: Software Development :: Debuggers",
|
|
33
37
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
34
38
|
]
|
|
35
|
-
|
|
39
|
+
version = "0.3.1"
|
|
36
40
|
dynamic = ['readme']
|
|
37
41
|
|
|
38
42
|
[project.urls]
|
|
@@ -47,7 +51,12 @@
|
|
|
47
51
|
"dojo" = "debug_dojo._cli:main"
|
|
48
52
|
|
|
49
53
|
[dependency-groups]
|
|
50
|
-
dev = [
|
|
54
|
+
dev = [
|
|
55
|
+
"basedpyright>=1.31.0",
|
|
56
|
+
"jupyter>=1.1.1",
|
|
57
|
+
"poethepoet>=0.36.0",
|
|
58
|
+
"ruff>=0.12.4",
|
|
59
|
+
]
|
|
51
60
|
|
|
52
61
|
[build-system]
|
|
53
62
|
requires = [
|
|
@@ -77,3 +86,10 @@
|
|
|
77
86
|
pythonVersion = "3.10"
|
|
78
87
|
strict = ["src/debug_dojo/*"]
|
|
79
88
|
ignore = ["examples"]
|
|
89
|
+
|
|
90
|
+
[tool.poe.tasks]
|
|
91
|
+
# Define your tasks here
|
|
92
|
+
lint = "ruff check --fix src"
|
|
93
|
+
format = "ruff format src"
|
|
94
|
+
type-check = "basedpyright"
|
|
95
|
+
code-quality = ["format", "lint", "type-check"]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
line-length = 88
|
|
2
|
+
target-version = "py310"
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
[lint]
|
|
6
|
+
select = ["ALL"]
|
|
7
|
+
ignore = ["COM", "D203", "D211", "D213"]
|
|
8
|
+
exclude = ["examples"]
|
|
9
|
+
|
|
10
|
+
[lint.per-file-ignores]
|
|
11
|
+
"src/debug_dojo/_installers.py" = [
|
|
12
|
+
"PLC0415",
|
|
13
|
+
"T100",
|
|
14
|
+
]
|
|
15
|
+
"examples/test_target.py" = ["F821"]
|
|
16
|
+
"examples/*" = ["INP001"]
|
|
17
|
+
|
|
18
|
+
[format]
|
|
19
|
+
docstring-code-format = true
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Debugging tools for Python.
|
|
2
|
+
|
|
3
|
+
This module provides functions to set up debugging tools like PuDB and Rich Traceback.
|
|
4
|
+
It checks for the availability of these tools and configures them accordingly.
|
|
5
|
+
|
|
6
|
+
Importing this module will install the debugging tools based on the configuration.
|
|
7
|
+
Example usage:
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
import debug_dojo.install
|
|
11
|
+
|
|
12
|
+
b()
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This will install the debugging tools and put debug breakpoint at this line.
|
|
16
|
+
|
|
17
|
+
Another way to use this module is to run the desired script or module with the
|
|
18
|
+
`dojo` command-line interface.
|
|
19
|
+
|
|
20
|
+
```console
|
|
21
|
+
$ dojo --verbose --config dojo.toml target_script.py --arg_1_for_script value1
|
|
22
|
+
```
|
|
23
|
+
"""
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Command-line interface for running Python scripts or modules with debugging tools."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import runpy
|
|
7
|
+
import sys
|
|
8
|
+
from bdb import BdbQuit
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Annotated
|
|
11
|
+
|
|
12
|
+
import typer
|
|
13
|
+
from pydantic import ValidationError
|
|
14
|
+
from rich import print as rich_print
|
|
15
|
+
|
|
16
|
+
from ._config import DebugDojoConfig, load_config
|
|
17
|
+
from ._installers import install_by_config
|
|
18
|
+
|
|
19
|
+
cli = typer.Typer(
|
|
20
|
+
name="debug_dojo",
|
|
21
|
+
help="Run a Python script or module with debugging tools installed.",
|
|
22
|
+
no_args_is_help=True,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def execute_with_debug(
|
|
27
|
+
target_name: str,
|
|
28
|
+
target_args: list[str],
|
|
29
|
+
*,
|
|
30
|
+
verbose: bool,
|
|
31
|
+
) -> None:
|
|
32
|
+
"""Execute a target script or module with installation of debugging tools."""
|
|
33
|
+
sys.argv = [target_name, *target_args]
|
|
34
|
+
|
|
35
|
+
if verbose:
|
|
36
|
+
rich_print(f"[blue]Installing debugging tools for {target_name}.[/blue]")
|
|
37
|
+
rich_print(f"[blue]Arguments for target: {target_args}[/blue]")
|
|
38
|
+
|
|
39
|
+
config = load_config()
|
|
40
|
+
install_by_config(config)
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
Path(target_name).exists()
|
|
44
|
+
or target_name.endswith(".py")
|
|
45
|
+
or os.sep in target_name
|
|
46
|
+
):
|
|
47
|
+
if not Path(target_name).exists():
|
|
48
|
+
sys.exit(1)
|
|
49
|
+
runner = runpy.run_path
|
|
50
|
+
else:
|
|
51
|
+
runner = runpy.run_module
|
|
52
|
+
|
|
53
|
+
_ = runner(target_name, run_name="__main__")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def display_config(config: DebugDojoConfig) -> None:
|
|
57
|
+
"""Display the configuration for the debug dojo."""
|
|
58
|
+
rich_print("[blue]Using debug-dojo configuration:[/blue]")
|
|
59
|
+
rich_print(config.model_dump_json(indent=4))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@cli.command(
|
|
63
|
+
help="Run a Python script or module with debugging tools installed.",
|
|
64
|
+
no_args_is_help=True,
|
|
65
|
+
context_settings={"allow_extra_args": True, "ignore_unknown_options": True},
|
|
66
|
+
)
|
|
67
|
+
def run_debug(
|
|
68
|
+
ctx: typer.Context,
|
|
69
|
+
target_name: Annotated[
|
|
70
|
+
str | None, typer.Argument(help="The target script or module to debug.")
|
|
71
|
+
] = None,
|
|
72
|
+
config_path: Annotated[
|
|
73
|
+
Path | None, typer.Option("--config", "-c", help="Show configuration")
|
|
74
|
+
] = None,
|
|
75
|
+
*,
|
|
76
|
+
verbose: Annotated[
|
|
77
|
+
bool,
|
|
78
|
+
typer.Option("--verbose", "-v", is_flag=True, help="Enable verbose output"),
|
|
79
|
+
] = False,
|
|
80
|
+
) -> None:
|
|
81
|
+
"""Run the command-line interface."""
|
|
82
|
+
try:
|
|
83
|
+
config = load_config(config_path, verbose=verbose)
|
|
84
|
+
except ValidationError as e:
|
|
85
|
+
rich_print(f"[red]Configuration error:\n{e}[/red]")
|
|
86
|
+
sys.exit(1)
|
|
87
|
+
|
|
88
|
+
if verbose:
|
|
89
|
+
display_config(config)
|
|
90
|
+
|
|
91
|
+
if target_name:
|
|
92
|
+
try:
|
|
93
|
+
execute_with_debug(target_name, ctx.args, verbose=verbose)
|
|
94
|
+
except BdbQuit:
|
|
95
|
+
rich_print("[red]Debugging session terminated by user.[/red]")
|
|
96
|
+
sys.exit(0)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def main() -> None:
|
|
100
|
+
"""Run the command-line interface."""
|
|
101
|
+
cli()
|
debug_dojo-0.3.0/src/debug_dojo/compareres.py → debug_dojo-0.3.1/src/debug_dojo/_compareres.py
RENAMED
|
@@ -4,6 +4,8 @@ This module provides functions to display attributes and methods of two objects
|
|
|
4
4
|
in a visually appealing, side-by-side format in the terminal.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
7
9
|
import contextlib
|
|
8
10
|
|
|
9
11
|
from rich.columns import Columns
|
|
@@ -48,7 +50,7 @@ def _get_object_methods(obj: object) -> list[str]:
|
|
|
48
50
|
for method_name in sorted(dir(obj)):
|
|
49
51
|
# Safely get attribute, returning None if it doesn't exist
|
|
50
52
|
attr = getattr(obj, method_name, None)
|
|
51
|
-
# Exclude private/protected methods (starting with '_') and non-
|
|
53
|
+
# Exclude private/protected methods (starting with '_') and non-callables.
|
|
52
54
|
if not method_name.startswith("_") and callable(attr):
|
|
53
55
|
methods.append(method_name)
|
|
54
56
|
return methods
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any, cast
|
|
6
|
+
|
|
7
|
+
import tomlkit
|
|
8
|
+
from pydantic import BaseModel, ConfigDict
|
|
9
|
+
from rich import print as rich_print
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DebuggerType(Enum):
|
|
13
|
+
"""Enum for different types of debuggers."""
|
|
14
|
+
|
|
15
|
+
PDB = "pdb"
|
|
16
|
+
PUDB = "pudb"
|
|
17
|
+
IPDB = "ipdb"
|
|
18
|
+
DEBUGPY = "debugpy"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Features(BaseModel):
|
|
22
|
+
"""Configuration for installing debug features."""
|
|
23
|
+
|
|
24
|
+
model_config = ConfigDict(extra="forbid") # pyright: ignore[reportUnannotatedClassAttribute]
|
|
25
|
+
|
|
26
|
+
rich_inspect: bool = True
|
|
27
|
+
"""Install rich inspect as 'i' for enhanced object inspection."""
|
|
28
|
+
rich_print: bool = True
|
|
29
|
+
"""Install rich print as 'p' for enhanced printing."""
|
|
30
|
+
rich_traceback: bool = True
|
|
31
|
+
"""Install rich traceback for better error reporting."""
|
|
32
|
+
comparer: bool = True
|
|
33
|
+
"""Install comparer as 'c' for side-by-side object comparison."""
|
|
34
|
+
breakpoint: bool = True
|
|
35
|
+
"""Install breakpoint as 'b' for setting breakpoints in code."""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class DebugDojoConfig(BaseModel):
|
|
39
|
+
"""Configuration for Debug Dojo."""
|
|
40
|
+
|
|
41
|
+
model_config = ConfigDict(extra="forbid") # pyright: ignore[reportUnannotatedClassAttribute]
|
|
42
|
+
|
|
43
|
+
debugger: DebuggerType = DebuggerType.PUDB
|
|
44
|
+
"""The type of debugger to use."""
|
|
45
|
+
features: Features = Features()
|
|
46
|
+
"""Features to install for debugging."""
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def resolve_config_path(config_path: Path | None) -> Path | None:
|
|
50
|
+
"""Resolve the configuration path, returning a default if none is provided."""
|
|
51
|
+
if config_path:
|
|
52
|
+
if not config_path.exists():
|
|
53
|
+
msg = f"Configuration file not found:\n{config_path.resolve()}"
|
|
54
|
+
raise FileNotFoundError(msg)
|
|
55
|
+
return config_path
|
|
56
|
+
|
|
57
|
+
# Default configuration path
|
|
58
|
+
for path in (Path("dojo.toml"), Path("pyproject.toml")):
|
|
59
|
+
if path.exists():
|
|
60
|
+
return path
|
|
61
|
+
return None
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def load_raw_config(
|
|
65
|
+
config_path: Path,
|
|
66
|
+
) -> dict[str, Any]: # pyright: ignore[reportExplicitAny]
|
|
67
|
+
"""Load the Debug Dojo configuration from a file.
|
|
68
|
+
|
|
69
|
+
Currently supports 'dojo.toml' or 'pyproject.toml'.
|
|
70
|
+
If no path is provided, it checks the current directory for these files.
|
|
71
|
+
"""
|
|
72
|
+
with config_path.open("rb") as f:
|
|
73
|
+
config_data = tomlkit.load(f).unwrap()
|
|
74
|
+
|
|
75
|
+
# If config is in [tool.debug_dojo] (pyproject.toml), extract it.
|
|
76
|
+
if config_path.name == "dojo.toml":
|
|
77
|
+
return config_data
|
|
78
|
+
|
|
79
|
+
if config_path.name == "pyproject.toml":
|
|
80
|
+
try:
|
|
81
|
+
dojo_config = cast(
|
|
82
|
+
"dict[str, Any]", # pyright: ignore[reportExplicitAny]
|
|
83
|
+
config_data["tool"]["debug_dojo"],
|
|
84
|
+
)
|
|
85
|
+
except KeyError:
|
|
86
|
+
return {}
|
|
87
|
+
else:
|
|
88
|
+
return dojo_config
|
|
89
|
+
|
|
90
|
+
# If the file is not recognized, raise an error.
|
|
91
|
+
msg = (
|
|
92
|
+
f"Unsupported configuration file: \n{config_path.resolve()}\n"
|
|
93
|
+
"Expected 'dojo.toml' or 'pyproject.toml'."
|
|
94
|
+
)
|
|
95
|
+
raise ValueError(msg)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def load_config(
|
|
99
|
+
config_path: Path | None = None,
|
|
100
|
+
*,
|
|
101
|
+
verbose: bool = False,
|
|
102
|
+
) -> DebugDojoConfig:
|
|
103
|
+
"""Load the Debug Dojo configuration and return a DebugDojoConfig instance."""
|
|
104
|
+
resolved_path = resolve_config_path(config_path)
|
|
105
|
+
|
|
106
|
+
if verbose:
|
|
107
|
+
if resolved_path:
|
|
108
|
+
msg = f"Using configuration file: {resolved_path.resolve()}."
|
|
109
|
+
else:
|
|
110
|
+
msg = "No configuration file found, using default settings."
|
|
111
|
+
rich_print(f"[blue]{msg}[/blue]")
|
|
112
|
+
|
|
113
|
+
if not resolved_path:
|
|
114
|
+
return DebugDojoConfig()
|
|
115
|
+
|
|
116
|
+
raw_config = load_raw_config(resolved_path)
|
|
117
|
+
return DebugDojoConfig.model_validate(raw_config)
|