Home Download Buy Blog Forum Support

Auto reloading of python module files used by plugin

Auto reloading of python module files used by plugin

Postby pixelami on Tue Apr 10, 2012 6:23 pm

Hi all,

I am developing a plugin and trying to develop it in a modular way...
... so I have a top level python plugin file e.g MyPlugin.py in my Packages/MyPlugin/ folder.
MyPlugin.py imports python modules from a sub folder e.g. Packages/MyPlugin/mypymodule

After editing and saving MyPlugin.py the plugin is reloaded and I am able to test it straight away in Sublime Text 2.
My python modules are imported correctly and all works fine at first glance.

However, after editing and saving one of my module.py files located in the Packages/MyPlugin/mypymodule, the changes are not picked up in the same way as a change to MyPlugin.py. Even if I then make some change to MyPlugin.py and save it - the changes made to the modules are still not picked up, even though Sublime Text does reload MyPlugin.py.

So far the only workaround I have is to close Sublime Text and re-open it, which will soon become a complete PITA.

I had a quick search but didn't find anything useful on the subject, but I feel I can't be the only person to have run into this problem.
If anybody has a tip or better workaround, I'd be Grateful to know about it.

Is there some way to force a recompile / reload of the modules ?

Thanks.
pixelami
 
Posts: 3
Joined: Tue Apr 10, 2012 6:01 pm

Re: Auto reloading of python module files used by plugin

Postby nick. on Tue Apr 10, 2012 9:50 pm

I'm not terribly knowledgeable on the subject, but have you tried deleting the *.pyc files?
nick.
 
Posts: 266
Joined: Wed Jan 18, 2012 3:45 am

Re: Auto reloading of python module files used by plugin

Postby Esente on Wed Apr 11, 2012 2:11 am

I also have similar issue. However, my plugin is supposed to connect to a server, but it only runs once, then it stops connecting.

I can see in the console that plugins are reloading, but it has no effect at all.
Esente
 
Posts: 26
Joined: Mon Aug 16, 2010 7:20 pm

Re: Auto reloading of python module files used by plugin

Postby pixelami on Wed Apr 11, 2012 5:59 am

Thanks for the responses,

@Nick,
Yes I tried deleting the *.pyc files, and interestingly they did not seem to get recreated.
I then opened a terminal in the module folder and explicitly ran 'python myPluginModule.py' which did recreate the .pyc , but Sublime Text did not seem to be using this new version.

I suspect once the modules are loaded into ST2's embedded python interpreter they are just sitting in RAM.

I did some more Googling and found this
http://docs.python.org/library/function ... oad#reload
http://stackoverflow.com/questions/4375 ... hon-module
I'm thinking that maybe during development, the main MyPlugin.py could use reload inside an on_activated event callback method.
I'll give it a try and update this post.
pixelami
 
Posts: 3
Joined: Tue Apr 10, 2012 6:01 pm

Re: Auto reloading of python module files used by plugin

Postby wbond on Wed Apr 11, 2012 3:37 pm

If you look at SVN.py in the SVN package, or SFTP.py in the SFTP package, I use reloading so that I can actively develop in Sublime without having to constantly restart. Depending on the complexity of your dependencies, you may have to do a little work to make sure they are all reloaded in the right order.
wbond
 
Posts: 528
Joined: Mon Feb 28, 2011 5:33 am

Re: Auto reloading of python module files used by plugin

Postby pixelami on Thu Apr 12, 2012 7:31 pm

Thanks wbond !

That was just what I needed. :D
I had almost got there with something along those lines but there were 2 vital bits that I was missing.

if mod.startswith("hxutil") and sys.modules[mod] != None:

and I think reloading the modules in a specific order has helped too.

Many thanks.
pixelami
 
Posts: 3
Joined: Tue Apr 10, 2012 6:01 pm


Return to Plugin Development

Who is online

Users browsing this forum: Exabot [Bot] and 10 guests