Make ExtensionHooks easier to implement and manage.
Review Request #7680 — Created Oct. 7, 2015 and submitted
ExtensionHook
s have always been pretty simple. Constructing them will
initialize them, shutting down will permanently destroy them, and
subclasses only needed to override__init__()
andshutdown()
. This was
almost too simple.Once destroyed, a hook had to be re-constructed in order to be
re-enabled, invalidating any signal connections that may exist or other
registered data. Extensions that needed finer-grained state management
had to do it entirely within the hook through its own custom
enabled/disabled states, which still left them initialized and
registered on the extension.This change improves this in a couple key ways. First, initialization
can now live ininitialize()
, which does not need to call the parent
method (unless inheriting from anotherExtensionHook
that defines
initialize()
). The shutdown code inshutdown()
no longer needs to call
the parent method either.
ExtensionHook
s can be disabled by callingdisable_hook()
, and then
re-enabled (with new state) by callingenable_hook()
. The instance will
remain around, but the hook's registration and state will be properly
handled. The hook can also be instantiated withstart_enabled=False
to
create the hook instance without enabling it, allowing the extension to
do that later in its process.Along with all this, I've fleshed out the docs quite a bit.
Djblets and Review Board unit tests pass.
Description | From | Last Updated |
---|---|---|
This patch is marked for release-0.10.x. |
brennie | |
No comma after otherwise. |
brennie | |
0.10? |
brennie | |
You don't need pass with a docstring. |
brennie | |
0.10? |
brennie | |
0.10 |
brennie | |
"Enables" is the wrong tense. |
AD adriano | |
"re-constructing" -> "reconstructing". |
AD adriano | |
This is not a list. |
brennie | |
This is not a list. |
brennie | |
Not a list. |
brennie | |
Not a list. |
brennie | |
Does this render correctly? If not, we should put 'This attribute is optional.' in the description instead of here. |
brennie | |
Same here. |
brennie | |
Here, too. |
brennie | |
And here. |
brennie | |
And here. |
brennie |
-
Tool: Pyflakes Processed Files: docs/djblets/conf.py djblets/extensions/extension.py djblets/extensions/hooks.py djblets/extensions/tests.py Tool: PEP8 Style Checker Processed Files: docs/djblets/conf.py djblets/extensions/extension.py djblets/extensions/hooks.py djblets/extensions/tests.py
- Change Summary:
-
Updated some of the docs to call out optional parameters and fix typos.
-
Tool: Pyflakes Processed Files: docs/djblets/conf.py djblets/extensions/extension.py djblets/extensions/hooks.py djblets/extensions/tests.py Tool: PEP8 Style Checker Processed Files: docs/djblets/conf.py djblets/extensions/extension.py djblets/extensions/hooks.py djblets/extensions/tests.py