`load_resource()` fails if called in `plugin_loaded()`
Description of the bug
The load_resource() function fails loading resources from a sub directory of a package, when called directly in plugin_loaded() hook, while package is being enabled.
Steps to reproduce
- Start ST in SAFE MODE
- Create a Package named "Debug" in Data (Safe Mode)/Packages
- Add a child folder "py33" in "Debug".
- Add an empty "debug.json" with only an object
{}in it. - Add a plugin named "debug.py" in root of "Debug"
import sublime def plugin_loaded(): sublime.load_resource("Packages/Debug/py33/debug.json") - Add "Debug" to
"ignored_packages" - Remove it. -> Exception thrown.
Expected behavior
All resources of a package should be available and accessible in plugin_loaded() function.
Actual behavior
load_resource() thows FileNotFoundError on python 3.8 or OSError on python 3.3 plugin_host, if the resource to load is located in a sub directory of the package.
reloading python 3.3 plugin Debug.debug
Traceback (most recent call last):
File "C:\Apps\Sublime Text 40xx\Lib\python33\sublime_plugin.py", line 400, in load_module
m.plugin_loaded()
File "C:\Apps\Sublime Text 40xx\Data (Safe Mode)\Packages\Debug\debug.py", line 4, in plugin_loaded
sublime.load_resource("Packages/Debug/py33/debug.json")
File "C:\Apps\Sublime Text 40xx\Lib\python33\sublime.py", line 435, in load_resource
raise IOError('resource "%s" not found' % name)
OSError: resource "Packages/Debug/py33/debug.json" not found
It happens if the package is removed from "ignored_packages" list.
It does not happen when reloading happens due to saving/modifying the file.
Note: This issue can/must currently be worked around by calling any function which makes use of load_resource() via sublime.set_timeout().
Sublime Text build number
4134
Operating system & version
Windows
(Linux) Desktop environment and/or window manager
No response
Additional information
No response
OpenGL context information
No response
I face the same issue using sublime.find_resources in CommandsBrowser. I worked around it using the aliter described, calling it in sublime.set_timeout