Improve submodule reloading#61
Conversation
1d05891 to
7adde96
Compare
This commit provides a change to clear the sys.modules cache before importing any local package/module. This causes python to reload all modules as soon as the FileManager.py is reloaded/imported by ST. It is to ensure fluent plugin updates even if global variables or module names change. Nothing else is needed to instantly update all submodules during development but saving the FileManager.py This strategy is used by `A File Icon` and `GitGutter` for instance.
|
Nice, I agree that reloading needed to be better in FileManager. Though, is there an idiomatic way to reload import os
import sys
import imp
import sublime_plugin
def reload_filemanager(view):
file_name = view.file_name()
assert file_name is not None, "post save and file_name is None?"
if "FileManager.FileManager" not in sys.modules:
print("FileManager not loaded, no reloading")
if not file_name.endswith(".py"):
return
filemanager_root = os.path.join(sublime.packages_path(), "FileManager")
if filemanager_root not in file_name:
return
imp.reload(sys.modules["FileManager.FileManager"])
class Hooks(sublime_plugin.EventListener):
def on_post_save(self, view):
reload_filemanager(view)Thoughts? Neat PR once more |
|
I personally use the AutomaticPackageReloader to reload submodules during development instead of hacking around something new for each plugin. I am not sure whether calling The trick with this PR is to clear the cache while ST is reloading the FileManager.py, so python reimports all submodules in the correct order to make sure all references are updated correctly. Your hook would need to call |
This commit provides a change to clear the sys.modules cache before
importing any local package/module. This causes python to reload all
modules as soon as the FileManager.py is reloaded/imported by ST.
It is to ensure fluent plugin updates even if global variables or
module names change.
Nothing else is needed to instantly update all submodules during
development but saving the FileManager.py
This strategy is used by
A File IconandGitGutterfor instance.