API Reference¶
Debugging tools for Python.
This module provides functions to set up debugging tools like PuDB and Rich Traceback. It checks for the availability of these tools and configures them accordingly.
Importing this module will install the debugging tools based on the configuration. Example usage:
This will install the debugging tools and put debug breakpoint at this line.
Another way to use this module is to run the desired script or module with the
dojo
command-line interface.
Dependency Graph¶
```mermaid graph TD src.debug_dojo._installers –> src.debug_dojo._compare src.debug_dojo._installers –> src.debug_dojo._config_models src.debug_dojo._cli –> src.debug_dojo._installers src.debug_dojo._cli –> src.debug_dojo._config src.debug_dojo._cli –> src.debug_dojo._config_models src.debug_dojo._config –> src.debug_dojo._config_models src.debug_dojo.install –> src.debug_dojo._config src.debug_dojo.install –> src.debug_dojo._installers src.debug_dojo._config_models src.debug_dojo._compare
```
Module for installing and configuring various debugging tools and features.
This module provides functions to set up different debuggers (PDB, PuDB, IPDB,
Debugpy) and to install enhanced debugging features like Rich Traceback, Rich
Inspect, Rich Print, and a side-by-side object comparer. These installations
are typically driven by the DebugDojoConfig
.
install_breakpoint(mnemonic='b')
¶
Inject thebreakpoint()
function into builtins under the given mnemonic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mnemonic
|
str
|
The name to use for the breakpoint function in builtins. If an empty string, the feature is not installed. |
'b'
|
install_breakpoint() import builtins callable(builtins.b) True
Source code in src/debug_dojo/_installers.py
install_by_config(config)
¶
Installs all debugging tools and features based on the given configuration.
This is the main entry point for applying debug-dojo
settings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DebugDojoConfig
|
The complete debug-dojo configuration object. |
required |
Source code in src/debug_dojo/_installers.py
install_compare(mnemonic='c')
¶
Injects the side-by-side object comparison function into builtins.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mnemonic
|
str
|
The name to use for the compare function in builtins. If an empty string, the feature is not installed. |
'c'
|
install_compare() import builtins callable(builtins.c) True
Source code in src/debug_dojo/_installers.py
install_features(features)
¶
Installs debugging features based on the provided configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features
|
FeaturesConfig
|
Configuration object specifying which features to install and their mnemonics. |
required |
Source code in src/debug_dojo/_installers.py
install_inspect(mnemonic='i')
¶
Injects rich.inspect
into builtins under the given mnemonic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mnemonic
|
str
|
The name to use for the inspect function in builtins. If an empty string, the feature is not installed. |
'i'
|
Source code in src/debug_dojo/_installers.py
install_rich_print(mnemonic='p')
¶
Injects rich.print
into builtins under the given mnemonic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mnemonic
|
str
|
The name to use for the print function in builtins. If an empty string, the feature is not installed. |
'p'
|
install_rich_print() import builtins callable(builtins.p) True p(“test”) test
Source code in src/debug_dojo/_installers.py
rich_traceback(*, locals_in_traceback)
¶
Install Rich Traceback for enhanced error reporting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locals_in_traceback
|
bool
|
Whether to include local variables in the traceback. |
required |
Source code in src/debug_dojo/_installers.py
set_debugger(config)
¶
Set the default debugger based on the provided configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
DebuggersConfig
|
Configuration object for debuggers. |
required |
Source code in src/debug_dojo/_installers.py
set_exceptions(exceptions)
¶
Configure exception handling based on the provided configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exceptions
|
ExceptionsConfig
|
Configuration object for exception handling. |
required |
Source code in src/debug_dojo/_installers.py
use_debugpy(config)
¶
Set Debugpy as the default debugger.
Configures sys.breakpointhook
to use debugpy.breakpoint
, sets the
PYTHONBREAKPOINT
environment variable, and starts a debugpy server
waiting for a client connection.
Source code in src/debug_dojo/_installers.py
use_ipdb(config)
¶
Set IPDB as the default debugger.
Configures sys.breakpointhook
to use ipdb.set_trace
, sets the
PYTHONBREAKPOINT
environment variable, and configures IPDB_CONTEXT_SIZE
.
Source code in src/debug_dojo/_installers.py
use_pdb(config)
¶
Set PDB as the default debugger.
Configures sys.breakpointhook
to use pdb.set_trace
and sets the
PYTHONBREAKPOINT
environment variable.
Source code in src/debug_dojo/_installers.py
use_pudb(config)
¶
Set PuDB as the default debugger.
Configures sys.breakpointhook
to use pudb.set_trace
and sets the
PYTHONBREAKPOINT
environment variable.
Source code in src/debug_dojo/_installers.py
Utilities for side-by-side inspection and comparison of Python objects.
This module provides functions to display attributes and methods of two objects in a visually appealing, side-by-side format in the terminal.
get_object_attributes(obj)
¶
Extract and format non-callable attributes of an object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
object
|
The object to extract attributes from. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: A list of formatted strings, each representing an attribute. |
Source code in src/debug_dojo/_compare.py
get_object_methods(obj)
¶
Extract and format public callable methods of an object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
object
|
The object to extract methods from. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: A list of method names. |
Source code in src/debug_dojo/_compare.py
get_simplified_object_info(obj)
¶
Generate a simplified, Rich-formatted inspection output for an object.
Handles basic Python types by displaying their value directly. For other objects, it lists their attributes and public methods.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
object
|
The object to generate info for. |
required |
Returns:
Type | Description |
---|---|
list[Text]
|
list[Text]: A list of Rich Text objects representing the object’s information. |
Source code in src/debug_dojo/_compare.py
inspect_objects_side_by_side(obj1, obj2)
¶
Display two Python objects side-by-side in the terminal using Rich.
Showing their attributes and methods in a simplified, aligned format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj1
|
object
|
The first object to display. |
required |
obj2
|
object
|
The second object to display. |
required |
Source code in src/debug_dojo/_compare.py
Debug Dojo configuration module.
It includes configurations for different debuggers, exception handling, and features that can be enabled or disabled.
load_config(config_path=None, *, verbose=False, debugger=None)
¶
Load the Debug Dojo configuration.
Return a DebugDojoConfig instance with the loaded configuration.
If no configuration file is found, it returns a default configuration. If a debugger is specified, it overrides the config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path
|
Path | None
|
Optional path to a configuration file. |
None
|
verbose
|
bool
|
If True, print verbose messages during configuration loading. |
False
|
debugger
|
DebuggerType | None
|
Optional debugger type to override the default debugger specified in the configuration. |
None
|
Returns:
Name | Type | Description |
---|---|---|
DebugDojoConfig |
DebugDojoConfig
|
The loaded and potentially overridden DebugDojoConfig instance. |
Source code in src/debug_dojo/_config.py
load_raw_config(config_path)
¶
Load the Debug Dojo configuration from a file.
Currently supports ‘dojo.toml’ or ‘pyproject.toml’. If no path is provided, it checks the current directory for these files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path
|
Path
|
The absolute path to the configuration file. |
required |
Returns:
Name | Type | Description |
---|---|---|
JSON |
JSON
|
The raw configuration data as a JSON-like dictionary. |
Raises:
Type | Description |
---|---|
ValueError
|
If there is an error parsing the TOML file. |
Source code in src/debug_dojo/_config.py
resolve_config_path(config_path)
¶
Resolve the configuration path.
Returning a default if none is provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path
|
Path | None
|
The explicit path to the configuration file, or None. |
required |
Returns:
Type | Description |
---|---|
Path | None
|
Path | None: The resolved absolute path to the configuration file, or None if no configuration file is found and no explicit path was given. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If an explicit |
Source code in src/debug_dojo/_config.py
validated_and_updated_config(raw_config, *, verbose)
¶
Validate and update the raw configuration to the latest DebugDojoConfig version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_config
|
JSON
|
The raw configuration data loaded from a file. |
required |
verbose
|
bool
|
If True, print verbose messages during validation and update. |
required |
Returns:
Name | Type | Description |
---|---|---|
DebugDojoConfig |
DebugDojoConfig
|
A validated and updated DebugDojoConfig instance. |
Raises:
Type | Description |
---|---|
Exit
|
If the configuration cannot be validated against any known version. |
Source code in src/debug_dojo/_config.py
Dataclass models for Debug Dojo’s configuration.
This module defines the data structures used to validate and manage the configuration of debug-dojo, including settings for debuggers, exception handling, and features.
DebugDojoConfigV1
dataclass
¶
Legacy configuration for Debug Dojo (version 1).
Source code in src/debug_dojo/_config_models.py
debugger = DebuggerType.PUDB
class-attribute
instance-attribute
¶
The type of debugger to use.
features = field(default_factory=Features)
class-attribute
instance-attribute
¶
Features to install for debugging.
update()
¶
Update the configuration to the latest version.
Source code in src/debug_dojo/_config_models.py
DebugDojoConfigV2
dataclass
¶
Configuration for Debug Dojo.
Source code in src/debug_dojo/_config_models.py
debuggers = field(default_factory=DebuggersConfig)
class-attribute
instance-attribute
¶
Default debugger and configs.
exceptions = field(default_factory=ExceptionsConfig)
class-attribute
instance-attribute
¶
Better exception messages.
features = field(default_factory=FeaturesConfig)
class-attribute
instance-attribute
¶
Features mnemonics.
DebuggerType
¶
DebuggersConfig
dataclass
¶
Configuration for debuggers.
Source code in src/debug_dojo/_config_models.py
debugpy = field(default_factory=DebugpyConfig)
class-attribute
instance-attribute
¶
Configuration for debugpy debugger.
default = DebuggerType.IPDB
class-attribute
instance-attribute
¶
Default debugger to use.
ipdb = field(default_factory=IpdbConfig)
class-attribute
instance-attribute
¶
Configuration for ipdb debugger.
pdb = field(default_factory=PdbConfig)
class-attribute
instance-attribute
¶
Configuration for pdb debugger.
prompt_name = 'debug-dojo> '
class-attribute
instance-attribute
¶
Prompt name for the debugger, used in the REPL.
pudb = field(default_factory=PudbConfig)
class-attribute
instance-attribute
¶
Configuration for pudb debugger.
DebugpyConfig
dataclass
¶
Configuration for debugpy debugger.
Source code in src/debug_dojo/_config_models.py
host = 'localhost'
class-attribute
instance-attribute
¶
Host for debugpy debugger.
log_to_file = False
class-attribute
instance-attribute
¶
Whether to log debugpy output to a file.
port = 1992
class-attribute
instance-attribute
¶
Port for debugpy debugger.
wait_for_client = True
class-attribute
instance-attribute
¶
Whether to wait for the client to connect before starting debugging.
ExceptionsConfig
dataclass
¶
Configuration for exceptions handling.
Source code in src/debug_dojo/_config_models.py
locals_in_traceback = False
class-attribute
instance-attribute
¶
Include local variables in traceback.
post_mortem = True
class-attribute
instance-attribute
¶
Enable post-mortem debugging after an exception.
rich_traceback = True
class-attribute
instance-attribute
¶
Enable rich traceback for better error reporting.
Features
dataclass
¶
Legacy configuration for installing debug features (used in V1 config).
Source code in src/debug_dojo/_config_models.py
breakpoint = True
class-attribute
instance-attribute
¶
Install breakpoint as ‘b’ for setting breakpoints in code.
comparer = True
class-attribute
instance-attribute
¶
Install comparer as ‘c’ for side-by-side object comparison.
rich_inspect = True
class-attribute
instance-attribute
¶
Install rich inspect as ‘i’ for enhanced object inspection.
rich_print = True
class-attribute
instance-attribute
¶
Install rich print as ‘p’ for enhanced printing.
rich_traceback = True
class-attribute
instance-attribute
¶
Install rich traceback for better error reporting.
FeaturesConfig
dataclass
¶
Configuration for installing debug features.
Source code in src/debug_dojo/_config_models.py
breakpoint = 'b'
class-attribute
instance-attribute
¶
Install breakpoint as ‘b’ for setting breakpoints in code.
comparer = 'c'
class-attribute
instance-attribute
¶
Install comparer as ‘c’ for side-by-side object comparison.
rich_inspect = 'i'
class-attribute
instance-attribute
¶
Install rich inspect as ‘i’ for enhanced object inspection.
rich_print = 'p'
class-attribute
instance-attribute
¶
Install rich print as ‘p’ for enhanced printing.
IpdbConfig
dataclass
¶
Configuration for ipdb debugger.
Source code in src/debug_dojo/_config_models.py
context_lines = 20
class-attribute
instance-attribute
¶
Number of context lines to show in ipdb.
PdbConfig
dataclass
¶
Command-line interface for running Python scripts or modules with debugging tools.
ExecMode
¶
__execute_with_debug(target_name, target_args, *, target_mode, verbose, config)
¶
Execute a target script or module with installed debugging tools.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_name
|
str
|
The name of the script, module, or executable to run. |
required |
target_args
|
list[str]
|
Arguments to pass to the target. |
required |
target_mode
|
ExecMode
|
The execution mode (FILE, MODULE, or EXECUTABLE). |
required |
verbose
|
bool
|
If True, print verbose output. |
required |
config
|
DebugDojoConfig
|
The debug-dojo configuration. |
required |
Raises:
Type | Description |
---|---|
Exit
|
If the target file is not found, or if an import error occurs, or if the script exits with a non-zero code. |
Source code in src/debug_dojo/_cli.py
main()
¶
run_debug(ctx, target_name=None, *, config_path=None, debugger=None, verbose=False, module=False, executable=False)
¶
Run a Python script, module, or executable with debug-dojo tools.
This command acts as the main entry point for debug-dojo
, allowing users to
execute their code while automatically installing and configuring debugging tools
based on the provided options or configuration file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ctx
|
Context
|
The Typer context object. |
required |
target_name
|
str | None
|
The path to the script, name of the module, or name of the executable to run. If not provided, the command will exit. |
None
|
config_path
|
Path | None
|
Path to a custom configuration file
(e.g., |
None
|
debugger
|
DebuggerType | None
|
Override the default debugger specified in the config. |
None
|
verbose
|
bool
|
Enable verbose output, showing loaded configuration and installation steps. |
False
|
module
|
bool
|
Treat |
False
|
executable
|
bool
|
Treat |
False
|
Raises:
Type | Description |
---|---|
Exit
|
If |
Source code in src/debug_dojo/_cli.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|