HOW-TO:Debug Python Scripts with Web-PDB: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[https://github.com/romanvm/kodi.web-pdb Web-PDB] is a remote web-interface to Python's built-in [https://docs.python.org/2/library/pdb.html PDB] debugger with additional convenience features. It is not tied to any IDE or other software, all you need is a common web-browser, e.g. Chrome or Firefox.
{{mininav|[[Development]]|[[Add-on development]]|[[Python development]]}}


[[File:https://raw.githubusercontent.com/romanvm/python-web-pdb/master/screenshot.png]]
[https://github.com/romanvm/kodi.web-pdb Web-PDB] is a remote web-interface to Python's built-in [https://docs.python.org/3/library/pdb.html PDB] debugger with additional convenience features. It is not tied to any IDE or other software, all you need is a common web-browser, e.g. Chrome or Firefox. Web-PDB is compatible with both Python 2 and 3, so you can use it to debug your Python 3 compatible addons.
 
[[File:web-pdb.png]]


Web-PDB for Kodi is available as an addon in the official Kodi addons repo.
Web-PDB for Kodi is available as an addon in the official Kodi addons repo.
Line 13: Line 15:
<requires>
<requires>
   ...
   ...
  <import addon="script.module.web-pdb" />
  <import addon="script.module.web-pdb" version="1.5.6"/>
<requires>
<requires>
</syntaxhighlight>
</syntaxhighlight>


3. Insert the following line into your addon code at the point where you want to start debugging:
3. Restart Kodi so that it re-reads addon dependencies.
 
4. Insert the following line into your addon code at the point where you want to start debugging:
<syntaxhighlight lang="python" enclose="div">
<syntaxhighlight lang="python" enclose="div">
import web_pdb; web_pdb.set_trace()
import web_pdb; web_pdb.set_trace()
Line 24: Line 28:
The <code>set_trace()</code> call will suspend your addon and open a web-UI at the default port 5555 (port value can be changed). At the same time a notification will be displayed in Kodi, indicating that a debug session is active. The notification also shows web-UI host/port.
The <code>set_trace()</code> call will suspend your addon and open a web-UI at the default port 5555 (port value can be changed). At the same time a notification will be displayed in Kodi, indicating that a debug session is active. The notification also shows web-UI host/port.


4. Enter in your the address bar of your browser: <code>http://<your Kodi machine hostname or IP>:5555</code>, for example <code>http://monty-python:5555</code>. Use <code>localhost</code> as a hostname if you are connecting from the same machine that runs Kodi. If everything is OK, you should see the Web-PDB UI. Now you can use all PDB commands and features. Additional '''Current file''', '''Globals''' and '''Locals''' information boxes help you better track your program runtime state.
5. Enter in your the address bar of your browser: <code>http://<your Kodi machine hostname or IP>:5555</code>, for example <code>http://monty-python:5555</code>. Use <code>localhost</code> as a hostname if you are connecting from the same machine that runs Kodi. If everything is OK, you should see the Web-PDB UI. Now you can use all PDB commands and features. Additional '''Current file''', '''Globals''' and '''Locals''' information boxes help you better track your program runtime state.


== More Information ==
== More Information ==
Line 30: Line 34:
* [https://github.com/romanvm/kodi.web-pdb Web-PDB for Kodi on GitHub].
* [https://github.com/romanvm/kodi.web-pdb Web-PDB for Kodi on GitHub].
* [https://docs.python.org/2/library/pdb.html PDB debugger documentation].
* [https://docs.python.org/2/library/pdb.html PDB debugger documentation].
[[Category:Development]]
[[Category:Python]]

Revision as of 00:40, 12 January 2022

Home icon grey.png   ▶ Development ▶ Add-on development ▶ Python development ▶ HOW-TO:Debug Python Scripts with Web-PDB

Web-PDB is a remote web-interface to Python's built-in PDB debugger with additional convenience features. It is not tied to any IDE or other software, all you need is a common web-browser, e.g. Chrome or Firefox. Web-PDB is compatible with both Python 2 and 3, so you can use it to debug your Python 3 compatible addons.

Web-pdb.png

Web-PDB for Kodi is available as an addon in the official Kodi addons repo.

How To Use Web-PDB for Kodi

1. Install Web-PDB addon: Kodi Add-on repository > Program add-ons > Web-PDB.

2. Add script.module.web-pdb to addon.xml as a dependency:

<requires>
  ...
   <import addon="script.module.web-pdb" version="1.5.6"/>
<requires>

3. Restart Kodi so that it re-reads addon dependencies.

4. Insert the following line into your addon code at the point where you want to start debugging:

import web_pdb; web_pdb.set_trace()

The set_trace() call will suspend your addon and open a web-UI at the default port 5555 (port value can be changed). At the same time a notification will be displayed in Kodi, indicating that a debug session is active. The notification also shows web-UI host/port.

5. Enter in your the address bar of your browser: http://<your Kodi machine hostname or IP>:5555, for example http://monty-python:5555. Use localhost as a hostname if you are connecting from the same machine that runs Kodi. If everything is OK, you should see the Web-PDB UI. Now you can use all PDB commands and features. Additional Current file, Globals and Locals information boxes help you better track your program runtime state.

More Information