You can extend the debugger without modifying its core code by implementing custom extensions. To do this, you must follow a specific directory structure, ensure your root directory is in sys.path (e.g., via PYTHONPATH), and use a specific namespace pattern.
1. Directory Structure
Your extension must follow this layout:
|-- root_directory (must be on python path)
| |-- pydevd_plugins
| | |-- __init__.py (must contain preamble)
| | |-- extensions
| | | |-- __init__.py (must contain preamble)
| | | |-- pydevd_plugin_<your_plugin_name>.py
2. Namespace Preamble
Both pydevd_plugins/__init__.py and pydevd_plugins/extensions/__init__.py must contain only the following preamble to support namespace packages:
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
3. Plugin Implementation
- Naming: The filename inside the
extensions folder must start with pydevd_plugin_ (e.g., pydevd_plugin_my_extension.py). - Logic: Implement one or more abstract base classes defined in
_pydevd_bundle.pydevd_extension_api. You can do this by either inheriting from the classes or registering with the abstract base class.
|-- root_directory-> must be on python path
| |-- pydevd_plugins
| | |-- __init__.py -> must contain preamble
| | |-- extensions
| | | |-- __init__.py -> must contain preamble
| | | |-- pydevd_plugin_plugin_name.py