Make ExtensionHooks easier to implement and manage.

Review Request #7680 — Created Oct. 7, 2015 and submitted

Information

Djblets
release-0.10.x

Reviewers

ExtensionHooks have always been pretty simple. Constructing them will
initialize them, shutting down will permanently destroy them, and
subclasses only needed to override __init__() and shutdown(). 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 in initialize(), which does not need to call the parent
method (unless inheriting from another ExtensionHook that defines
initialize()). The shutdown code in shutdown() no longer needs to call
the parent method either.

ExtensionHooks can be disabled by calling disable_hook(), and then
re-enabled (with new state) by calling enable_hook(). The instance will
remain around, but the hook's registration and state will be properly
handled. The hook can also be instantiated with start_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.

brenniebrennie

No comma after otherwise.

brenniebrennie

0.10?

brenniebrennie

You don't need pass with a docstring.

brenniebrennie

0.10?

brenniebrennie

0.10

brenniebrennie

"Enables" is the wrong tense.

AD adriano

"re-constructing" -> "reconstructing".

AD adriano

This is not a list.

brenniebrennie

This is not a list.

brenniebrennie

Not a list.

brenniebrennie

Not a list.

brenniebrennie

Does this render correctly? If not, we should put 'This attribute is optional.' in the description instead of here.

brenniebrennie

Same here.

brenniebrennie

Here, too.

brenniebrennie

And here.

brenniebrennie

And here.

brenniebrennie
reviewbot
  1. 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
    
    
  2. 
      
brennie
  1. 
      
  2. djblets/extensions/hooks.py (Diff revision 1)
     
     
    Show all issues

    This patch is marked for release-0.10.x.

  3. djblets/extensions/hooks.py (Diff revision 1)
     
     
    Show all issues

    No comma after otherwise.

  4. djblets/extensions/hooks.py (Diff revision 1)
     
     
    Show all issues

    0.10?

  5. djblets/extensions/hooks.py (Diff revision 1)
     
     
    Show all issues

    You don't need pass with a docstring.

    1. We don't need it, but it communicates intent, that "we know there's no code here, just docs." Same reason I always put a break; after the last case in a switch.

  6. djblets/extensions/hooks.py (Diff revision 1)
     
     
    Show all issues

    0.10?

  7. djblets/extensions/hooks.py (Diff revision 1)
     
     
    Show all issues

    0.10

  8. 
      
chipx86
reviewbot
  1. 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
    
    
  2. 
      
brennie
  1. Ship It!
  2. 
      
AD
  1. 
      
  2. djblets/extensions/hooks.py (Diff revision 2)
     
     

    An opportunity to use (bool, optional).

  3. djblets/extensions/hooks.py (Diff revision 2)
     
     
    Show all issues

    "Enables" is the wrong tense.

  4. djblets/extensions/hooks.py (Diff revision 2)
     
     
    Show all issues

    "re-constructing" -> "reconstructing".

  5. djblets/extensions/hooks.py (Diff revision 2)
     
     

    Another opportunity for (bool, optional).

  6. djblets/extensions/hooks.py (Diff revision 2)
     
     

    Another opportunity for (list, optional).

  7. djblets/extensions/hooks.py (Diff revision 2)
     
     

    Another opportunity for (object or class, optional).

  8. djblets/extensions/hooks.py (Diff revision 2)
     
     

    Another opportunity for (bool, optional).

  9. djblets/extensions/hooks.py (Diff revision 2)
     
     

    Another opportunity for (unicode, optional).

  10. djblets/extensions/hooks.py (Diff revision 2)
     
     

    Another opportunity for (list, optional).

  11. 
      
mike_conley
  1. I think this will close issue 3731.

  2. 
      
chipx86
reviewbot
  1. 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
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
brennie
  1. 
      
  2. djblets/extensions/hooks.py (Diff revision 3)
     
     
    Show all issues

    This is not a list.

    1. Not a list in the data type sense, but a list in the "list of arguments" sense. The fact that these are tuple are internal details, but any list coming in as an argument in the form of *mylist becomes a tuple anyway. Officially, this is called a "variable length argument list," so I think the usage is okay here.

  3. djblets/extensions/hooks.py (Diff revision 3)
     
     
    Show all issues

    This is not a list.

  4. djblets/extensions/hooks.py (Diff revision 3)
     
     
    Show all issues

    Not a list.

  5. djblets/extensions/hooks.py (Diff revision 3)
     
     
    Show all issues

    Not a list.

  6. djblets/extensions/hooks.py (Diff revision 3)
     
     
    Show all issues

    Does this render correctly? If not, we should put 'This attribute is optional.' in the description instead of here.

    1. It does not, but many things we want to do don't. I'm planning to do some work to replace napolean with something that offers more choices like this. (This is also what others out there seem to be using for optional arguments, and it's handy information to have.)

  7. djblets/extensions/hooks.py (Diff revision 3)
     
     
    Show all issues

    Same here.

  8. djblets/extensions/hooks.py (Diff revision 3)
     
     
    Show all issues

    Here, too.

  9. djblets/extensions/hooks.py (Diff revision 3)
     
     
    Show all issues

    And here.

  10. djblets/extensions/hooks.py (Diff revision 3)
     
     
    Show all issues

    And here.

  11. 
      
chipx86
reviewbot
  1. 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
    
    
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-0.10.x (7648acc)