Kodistubs (xbmcstubs) - code auto-completion and quick help for Python IDEs - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26) +--- Thread: Kodistubs (xbmcstubs) - code auto-completion and quick help for Python IDEs (/showthread.php?tid=173780) |
Kodistubs (xbmcstubs) - code auto-completion and quick help for Python IDEs - Roman_V_M - 2013-09-18 XBMCstubs were renamed to Kodistubs! Started to learn how to create XBMC Python addons, I came across xbmcstubs project and started using it. Then I've decided to update it with the most recent information from the latest XBMC Python docs and my personal experience. Currently Kodistubs are generated (indirectly) from Kodi source code so they pretty much exactly re-create Kodi Python API classes and functions. Now Kodistubs also include PEP-484 type annotations that provide information about actual arguments and return values of Kodi Python API functions and methods. What is this and why do you need it? Kodistubs are literally Python module stubs which mimic Kodi Python API modules. They contain all (hopefully) classes, methods, functions and constants declarations with docstrings, type annotations and minimal code not to raise syntax errors and basic exceptions. If you using some Python IDE (PyCharm, Eclipse+Pydev, Python Tools for Visual Studio, PyScripter etc.), you can add those modules to Python import paths of your current Kodi addon project, and you will get code auto-completion, code inspection (if your IDE/code editor supports it), and quick help that greatly facilitates writing addon code and reduces the number of errors. Where to add these stub modules in my IDE? Simply runĀ pip install Kodistubs to install Kodistubs into your project's virtual environment.Also it is strongly recommended to read Kodistubs documentation: http://romanvm.github.io/Kodistubs/ If you are documenting your code with Sphinx, this URL can also be used as intersphinx reference point for Kodi Python API. You can find the latest Kodi Python stub modules in my Github repo. Note: I try to keep Kodistubs in sync with Kodi Python API changes but it may happen that I miss something, so any comments, corrections, and pull requests are welcomed. Warning: those stub modules do not include any useful code so don't try to run/debug your addon directly from IDE, unless you add some debug code to them. They are meant only to help writing addon code. However, if you want to test your code outside Kodi (e.g. do unit testing), with Kodistubs you can use some Python mock library like mock or flexmock to mimic Kodi Python functions and classes. This will help you to eliminate at least some basic errors and bugs. RE: XBMCstubs re-worked (code auto-completion and quick help) - Roman_V_M - 2013-09-24 I've also added documentation for XBMC Python modules auto-generated from XBMCstubs docstrings: http://romanvm.github.io/xbmcstubs/docs This is the most up to date XBMC Python documentation, because, frankly speaking, official documentation pages are far from perfect (and Gotham docs are really messy at some places). Any comments or corrections are welcomed RE: XBMCstubs re-worked (code auto-completion and quick help) - jerimiah797 - 2013-09-25 This looks awesome! I can't wait to try it out. Do you know if there's anything similar for the domain-specific xml that xbmc uses? RE: XBMCstubs re-worked (code auto-completion and quick help) - Roman_V_M - 2013-09-25 (2013-09-25, 03:08)jerimiah797 Wrote: Do you know if there's anything similar for the domain-specific xml that xbmc uses? You mean auto-completion for XBMC skin files? I doubt such thing exists. With Python it's relatively simple due to full code introspection. RE: XBMCstubs re-worked (code auto-completion and quick help) - jerimiah797 - 2013-09-25 Yeah, I've only worked with xml in the context of xbmc files so i dont know that much about it. I'm wondering if there's an editor that supports some kind of xml dictionary so it can autocomplete only the tags that xbmc recognizes and flag tags that aren't in the 'dictionary'. RE: XBMCstubs re-worked (code auto-completion and quick help) - Dhorse - 2013-09-27 Could you tell me how i would add this to VS2012? I am still pretty new to this. RE: XBMCstubs re-worked (code auto-completion and quick help) - Roman_V_M - 2013-09-27 (2013-09-27, 17:21)Dhorse Wrote: Could you tell me how i would add this to VS2012? I am still pretty new to this. I guess by "VS2012" you really mean Python Tools for Visual Studio. You need to download a ZIP from Gighub, unpack it to a folder of your convenience and add the folder with stub .py files to "Search Paths" of your PTVS project. See the example below: RE: XBMCstubs re-worked (code auto-completion and quick help) - Martijn - 2013-09-27 can i ask if you found docstrings that needed fixing in xbmc source code? because you stated: Quote:because original docstrings include incorrect info in some cases. if yes can we perhaps expect a PR to fix these? RE: XBMCstubs re-worked (code auto-completion and quick help) - Roman_V_M - 2013-09-27 (2013-09-27, 20:25)Martijn Wrote: can i ask if you found docstrings that needed fixing in xbmc source code? I'm afraid, PR is not possible because the C++ files in question are not present on Github and are auto-generated during compilation. Those are: \xbmc\interfaces\python\generated\ AddonModuleXbmc.cpp AddonModuleXbmcaddon.cpp AddonModuleXbmcgui.cpp AddonModuleXbmcplugin.cpp AddonModuleXbmcvfs.cpp Also I need to note that to say that my C++ knowledge is very basic will be a great exaggeration. RE: XBMCstubs re-worked (code auto-completion and quick help) - Martijn - 2013-09-27 They are generated from the files located here: https://github.com/xbmc/xbmc/blob/master/xbmc/interfaces/legacy/ example: https://github.com/xbmc/xbmc/blob/master/xbmc/interfaces/legacy/Control.h#L417 https://github.com/xbmc/xbmc/blob/master/xbmc/interfaces/legacy/ModuleXbmc.h#L41 If you grep through those files finding the "wrong" text you will end up on the file containing that text. Edit: already started on some a while ago. need to finish it https://github.com/xbmc/xbmc/pull/3187 RE: XBMCstubs re-worked (code auto-completion and quick help) - Roman_V_M - 2013-09-28 2 Martijn Thanks for the explanation, I'll see what I can do. P. S. Added some screenshots to the OP. RE: XBMCstubs re-worked (code auto-completion and quick help) - Martijn - 2013-09-29 (2013-09-28, 15:24)Roman_V_M Wrote: 2 Martijn Thanks. Will appreciate it RE: XBMCstubs re-worked (code auto-completion and quick help) - jerimiah797 - 2013-10-01 I've tried out the stubs and they work in PyCharm, too. Here's how to install (per project, not globally) Open the project folder in PyCharm. Select Settings, then click 'Project Structure' under Project Settings. Then click '+ Add Content Root', browse to where you have put the folder containing the stub files, and select the folder. The stubs folder can be anywhere on your machine, it doesn't have to be in your project (skin, addon, script, whatever) folder. Then click 'Apply', and then 'Okay'. Thanks so much for this, Roman!!!! It's really saves a lot of time pouring over the pydocs and figuring out which methods can be used in a given context. -Jerimiah PS I'm working on the XML helper code and have made some progress defining the default xml namespace and associated tags and rules for an xbmc compliant window file. There are currently several methods to do this and I'm experimenting to find out the best way that doesn't confuse xbmc when it loads the xml files. So far, some methods don't work. I'll keep you posted. RE: XBMCstubs re-worked (code auto-completion and quick help) - Roman_V_M - 2013-10-02 2 jerimiah797 Thanks for the info. Could you also provide an example screenshot like the ones in the OP? I will update the OP with your info. BTW, I've changed docstrings structure in xbmcgui module to provide better tooltips. RE: XBMCstubs re-worked (code auto-completion and quick help) - jerimiah797 - 2013-10-02 Here you go! -Jerimiah |