I’m running the Plex server on my Synology NAS drive. I’ve found a bug in some channel code that I loaded. I’d like to fix it, but, I don’t know ho to go about debugging it. I’d like to walk through the code to make sure my suspicions are correct and that my fix actually works. Is there any way I can do that?
I have experience writing channels for Roku. I can connect a box, side load my code, and step through it to debug. Does the equivalent process exist for Plex?
I cannot speak to any specific issues using a NAS for your PMS and how that would affect updating code and pulling logs. But the best method of debugging is adding log statements to your code. And then pull up the channel log (or system log if it is an issue with the URL service or playback) to see the data and determine where and what the issue may be.
For example: try: my_variable = html.xpath('//@href')[0] except: Log('entered except statement') my_variable = None Log('the value of my_variable is %s' %my_variable)
@baradanikto I routinely debug my Plex channel code, but only on the local machine since this is also where my Plex Server is. It is most probably possible to remote debug as well, but that would require to set up Python debugger at the box and connect to it. I don’t think it’s necessary though, because if you want to debug your own Python code, it shouldn’t matter much where you run it.
Here’s a package that you could add to your channel as a git submodule, it’ll help to set up testing runtime environment, create and run unit tests for the channel code. The practical point is that once you’re able to run any function in your channel, you can also debug it using a standard Python debugger.
czukowski - your answer sounds interesting. Can you explain further? What steps do you take to debug the code? My intent is to debug the code using Visual Studio’s Python add-in. I’m running on Win 7, so, I can easily start the PMS for Windows locally. I’m just not sure how to connect the debugger to the PMS.
The key is you don’t run your channel from Plex Server, but bootstrap the Framework directly and load your channel code into its sandbox environment. Then it’s just a matter of calling a function you need. There must be quite a lot of paths added to PYTHONPATH though, you’ll need to figure out how to do it from Visual Studio (I use PyCharm and it requires some quirks to make it work - see the readme from that repo I linked, though maybe VS will have it simpler), I use Python interpreter shipped with Plex (PlexScriptingHost.exe - it’s just good old python.exe renamed). That repo actually works as a base for unit tests as I mentioned, and does most of the Framework initialization phase for you, so as for running it, it’s just a matter of creating a class inheriting from the base PlexTestCase, adding a few test methods that calls the functions you need (and optionally asserting the results) and then configuring Run or Debug command on the tests runner that comes with IDE.
Edit: Now that said, this unit testing base is far from mature as I’ve only used it in a few channels to streamline testing of the web pages parsing functions, so some adjustments may still be needed depending on your use cases.
@angeloavv this was meant to be a platform for testing plug-ins. I have a channel that I haven’t finished, but it has some tests that could serve as an example, see the Tests directory: