Sublime Forum

Sublime_plugin.reload_plugin not completely reloading plugin?

#1

Hi all,

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

sublime_plugin.reload_plugin("test.main")
vs
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
Regards,

toy example, main.py :

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

0 Likes

#2

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?

0 Likes

#3

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.

0 Likes

#4

You can also use something like AutomaticPackageReloader

0 Likes

#5

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

0 Likes