Edgewall Software
Modify

Opened 15 years ago

Closed 15 years ago

#8931 closed defect (fixed)

Plugin auto-enable is too eager for plugins with sub-packages

Reported by: Remy Blank Owned by: Remy Blank
Priority: normal Milestone: 0.12
Component: general Version: 0.12dev
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

Plugins located in $ENV/plugins are auto-enabled in _enable_plugin() if there is no entry for each module in [components]. However, the check is too precise, and prevents e.g. disabling a whole plugin containing sub-packages with a single line in [components].

For example, adding the following line to [components] doesn't disable AccountManagerPlugin if it is installed in $ENV/plugins:

acct_mgr.* = disabled

Instead, all the various sub-packages have to be listed explicitly:

acct_mgr.admin.* = disabled
acct_mgr.api.* = disabled
acct_mgr.db.* = disabled
acct_mgr.htfile.* = disabled
acct_mgr.http.* = disabled
acct_mgr.notification.* = disabled
acct_mgr.pwhash.* = disabled
acct_mgr.svnserve.* = disabled
acct_mgr.web_ui.* = disabled

I suggest extending the check to include all parent packages:

  • trac/loader.py

    diff --git a/trac/loader.py b/trac/loader.py
    a b  
    2525
    2626from trac import __version__ as TRAC_VERSION
    2727from trac.util import get_doc, get_module_path, get_pkginfo
     28from trac.util.compat import any
    2829from trac.util.text import exception_to_unicode, to_unicode
    2930
    3031__all__ = ['load_components']
     
    4546def _enable_plugin(env, module):
    4647    """Enable the given plugin module by adding an entry to the configuration.
    4748    """
    48     if module + '.*' not in env.config['components']:
     49    parts = module.split('.')
     50    if not any('.'.join(parts[:i + 1]) + '.*' in env.config['components']
     51               for i in range(len(parts))):
    4952        env.config['components'].set(module + '.*', 'enabled')
    5053
    5154def load_eggs(entry_point_name):

Thoughts?

Attachments (1)

8931-auto-enable-r9002.patch (2.9 KB ) - added by Remy Blank 15 years ago.
Patch using the component rule cache.

Download all attachments as: .zip

Change History (7)

comment:1 by Christian Boos, 15 years ago

Use env.is_component_enabled(module)?

in reply to:  1 comment:2 by Remy Blank, 15 years ago

Replying to cboos:

Use env.is_component_enabled(module)?

You mean, instead of updating the config? I'll have to try that. I also thought that modifying the config was a bit of a hack.

comment:3 by Christian Boos, 15 years ago

Ah, no I meant doing if not env.is_component_enabled() instead of the if not any(...) - but that won't work alone as the env._rules will then get out of sync of the change done with config.set. But we could add an env.enable_component(module) method that will add that entry to env._rules.

in reply to:  3 comment:4 by Christian Boos, 15 years ago

Replying to cboos:

… add an env.enable_component(module) method that will add that entry to env._rules.

… and use that instead of config.set, i.e.

def _enable_plugin(env, module): 
    """Enable the given plugin module by adding an entry to the configuration. 
    """ 
    if not env.is_component_enabled(module):
        env.enable_component(module)

by Remy Blank, 15 years ago

Patch using the component rule cache.

comment:5 by Remy Blank, 15 years ago

Using the cache is a good idea, but _enable_plugin() should only enable a plugin if it wasn't disabled explicitly. env.is_component_enabled() currently doesn't provide this information. In the patch above, I made it return None if a component was neither enabled, nor disabled through a rule in [components] (and therefore is disabled implicitly).

This seems to work fine, but I'm not completely sure if this has other implications.

comment:6 by Remy Blank, 15 years ago

Resolution: fixed
Status: newclosed

Patch applied (with some docstring updates) in [9035].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Remy Blank.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Remy Blank to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.