Sublime Forum

Sublime_plugin.reload_plugin not completely reloading plugin?


Hi all,

Playing with an unpacked plugin for development and reloading things “by hand”.
What is the “expected” difference between the following ?:

os.utime(sys.modules['test.main'].__file__,None) # touch equivalent

It seems that when doing the touch equivalent sublime does a reload_plugin + something else …
My question could also be what is this “something else” ? (and is there an API for it ?)

Looking at randy3k/AutomaticPackageReloader, this seems to be related to load_dummy / Hack to trigger automatic "reloading plugins"

thanks for your time

toy example, :

import sublime_plugin
class test_command(sublime_plugin.ApplicationCommand):
    def __init__(self, *args, **kwargs):
        print("__init__    --------------->", hex(id(self.__class__)))
        super().__init__(*args, **kwargs)
    def run(self):
        print("run    --------------->", hex(id(self.__class__)))
print("module      --------------->", hex(id(test_command)))

console trace :

+++ import os,sys; os.utime(sys.modules[‘test.main’].file,None)
reloading plugin test.main
module ---------------> 0x7fa68ddb1a60
__ init__ ---------------> 0x7fa68ddb1a60
+++ sublime.run_command(‘test’)
run ---------------> 0x7fa68ddb1a60
+++ import sublime_plugin; sublime_plugin.reload_plugin(‘test.main’)
reloading plugin test.main
module ---------------> 0x7fa69264b000
+++ sublime.run_command(‘test’)
run ---------------> 0x7fa68ddb1a60. <== still using old test_command



You’re not really intended to invoke parts of the plugin machinery (e.g. sublime_plugin.reload_plugin()); Sublime automatically reloads plugins when they change on disk (or their modification changes) as seen above where your os.utime() touches the file and Sublime responds by saying it’s reloading the plugin.

Is there a reason you’re trying to manipulate the innards of the system directly?



Thanks for your reply.
you are correct : sublime_plugin.reload_plugin is not referenced in the documentation ; I was maybe over-adventurous in using an (undocumented) reload_plugin thinking it would “reload plugin” :wink:

Given that I was already partly reloading my plugin programmatically (aka doing imp.reload because of submodules), I was wondering if there was a programmatic way to reload the top-level plugin.
Note : the top-level plugin rarely changes (the implementations are in the submodules), so the touch on said top-level is purely to trigger reload.

I will happily touch my top-level module if that’s the only way to reload. Do you know of another way ?

Thanks again.



You can also use something like AutomaticPackageReloader



I faced similar issue, and since i use different editor i cannot use any plugin, so i wrote this little snippet which reloads even if rename/delete the file.
Plugin Reloder