Page 1 of 1

PyCharm Restart Plugin Configuration

PostPosted: Tue Mar 01, 2016 5:35 pm
by jay (support)
For those of you using PyCharm for development, I thought I'd share how I get a plugin to restart from within PyCharm. First, you need this script:

Code: Select all
import sys, subprocess

print "sys.argv: %s " % str(sys.argv)
if len(sys.argv) != 2:
   print "Usage: restart_plugin.py /path/to/plugin/plugin.indigoPlugin\n"
else:
   plugin_id = sys.argv[1]
   print "calling restart_plugin with '%s'" % plugin_id
   plugin_script = '''plugin = indigo.server.getPlugin("%s")
if plugin.isEnabled():
   plugin.restart()
   return "Plugin %s restarted"
else:
   return "Plugin %s isn't enabled"
''' % (plugin_id, plugin_id, plugin_id)
   
   plugin_host_path = "/Library/Application Support/Perceptive Automation/Indigo 6/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost"
   subprocess.call([plugin_host_path, "-e", plugin_script])



Save it to your hard drive somewhere. I call it restart_plugin.py. Basically, it's a wrapper around an Indigo script to restart a plugin. Of course, Indigo Python scripts have to be run in a IndigoPluginHost process, not a regular Python interpreter. So, the script just takes a plugin ID from the command line, substitutes it into the Indigo Python script, and executes it from the IndigoPluginHost process.

Once you have it saved somewhere, open your plugin in PyCharm and create a run configuration by selecting the Run->Edit Configurations menu item. You'll get the Run/Debug Configurations dialog:

ss81.png
ss81.png (97.48 KiB) Viewed 9296 times


You probably won't have any configurations, so you'll just see Defaults in the left outline view. Click the "+" button above that outline view, and select the Python option from the list. That will create an Unnamed configuration. On the right side, give it a name (I call mine restart_plugin), then click the "..." button after the Script label and select the file you created above. Insert your plugin's ID into the Script parameters field. Finally, from the Python interpreter field, select the Python 2.7 (or 2.6) interpreter. Apply and OK the dialog. Now, in the icon bar at the top right, you should see your configuration in the popup beside the run and debug buttons. Click the run button and it'll restart your plugin.

Have fun!

Re: PyCharm Restart Plugin Configuration

PostPosted: Sun Apr 24, 2016 5:58 am
by freshwuzhere
Hi Jay,

Realise this is a little old but thanks! I use Pycharm every day now at work and home (with indigo) and I first heard about it here. This is a great tip thank you. Would appreciate any other useful dev tricks also!

Re: PyCharm Restart Plugin Configuration

PostPosted: Sun Apr 24, 2016 10:03 pm
by kw123
One thing to be aware of:
If you click the run button twice quickly it will start the plugin twice sometimes. That will create a big mess. To stop it you need to
- disable plugin,
- stop indigo server
- delete plugin in enabled directory ( there is a fragment of the plugin left)
- restart server
- restart plugin

Jay could we add an if ... To prevent this from happening. Don't know what the condition should be

Karl


Sent from my iPhone using Tapatalk

Re: PyCharm Restart Plugin Configuration

PostPosted: Mon Apr 25, 2016 9:35 am
by jay (support)
kw123 wrote:
Jay could we add an if ... To prevent this from happening. Don't know what the condition should be


Yeah, me neither. I'll leave it to those who experience the problem to come up with a script mod... :twisted:

We'll look into the server side to see if there's something we can do there.

Re: PyCharm Restart Plugin Configuration

PostPosted: Thu Jul 28, 2016 4:01 pm
by Vig
jay (support) wrote:
For those of you using PyCharm for development, I thought I'd share how I get a plugin to restart from within PyCharm. First, you need this script:
[code]import sys, subprocess
print "sys.argv: %s " % str(sys.argv)
......


Is there a way to restart the Indigo server from a script or command line?