randy3k / AutomaticPackageReloader

Automatically reload submodules while developing a Sublime Text package.
MIT License
38 stars 13 forks source link

Question regarding `plugin_loaded()` method #1

Closed jcberquist closed 8 years ago

jcberquist commented 8 years ago

When reloading submodules does/can this call plugin_loaded() if it is present?

randy3k commented 8 years ago

why not trying yourself? (and the answer is yes).

jcberquist commented 8 years ago

Sorry if I wasn't clear. It seems to me that if a .py file containing a plugin_loaded() function is in a package subfolder, and is reloaded by this plugin, plugin_loaded() isn't called on the reload. (And it is called by ST on initial package load.)

I asked the way I did because I don't understand what you are doing well enough to know for sure what is and isn't happening :)

randy3k commented 8 years ago

I don't think plugin_loaded() in .py file inside a subfolder will be ever loaded in the first place. The .py file should be at the top level.

Consider this

(rmbpro)-Packages$ tree Test
Test
└── bar
    └── __init__.py

1 directory, 1 file
(rmbpro)-Packages$ cat Test/bar/__init__.py 
def plugin_loaded():
    print("foo")
jcberquist commented 8 years ago

Thanks for looking at this. If you have a top level file that imports bar, so:

Test
└── bar
    └── __init__.py
└── testme.py

testme.py:

from . import bar

plugin_loaded() in bar/__init__.py will be called when ST first loads.

Maybe that's a crazy structure? :smile: But at any rate, that is what I was hoping could happen on reload.

randy3k commented 8 years ago

Oh, I think it is an issue of Sublime Text itself.

https://github.com/twolfson/sublime-files/blob/441067288c2e035cf05295a79e3f8385ac5d0f77/sublime_plugin.py

Check the difference between reload_plugin and on_api_ready.

on_api_ready is launched at startup and finds all plugin_loaded.

reload_plugin is used to reload top level plugins, e.g., reload_plugin("Test.testme") and only reload plugin_loaded in testme.py.

My suggestion is to rename all plugin_loaded in subdir to something and export the calls to top level to execute them

from .bar import call1
from .foo import call2

def plugin_loaded():
     call1()
     call2()
jcberquist commented 8 years ago

Makes sense, and thanks for explaining it to me!