debug-dojo 0.2.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.
Files changed (29) hide show
  1. {debug_dojo-0.2.0 → debug_dojo-0.3.1}/HISTORY.md +17 -5
  2. {debug_dojo-0.2.0 → debug_dojo-0.3.1}/PKG-INFO +83 -34
  3. debug_dojo-0.3.1/README.md +102 -0
  4. debug_dojo-0.3.1/dojo.toml +7 -0
  5. debug_dojo-0.3.1/logo/logo_black.png +0 -0
  6. debug_dojo-0.3.1/logo/logo_white.png +0 -0
  7. {debug_dojo-0.2.0 → debug_dojo-0.3.1}/pyproject.toml +25 -4
  8. debug_dojo-0.3.1/ruff.toml +19 -0
  9. debug_dojo-0.3.1/src/debug_dojo/__init__.py +23 -0
  10. {debug_dojo-0.2.0 → debug_dojo-0.3.1}/src/debug_dojo/__main__.py +2 -2
  11. debug_dojo-0.3.1/src/debug_dojo/_cli.py +101 -0
  12. debug_dojo-0.2.0/src/debug_dojo/compareres.py → debug_dojo-0.3.1/src/debug_dojo/_compareres.py +3 -1
  13. debug_dojo-0.3.1/src/debug_dojo/_config.py +117 -0
  14. debug_dojo-0.3.1/src/debug_dojo/_installers.py +138 -0
  15. debug_dojo-0.3.1/src/debug_dojo/install.py +7 -0
  16. debug_dojo-0.3.1/uv.lock +2083 -0
  17. debug_dojo-0.2.0/README.md +0 -70
  18. debug_dojo-0.2.0/ruff.toml +0 -20
  19. debug_dojo-0.2.0/src/debug_dojo/__init__.py +0 -21
  20. debug_dojo-0.2.0/src/debug_dojo/all.py +0 -5
  21. debug_dojo-0.2.0/src/debug_dojo/cli.py +0 -49
  22. debug_dojo-0.2.0/src/debug_dojo/installers.py +0 -82
  23. debug_dojo-0.2.0/src/debug_dojo/version.py +0 -3
  24. debug_dojo-0.2.0/uv.lock +0 -199
  25. {debug_dojo-0.2.0 → debug_dojo-0.3.1}/.gitignore +0 -0
  26. {debug_dojo-0.2.0 → debug_dojo-0.3.1}/.python-version +0 -0
  27. {debug_dojo-0.2.0 → debug_dojo-0.3.1}/LICENCE +0 -0
  28. {debug_dojo-0.2.0 → debug_dojo-0.3.1}/examples/test_target.py +0 -0
  29. {debug_dojo-0.2.0 → debug_dojo-0.3.1}/src/debug_dojo/py.typed +0 -0
