Staring a new plugin.
Where do I put the python files for the plugin while I'm developing? Which folder in OctoPrint? Also, how do I get get OctoPrint to reload my plugin whenever my file has been modified?
Staring a new plugin.
Where do I put the python files for the plugin while I'm developing? Which folder in OctoPrint? Also, how do I get get OctoPrint to reload my plugin whenever my file has been modified?
There are many ways, I'm sure.
The way I develop a plugin is to begin with the cookiecutter as described here. I do this locally on my macOS workstation in a folder I might call OctoPrint-Something
.
I'll create a folder on the Pi (~/OctoPrint-Something
) and a shell script that will rsync things over to it which might look a bit like:
#!/bin/bash
rsync -avz --no-perms --exclude '.DS_Store' ~/OctoPrint-Something/ pi@octopi.local:~/OctoPrint-Something
In the local folder I'll do a git init
to track things.
On the Pi, I'll add an alias in the ~/.bashrc
file:
alias begin='source ~/oprint/bin/activate && cd ~/OctoPrint-Something'
...and add a script somewhere in my path there like the /usr/local/bin
folder...
#!/bin/sh
clear
cd ~/OctoPrint-Something
python setup.py develop
sudo service octoprint restart
tail -f ~/.octoprint/logs/octoprint.log
syncit
script which will synchronize the files over to the Pi which have changedssh
session to the Pi
begin
to activate the virtual environment and to put me in the correct folder on the Picycle
which will re-introduce the changes for my plugin to OctoPrint, restart it and tail the logThe cookiecutter application will scaffold things which should work well. You'll end up with something like:
My workflow involves a locally installed OctoPrint instance on my windows machine setup following the instructions here. I then do the same cookie cutter method linked by @OutsourcedGuru to create the framework for the plugin. Then once I have a point where I think I'm ready to test I zip up the contents of OctoPrint-Something
folder into a zip file and then install it via the plugin manager and see what breaks...lol.
So let me guess, no attaching a debugger then. Sigh.
I think I have seen ways of doing that here on the forum, but I personally have never used debuggers for my own development. That's why it probably takes me so long to program stuff.
Wow, developing without debugging, that's a "no go" for me!
Very interesting how each developer set up his/her environment.
See this thread for more approaches: Plugin development Tutorial Problem
My two cents about developing plugins:
I documented the IDE- and Plugin-Structure-Setup in my KnowledgeBase:
To me not using a debugger is like not washing hands after using the toilet; this is how bugs spread.
I was hoping Ollis (Olli?) would chime in.
I definitely need the actual hardware for my testing. I'm pushing all the boundaries of performance and cpu/gpu memory on this thing, GPIO, etc. After this month I should be able to share some photos when FormNext is over.
I'm an old programmer and my approach involves log feedback and manually forcing the tests of edge cases. If I had an AI to write automated test cases then I might trust that approach. What I usually see is that nobody has any time to focus on the test cases.
I know, it's crazy right? In my approach it requires a lot of installing/restarting, but on windows that doesn't take much time. I do actually debug, just not the traditional approach of using a debugger and depend on errors popping up in console. Probably because I program in Notepad++ rather than PyCharm. I tried setting that up once but never could get it to work right. I'll have to walk through @OllisGit's knowedgebase and see if I can get it to work.
I just started a conversion of old gamepad to cnc pendant by adding esp32 inside of it so I can telnet to duet3d board and control printer .. would be cool to have support for usb based gamepad on octoprint too
Well it turns out that Marlin has a new joystick feature. It's buggy (and unusable) but I think I can improve on it somewhat. No need to go through OctoPrint.