def test_get_module_metadata_keyword_expansion(self): version = '10' url = 'http://example.org' modname = self._write_module('$Rev: %s $' % version, '$URL: %s $' % url) mod = importlib.import_module(modname) info = util.get_module_metadata(mod) self.assertEqual('r%s' % version, info['version']) self.assertEqual(url, info['home_page'])
def test_get_module_metadata(self): version = '0.1' home_page = 'http://example.org' modname = self._write_module(version, home_page) mod = importlib.import_module(modname) info = util.get_module_metadata(mod) self.assertEqual(version, info['version']) self.assertEqual('Joe', info['author']) self.assertEqual('*****@*****.**', info['author_email']) self.assertEqual('Jim', info['maintainer']) self.assertEqual('*****@*****.**', info['maintainer_email']) self.assertEqual(home_page, info['home_page']) self.assertEqual('summary.', info['summary']) self.assertEqual('BSD 3-Clause', info['license']) self.assertEqual('http://my.trac.com', info['trac'])
def get_plugin_info(env, include_core=False): """Return package information about Trac core and installed plugins.""" path_sources = {} def find_distribution(module): name = module.__name__ path = get_module_path(module) sources = path_sources.get(path) if sources is None: sources = path_sources[path] = get_sources(path) dist = sources.get(name.replace('.', '/') + '.py') if dist is None: dist = sources.get(name.replace('.', '/') + '/__init__.py') if dist is None: # This is a plain Python source file, not an egg dist = pkg_resources.Distribution(project_name=name, version='', location=module.__file__) return dist plugins_dir = env.plugins_dir plugins = {} for component in ComponentMeta._components: module = sys.modules[component.__module__] dist = find_distribution(module) plugin_filename = None if os.path.realpath(os.path.dirname(dist.location)) == plugins_dir: plugin_filename = os.path.basename(dist.location) if dist.project_name not in plugins: readonly = True if plugin_filename and os.access(dist.location, os.F_OK + os.W_OK): readonly = False # retrieve plugin metadata info = get_pkginfo(dist) version = dist.version if info: # Info found; set all those fields to "None" that have the # value "UNKNOWN" as this is the value for fields that # aren't specified in "setup.py" for k in info: if info[k] == 'UNKNOWN': info[k] = '' else: # Must be encoded as unicode as otherwise Genshi # may raise a "UnicodeDecodeError". info[k] = to_unicode(info[k]) else: info = get_module_metadata(module) version = info['version'] plugins[dist.project_name] = { 'name': dist.project_name, 'version': version, 'path': dist.location, 'plugin_filename': plugin_filename, 'readonly': readonly, 'info': info, 'modules': {}, } modules = plugins[dist.project_name]['modules'] if module.__name__ not in modules: summary, description = get_doc(module) plugins[dist.project_name]['modules'][module.__name__] = { 'summary': summary, 'description': description, 'components': {}, } full_name = module.__name__ + '.' + component.__name__ summary, description = get_doc(component) c = component if c in env and not issubclass(c, env.__class__): c = component(env) modules[module.__name__]['components'][component.__name__] = { 'full_name': full_name, 'summary': summary, 'description': description, 'enabled': env.is_component_enabled(component), 'required': getattr(c, 'required', False), } if not include_core: for name in list(plugins): if name.lower() == 'trac': plugins.pop(name) return sorted(plugins.itervalues(), key=lambda p: (p['name'].lower() != 'trac', p['name'].lower()))