@@ -1,6 +1,20 @@
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
- *release tag*: [v0.2.0](https://github.com/pydantic/pydantic/releases/tag/v2.11.6)
17
+ *release tag*: [v0.2.0]
4
18
 
5
19
  ### What's Changed
6
20
 
@@ -13,13 +27,11 @@
13
27
 
14
28
  - Fixed `pyproject.toml` to point to GitHub repository as the homepage.
15
29
 
16
- ## v0.1.0 (2025-07-20)
30
+ ## v0.1.0 (2025-07-19)
17
31
 
18
- *release tag*: [v0.1.0](https://github.com/pydantic/pydantic/releases/tag/v2.11.6)
32
+ *release tag*: [v0.1.0]
19
33
 
20
34
  ### What's Changed
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.2.0
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,36 +20,63 @@ 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: rich>=11.0.0
26
+ Requires-Dist: pydantic>=2.11.7
27
+ Requires-Dist: rich>=12.0.0
28
+ Requires-Dist: tomlkit>=0.13.3
29
+ Requires-Dist: typer>=0.15.0
25
30
  Description-Content-Type: text/markdown
26
31
 
27
- # debug-dojo
32
+ <p align="center">
33
+ <img src="https://github.com/bwrob/debug-dojo/blob/main/logo/logo_white.png?raw=true" alt="debug dojo" style="width:50%; max-width:400px;"/>
34
+ </p>
28
35
 
29
- **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 PuDB. All tools can be installed at once or individually, allowing for flexible debugging setups.
36
+ <p align="center">
37
+ <em>debug dojo, a place for zen debugging</em>
38
+ </p>
39
+
40
+ [![PyPi Version](https://img.shields.io/pypi/v/debug-dojo.svg?style=flat-square)](https://pypi.org/project/debug-dojo)
41
+ [![PyPI pyversions](https://img.shields.io/pypi/pyversions/debug-dojo.svg?style=flat-square)](https://pypi.org/pypi/debug-dojo/)
42
+
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.
30
44
 
31
45
  ## Features
32
46
 
47
+ - **Convenient CLI** Quickly run your code with debugging tools enabled.
33
48
  - **Simple API:** Install all tools or only what you need.
34
- - **PuDB integration:** Quickly enable the PuDB TUI debugger.
49
+ - **Debugger integration:** Quickly enable Debugpy, PuDB, PDB, or IPDB as your default debugger.
35
50
  - **Rich tracebacks:** Get readable, colorized tracebacks for easier debugging.
36
51
  - **Side-by-side object inspection:** Visually compare Python objects, their attributes, and methods in the terminal.
37
52
 
38
- ## Installation
53
+ ## Usage
39
54
 
40
- ```sh
41
- pip install debug-dojo
55
+ ### CLI
56
+
57
+ Run your Python script with debugging tools enabled using the `debug-dojo` command:
58
+
59
+ ```console
60
+ dojo my_script.py
42
61
  ```
43
62
 
44
- ## Usage
63
+ You can optionally set configuration file and verbose mode:
45
64
 
46
- ### Install all debugging tools
65
+ ```console
66
+ dojo --config dojo.toml --verbose my_script.py
67
+ ```
68
+
69
+ ### From the code
47
70
 
48
71
  In the `PuDB` style, you can install all debugging tools and enter the debugging mode with a single command:
49
72
 
50
73
  ```python
51
- import debug_dojo.all; b()
74
+ import debug_dojo.install; b()
52
75
 
76
+ object_1 = {"foo": 1, "bar": 2}
77
+ object_2 = [1, 2, 3]
78
+
79
+ p(object_1) # Pretty print an object with Rich
53
80
  i(object_1) # Inspect an object
54
81
  c(object_1, object_2) # Compare two objects side-by-side
55
82
  ```
@@ -57,40 +84,50 @@ c(object_1, object_2) # Compare two objects side-by-side
57
84
  Where:
58
85
 
59
86
  - `b()` is a builtin-injected function that sets a breakpoint using PuDB's `set_trace()`.
60
- - `i(object_1)` to inspect an object.
87
+ - `p(object_1)` is pretty printing of an object using Rich.
88
+ - `i(object_1)` to inspect an object using Rich.
61
89
  - `c(object_1, object_2)` to compare two objects side-by-side.
62
90
 
63
- ### Use individual tools
91
+ ## Configuration
64
92
 
65
- ```python
66
- 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.
67
94
 
68
- install_inspect() # Enable object inspection helpers
69
- use_pudb() # Set up PuDB as the debugger
70
- use_rich_traceback() # Enable Rich tracebacks
95
+ **Example `dojo.toml`:**
96
+
97
+ ```toml
98
+ debugger = "ipdb"
99
+
100
+ [features]
101
+ rich_inspect = true
102
+ rich_print = true
103
+ comparer = false
71
104
  ```
72
105
 
73
- ### Compare objects side-by-side
106
+ ## Installation
74
107
 
75
- ```python
76
- from debug_dojo.compareres import inspect_objects_side_by_side
108
+ The package is available on PyPI and can be installed using standard Python package management tools.
77
109
 
78
- a = {"foo": 1, "bar": 2}
79
- b = [1, 2, 3]
80
- inspect_objects_side_by_side(a, b)
110
+ ```console
111
+ pip install debug-dojo
81
112
  ```
82
113
 
83
- ## Development
114
+ You can also use `poetry` or `uv` to add it to your project:
84
115
 
85
- ### Run tests
116
+ ```console
117
+ poetry add debug-dojo
118
+ ```
86
119
 
87
- ```sh
88
- pytest
120
+ ```console
121
+ uv add debug-dojo
89
122
  ```
90
123
 
124
+ Note that dojo most likely will not work when installed via `pipx` or `uvx`, as it relies on the current Python environment dependencies.
125
+
126
+ ## Development
127
+
91
128
  ### Lint and type check
92
129
 
93
- ```sh
130
+ ```console
94
131
  ruff check src/debug_dojo --fix
95
132
  basedpyright src/debug_dojo
96
133
  ```
@@ -98,9 +135,23 @@ basedpyright src/debug_dojo
98
135
 
99
136
  ## Changelog
100
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
+
101
152
  ## v0.2.0 (2025-07-20)
102
153
 
103
- *release tag*: [v0.2.0](https://github.com/pydantic/pydantic/releases/tag/v2.11.6)
154
+ *release tag*: [v0.2.0]
104
155
 
105
156
  ### What's Changed
106
157
 
@@ -113,13 +164,11 @@ basedpyright src/debug_dojo
113
164
 
114
165
  - Fixed `pyproject.toml` to point to GitHub repository as the homepage.
115
166
 
116
- ## v0.1.0 (2025-07-20)
167
+ ## v0.1.0 (2025-07-19)
117
168
 
118
- *release tag*: [v0.1.0](https://github.com/pydantic/pydantic/releases/tag/v2.11.6)
169
+ *release tag*: [v0.1.0]
119
170
 
120
171
  ### What's Changed
121
172
 
122
173
  - Initial module to install debugging tools.
123
174
  - Debug mode utilities for PuDB, rich tracebacks, and object inspection.
124
-
125
- #### Fixes
@@ -0,0 +1,102 @@
1
+ <p align="center">
2
+ <img src="https://github.com/bwrob/debug-dojo/blob/main/logo/logo_white.png?raw=true" alt="debug dojo" style="width:50%; max-width:400px;"/>
3
+ </p>
4
+
5
+ <p align="center">
6
+ <em>debug dojo, a place for zen debugging</em>
7
+ </p>
8
+
9
+ [![PyPi Version](https://img.shields.io/pypi/v/debug-dojo.svg?style=flat-square)](https://pypi.org/project/debug-dojo)
10
+ [![PyPI pyversions](https://img.shields.io/pypi/pyversions/debug-dojo.svg?style=flat-square)](https://pypi.org/pypi/debug-dojo/)
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 different debuggers. All tools can be installed at once or individually, allowing for flexible debugging setups.
13
+
14
+ ## Features
15
+
16
+ - **Convenient CLI** Quickly run your code with debugging tools enabled.
17
+ - **Simple API:** Install all tools or only what you need.
18
+ - **Debugger integration:** Quickly enable Debugpy, PuDB, PDB, or IPDB as your default debugger.
19
+ - **Rich tracebacks:** Get readable, colorized tracebacks for easier debugging.
20
+ - **Side-by-side object inspection:** Visually compare Python objects, their attributes, and methods in the terminal.
21
+
22
+ ## Usage
23
+
24
+ ### CLI
25
+
26
+ Run your Python script with debugging tools enabled using the `debug-dojo` command:
27
+
28
+ ```console
29
+ dojo my_script.py
30
+ ```
31
+
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
39
+
40
+ In the `PuDB` style, you can install all debugging tools and enter the debugging mode with a single command:
41
+
42
+ ```python
43
+ import debug_dojo.install; b()
44
+
45
+ object_1 = {"foo": 1, "bar": 2}
46
+ object_2 = [1, 2, 3]
47
+
48
+ p(object_1) # Pretty print an object with Rich
49
+ i(object_1) # Inspect an object
50
+ c(object_1, object_2) # Compare two objects side-by-side
51
+ ```
52
+
53
+ Where:
54
+
55
+ - `b()` is a builtin-injected function that sets a breakpoint using PuDB's `set_trace()`.
56
+ - `p(object_1)` is pretty printing of an object using Rich.
57
+ - `i(object_1)` to inspect an object using Rich.
58
+ - `c(object_1, object_2)` to compare two objects side-by-side.
59
+
60
+ ## Configuration
61
+
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.
63
+
64
+ **Example `dojo.toml`:**
65
+
66
+ ```toml
67
+ debugger = "ipdb"
68
+
69
+ [features]
70
+ rich_inspect = true
71
+ rich_print = true
72
+ comparer = false
73
+ ```
74
+
75
+ ## Installation
76
+
77
+ The package is available on PyPI and can be installed using standard Python package management tools.
78
+
79
+ ```console
80
+ pip install debug-dojo
81
+ ```
82
+
83
+ You can also use `poetry` or `uv` to add it to your project:
84
+
85
+ ```console
86
+ poetry add debug-dojo
87
+ ```
88
+
89
+ ```console
90
+ uv add debug-dojo
91
+ ```
92
+
93
+ Note that dojo most likely will not work when installed via `pipx` or `uvx`, as it relies on the current Python environment dependencies.
94
+
95
+ ## Development
96
+
97
+ ### Lint and type check
98
+
99
+ ```console
100
+ ruff check src/debug_dojo --fix
101
+ basedpyright src/debug_dojo
102
+ ```
@@ -0,0 +1,7 @@
1
+ debugger = "ipdb"
2
+
3
+ [features]
4
+ rich_inspect = true
5
+ rich_print = true
6
+ comparer = false
7
+ breakpoint = true
Binary file
Binary file
@@ -5,7 +5,15 @@
5
5
  { name = "bwrob", email = "bartosz.marcin.wroblewski@gmail.com" },
6
6
  ]
7
7
  requires-python = ">=3.10"
8
- dependencies = ["pudb>=2020.1", "rich>=11.0.0"]
8
+ dependencies = [
9
+ "debugpy>=1.8.0",
10
+ "ipdb>=0.13.0",
11
+ "pudb>=2020.1",
12
+ "pydantic>=2.11.7",
13
+ "rich>=12.0.0",
14
+ "tomlkit>=0.13.3",
15
+ "typer>=0.15.0",
16
+ ]
9
17
  license = 'MIT'
10
18
  license-files = ['LICENSE']
11
19
  keywords = [
@@ -28,7 +36,8 @@
28
36
  "Topic :: Software Development :: Debuggers",
29
37
  "Topic :: Software Development :: Libraries :: Python Modules",
30
38
  ]
31
- dynamic = ['readme', 'version']
39
+ version = "0.3.1"
40
+ dynamic = ['readme']
32
41
 
33
42
  [project.urls]
34
43
  Homepage = "https://github.com/bwrob/debug-dojo"
@@ -39,10 +48,15 @@
39
48
  [project.scripts]
40
49
  # This defines your command-line script!
41
50
  # It points to the 'main' function in your 'cli' module.
42
- "dojo" = "debug_dojo.cli:main"
51
+ "dojo" = "debug_dojo._cli:main"
43
52
 
44
53
  [dependency-groups]
45
- dev = ["basedpyright>=1.31.0", "ruff>=0.12.4"]
54
+ dev = [
55
+ "basedpyright>=1.31.0",
56
+ "jupyter>=1.1.1",
57
+ "poethepoet>=0.36.0",
58
+ "ruff>=0.12.4",
59
+ ]
46
60
 
47
61
  [build-system]
48
62
  requires = [
@@ -72,3 +86,10 @@
72
86
  pythonVersion = "3.10"
73
87
  strict = ["src/debug_dojo/*"]
74
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
+ """
@@ -1,6 +1,6 @@
1
1
  """Entry point for the debug_dojo package."""
2
2
 
3
- from .cli import main
4
-
5
3
  if __name__ == "__main__":
4
+ from ._cli import main
5
+
6
6
  main()
@@ -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()
@@ -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-callable attributes
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)