HOW-TO:Python Development in Visual Studio: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
(Created page with "== Getting Started == This guide is based on Visual Studio 2013, this guidance may be relevant for other versions but mileage may vary! * Install Visual Studio 2013 and updat...")
 
No edit summary
Line 21: Line 21:
TODO
TODO


== Project Setup ==
These are optional but make the experience better.
To enable better intellisense for kodi components use XBMCstubs. This can be downloaded @ https://github.com/romanvm/xbmcstubs and all you need to do is add the location you downloaded the files from to the Search Paths.
Add the kodi addons directory to the search paths for the addons you are referencing. An example would be <KODI Root>\portable_data\addons\script.common.plugin.cache\lib to allow intellisense to work for StorageServer
Note: Intellisense will not be fully active until the DB is created, Press <Ctrl+K, `> to see its progress.
== Running your project ==
== Running your project ==


Line 26: Line 34:


Right click on you python file that is the starting point for the plugin and ensure it is set as the startup file. If it is already bolded you do not have to worry about this.
Right click on you python file that is the starting point for the plugin and ensure it is set as the startup file. If it is already bolded you do not have to worry about this.
== Debugging your project ==
Work in Progress: Currently the attach process does not seem to be picking correctly for the breakpoints.
To debug your project you need to add a reference to ptvsd to your script and the project to enable intellisense.
* Install ptvsd via pip
pip install ptvsd
* Add the following lines to the top of your script. Remember to comment out or remove once completed.
import ptvsd
ptvsd.enable_attach(secret = 'mysecret')
ptvsd.wait_for_attach
* Set the breakpoint in your script that you want to check.
* Start KODI
* Start your plugin.
* In Visual Studio use '''''Debug''''' -> '''''Attach to Process''''' menu command, which opens the '''Attach to Process''' dialog. The first thing to do in it is to open the '''Transport''' combo box, and change selection to '''Python remote debugging'''
* For the qualifier add tcp://mysecret@localhost/

Revision as of 15:07, 14 May 2015

Getting Started

This guide is based on Visual Studio 2013, this guidance may be relevant for other versions but mileage may vary!

Setting up your Project

If you have existing code go to File -> New -> Project and select From Existing Python Code, otherwise select Python Application. these project templates are under Templates / Python Update the name and the location relevant to your choice.

From Existing Python Code

For the existing code option ensure all the files are added, if you miss some you can add them to the project later. On the next page select the Python version you are running against. On the final page ensure you are happy with your project file name and location and click on Finish.

Python Application

TODO

Project Setup

These are optional but make the experience better.

To enable better intellisense for kodi components use XBMCstubs. This can be downloaded @ https://github.com/romanvm/xbmcstubs and all you need to do is add the location you downloaded the files from to the Search Paths. Add the kodi addons directory to the search paths for the addons you are referencing. An example would be <KODI Root>\portable_data\addons\script.common.plugin.cache\lib to allow intellisense to work for StorageServer

Note: Intellisense will not be fully active until the DB is created, Press <Ctrl+K, `> to see its progress.

Running your project

Once you have a project up and running you have the magic of Visual Studio and the python tools at your disposal, along with any other adding to visual studio you like.

Right click on you python file that is the starting point for the plugin and ensure it is set as the startup file. If it is already bolded you do not have to worry about this.




Debugging your project

Work in Progress: Currently the attach process does not seem to be picking correctly for the breakpoints.

To debug your project you need to add a reference to ptvsd to your script and the project to enable intellisense.

  • Install ptvsd via pip
pip install ptvsd 
  • Add the following lines to the top of your script. Remember to comment out or remove once completed.
import ptvsd
ptvsd.enable_attach(secret = 'mysecret')
ptvsd.wait_for_attach
  • Set the breakpoint in your script that you want to check.
  • Start KODI
  • Start your plugin.
  • In Visual Studio use Debug -> Attach to Process menu command, which opens the Attach to Process dialog. The first thing to do in it is to open the Transport combo box, and change selection to Python remote debugging
  • For the qualifier add tcp://mysecret@localhost/