Plugin Development with Visual Studio 2019

Hi,

I want to create a new Octoprint Plugin with Visual Studio 2019.
I've got everything setup (clone, virtualenv an $ pip install -e .[develop,plugins]) and can start octoprint via command line from within Visual Studio with success.
But starting with debugging in Visual Studio doesn't work. It always throws an exception with the message: "module 'logging' has no attribute 'Filter'" in filters.py at "class TornadoAccessFilter(logging.Filter):"

Could anyone please help me before I lose my mind with python development!?
Am I missing some command line arguments?

Thanks!

Ok I got it running. The solution is very simple: To debug octoprint in Visual Studio 2019 you need to use the file \Scripts\octoprint-script.py as start-file. And you should use the legacy debugger, because otherwise VS will break at any exception even if they are intended.

2 Likes

Sorry for the necro posting, but this is interesting !

When coding for OctoPrint in Python, do you develop locally or remotely ? (are OctoPrint and the scripts running on the PC or on the RasPi) ?
What Python development components did you install ?

Did not know it could be done. Just seen this after reading your post : Debug Python code on remote Linux computers - Visual Studio (Windows) | Microsoft Docs

My VS project ("solution") includes two projects (a Raspi service, and a shield with a embeded STM32 I program using VisualMicro, both coded in C++). I'd love to work and debug remotely on the OctoPrint side, instead of using Samba shares with root access and PuTTY...

(I'd also super happy if some WYSIWYG add on for jinja existed)

I think remote debugging is one of the benefits of using Visual Code over pyCharm. I believe @Charlie_Powell has set this up in the past for his ws281x plugin.

Relevant article about Visual Studio Code & Remote SSH - I have used both VS Code and PyCharm, but you either have to pay or get an open source license to use PyCharm Pro.

Developing on Remote Machines using SSH and Visual Studio Code

I was asking about Visual Studio 2019.
I don't really use VSCode (except for compiling Marlin), and I've been using VS (formerly VC++) for nearly 3 decades. Much more comfortable with this IDE. Reason why I am excited about this thread : VS2019 + C++ Linux tools work a treat ! Should be the same with Python...
But I don't understand what the OP did... At first I don't have this file anywhere in the scripts directories or along with HelloWorld !

I tried using pyCharm one year ago. Epic fail !

The scripts folder and octoprint-script.py file referenced would be inside of the python venv you created and installed OctoPrint into.

And yes, there is a huge difference between VS2019 (or any VS for that matter) and VS Code.

I've been using it for a similar amount of time, however, I would say it's worth giving vscode a chance in this case. Or any other dev environment, for that matter (Pycharm, etc.) While VS certainly has certain workflows that work well, if you are familiar with them at least, I find that vscode integrates all of the different language features and technologies in a project like an octoprint plugin much better.

Instead of trying to get VS to work with a workflow it wasn't designed for, like debugging Python, you can install extensions in vscode specifically designed for the task at hand.

I suspect something is broken on my Pi... (can't find the virtual environments, but HelloWorld! is working with what I aready added to). Can't remember...

I tried installing Python and Python web exensions for VS2019, but the download failed, and I had to repair VS !

Finally, reading some plugin sources (jinja2 files and init.py), and only needing data bindings, I was able to understand how it works and code what I need, just ctrl-C-ing ctrl-V-ing a dozen controls in files over Samba shares. No debugging needed. Without reading any jinja tutorial or reference. I'm sure that learning how to use a framework would have taken much more time. At least for very basic plugins, it is amazingly easy.