Sublime Forum

Hot update without restarting sublime

#1

Sublime scans and reloads only modified python files in the root directory of plugin, and don’t bother to check subfolders (in my case utilities).
Modifications in subfolders do not trigger module reloading that uses plugin_reloaded(), and plugin still gets utilities from pycache.

What’s a proper way to handle this situation?
I think about magic number (sha1) that should be changed with subfolders and every root module should declare it.

0 Likes

#2

That would be very useful for package development indeed.

Currently you need to use imp.reload to explicitly reload all modules in subfolders (which I recommend to do with everything that does not directly define interface classes for ST, i.e. does not import sublime_plugin).

Here is how Package Control does it:
github.com/wbond/package_contro … y#L98-L108
github.com/wbond/package_contro … eloader.py

0 Likes

#3

Sure in plugin_reloaded() resides imp.reload(util_module_in_subfolder).

I checked package control actions and now I also toggling “ignored_packages” list (add package name, copy package, delete package name).

For unzipped package in <data_path>/Packages works fine.

For zipped package in <data_path>/Installed Packages from time to time I get exceptions:

reloading plugin debug_sv_deploy.__init__ Traceback (most recent call last): File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 74, in reload_plugin m = importlib.import_module(modulename) File "./importlib/__init__.py", line 90, in import_module File "<frozen importlib._bootstrap>", line 1584, in _gcd_import File "<frozen importlib._bootstrap>", line 1565, in _find_and_load File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked zipimport.ZipImportError: bad local file header in C:\Users\max\AppData\Roaming\Sublime Text 3\Installed Packages\debug_sv_deploy.sublime-package
or

reloading plugin SystemVerilog.verilog_completion Traceback (most recent call last): File "c:\Program Files\Sublime Text 3\sublime_plugin.py", line 116, in reload_plugin m.plugin_loaded() File "verilog_completion in C:\Users\max\AppData\Roaming\Sublime Text 3\Installed Packages\SystemVerilog.sublime-package", line 16, in plugin_loaded File "./imp.py", line 276, in reload zipimport.ZipImportError: bad local file header in C:\Users\max\AppData\Roaming\Sublime Text 3\Installed Packages\SystemVerilog.sublime-package

0 Likes

#4

I also received the bad local file header a few times but not reliably reproducable. It usually goes away after a ST restart.

0 Likes

#5

Restarting sublime is a remedy, but hot updates through package control can give a bad user experience. At first I start to blame package control, after some debugging came to idea that smth wrong with zipimport and cache. So I’m considering to use .no-sublime-package. Still imp.reload() can give nasty affects (like zombie objects).

0 Likes

#6

what do you mean by “hot updates via package control”?

from the code @gotcha pointed to I created such a command

class ReloadCommand(sublime_plugin.WindowCommand):
    def run(self):
        logger.log.info("reload")
        import sys
        from imp import reload
        for module in sys.modules.keys():
            if "MY_PLUGIN_DIR" in module:
                reload(sys.modules[module])
        logger.log.info("reload DONE")

and it works really well
but once, after I did this, some parts of my .py file were not loaded at all, only restart sublime helped

not sure if this is what you meant
is there any other way to force sublime to reload entire plugin?

0 Likes

#7

see also



0 Likes

#8

Forgive me for the advertisement. Try https://github.com/randy3k/AutomaticPackageReloader

3 Likes