Edgewall Software

Ticket #2638: sitewide-plugins.diff

File sitewide-plugins.diff, 4.6 KB (added by athomas, 3 years ago)

Patch implementing of site-wide plugins against r3147

  • setup.py

     
    3636         htdocs_dir = os.path.join(self.prefix, 'share', 'trac', 'htdocs') 
    3737         wiki_dir = os.path.join(self.prefix, 'share', 'trac', 'wiki-default') 
    3838         macros_dir = os.path.join(self.prefix, 'share', 'trac', 'wiki-macros') 
     39         plugins_dir = os.path.join(self.prefix, 'share', 'trac', 'plugins') 
    3940         f = open(_p('trac/siteconfig.py'), 'w') 
    4041         f.write(""" 
    4142# PLEASE DO NOT EDIT THIS FILE! 
     
    4647__default_htdocs_dir__ = %(htdocs)r 
    4748__default_wiki_dir__ = %(wiki)r 
    4849__default_macros_dir__ = %(macros)r 
     50__default_plugins_dir__ = %(plugins)r 
    4951 
    5052""" % {'trac': PACKAGE, 'ver': VERSION, 'conf': _p(conf_dir), 
    5153       'templates': _p(templates_dir), 'htdocs': _p(htdocs_dir), 
    52        'wiki': _p(wiki_dir), 'macros': _p(macros_dir)}) 
     54       'wiki': _p(wiki_dir), 'macros': _p(macros_dir), 
     55       'plugins': _p(plugins_dir)}) 
    5356         f.close() 
    5457 
    5558         # Run actual install 
  • trac/loader.py

     
    1818import imp 
    1919import os 
    2020import sys 
     21from trac.config import default_dir 
    2122try: 
    2223    set 
    2324except NameError: 
     
    3233 
    3334def load_components(env): 
    3435    loaded_components = [] 
    35     plugins_dir = os.path.normcase(os.path.realpath(os.path.join(env.path, 
    36                                                                  'plugins'))) 
     36    plugins_dirs = [os.path.normcase(os.path.realpath(os.path.join(env.path, 
     37                                                                 'plugins'))), 
     38                    default_dir('plugins')] 
    3739 
    3840    # First look for Python source files in the plugins directory, which simply 
    3941    # get imported, thereby registering them with the component manager if they 
    4042    # define any components 
    41     plugin_files = glob(os.path.join(plugins_dir, '*.py')) 
    42     for plugin_file in plugin_files: 
    43         try: 
    44             plugin_name = os.path.basename(plugin_file[:-3]) 
    45             if plugin_name not in loaded_components: 
    46                 env.log.debug('Loading plugin %s from %s' % (plugin_name, 
    47                                                              plugin_file)) 
    48                 module = imp.load_source(plugin_name, plugin_file) 
    49                 loaded_components.append(plugin_name) 
    50                 env.config.setdefault('components', plugin_name + '.*', 
    51                                       'enabled') 
    52         except Exception, e: 
    53             env.log.error('Failed to load plugin from %s', plugin_file, 
    54                           exc_info=True) 
     43    for plugins_dir in plugins_dirs: 
     44        plugin_files = glob(os.path.join(plugins_dir, '*.py')) 
     45        for plugin_file in plugin_files: 
     46            try: 
     47                plugin_name = os.path.basename(plugin_file[:-3]) 
     48                if plugin_name not in loaded_components: 
     49                    env.log.debug('Loading plugin %s from %s' % (plugin_name, 
     50                                                                 plugin_file)) 
     51                    module = imp.load_source(plugin_name, plugin_file) 
     52                    loaded_components.append(plugin_name) 
     53                    env.config.setdefault('components', plugin_name + '.*', 
     54                                          'enabled') 
     55            except Exception, e: 
     56                env.log.error('Failed to load plugin from %s', plugin_file, 
     57                              exc_info=True) 
    5558 
    5659    # If setuptools is installed try to load any eggs from the plugins 
    5760    # directory, and also plugins available on sys.path 
    5861    if pkg_resources is not None: 
    5962        ws = pkg_resources.working_set 
    60         ws.add_entry(plugins_dir) 
    61         pkg_env = pkg_resources.Environment([plugins_dir] + sys.path) 
     63        for plugins_dir in plugins_dirs: 
     64            ws.add_entry(plugins_dir) 
     65        pkg_env = pkg_resources.Environment(plugins_dirs + sys.path) 
    6266 
    6367        memo = set() 
    6468        def flatten(dists): 
     
    113117 
    114118            if modules: 
    115119                # Automatically enable any components provided by plugins 
    116                 # loaded from the environment plugins directory. 
    117                 if os.path.dirname(egg.location) == plugins_dir: 
     120                # loaded from the environment and site-wide plugins directory. 
     121                if os.path.dirname(egg.location) in plugins_dirs: 
    118122                    for module in modules: 
    119123                        env.config.setdefault('components', module + '.*', 
    120124                                              'enabled')