PyCharm Restart Plugin Configuration

Posted on
Tue Mar 01, 2016 5:35 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

PyCharm Restart Plugin Configuration

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 9192 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!

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Apr 24, 2016 5:58 am
freshwuzhere offline
Posts: 105
Joined: Apr 05, 2012

Re: PyCharm Restart Plugin Configuration

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!

Posted on
Sun Apr 24, 2016 10:03 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: PyCharm Restart Plugin Configuration

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

Posted on
Mon Apr 25, 2016 9:35 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: PyCharm Restart Plugin Configuration

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.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jul 28, 2016 4:01 pm
Vig offline
Posts: 111
Joined: Oct 06, 2015

Re: PyCharm Restart Plugin Configuration

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?

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests