reloading custom package
reloading custom package
Is it possible to reload custom package? I can't seem to figure out a way to make changes in the custom package reflect in reloaded plugins. A server reboot works, but I'm wondering if theres a more obvious, better approach that I'm missing. Thanks.
Last edited by malt on Fri Jun 22, 2018 11:58 pm, edited 1 time in total.
Re: reloading custom package
I edited my post a bit to clear up ambiguity.
Thanks for the response. Would that work? - since sp seems to cache the version of the package that existed on in initial load. ie, if the package prints a message when you sp plugin load a plugin that imports it, and you delete the package, it'll print the message instead of ModuleNotFoundError
Thanks for the response. Would that work? - since sp seems to cache the version of the package that existed on in initial load. ie, if the package prints a message when you sp plugin load a plugin that imports it, and you delete the package, it'll print the message instead of ModuleNotFoundError
Re: reloading custom package
Yes, it should work. Can you show us your test code?
Re: reloading custom package
In plugins/testplugin/testplugin.py
in packages/custom/testlib/__init__.py
So when I initially enter sp plugin load testplugin, it loads successfully and prints "newest testlib imported". When I reload testplugin, the message no longer prints. This holds true even when I replace the testlib/__init__.py file. I'm guessing this is intended behavior, but is there a way around it? Sorry if this is really obvious.
Syntax: Select all
import testlib
in packages/custom/testlib/__init__.py
Syntax: Select all
print("newest testlib imported")
#print("even newer testlib imported")
So when I initially enter sp plugin load testplugin, it loads successfully and prints "newest testlib imported". When I reload testplugin, the message no longer prints. This holds true even when I replace the testlib/__init__.py file. I'm guessing this is intended behavior, but is there a way around it? Sorry if this is really obvious.
Re: reloading custom package
Like quartata mentioned reloading works fine:
The caching is done by Python itself via a dictionary (sys.modules).
If you delete the module and use the above code, you will get an error like this:
Syntax: Select all
import testlib
import importlib
importlib.reload(testlib)
If you delete the module and use the above code, you will get an error like this:
Code: Select all
[SP] Caught an Exception:
Traceback (most recent call last):
File "..\addons\source-python\packages\source-python\plugins\command.py", line 162, in load_plugin
plugin = self.manager.load(plugin_name)
File "..\addons\source-python\packages\source-python\plugins\manager.py", line 193, in load
plugin._load()
File "..\addons\source-python\packages\source-python\plugins\instance.py", line 74, in _load
self.module = import_module(self.import_name)
AttributeError: 'NoneType' object has no attribute 'name'
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 72 guests