From cb17b350caf9e113b7a3a36c5add5d16a88ea46d Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 20 Aug 2014 09:47:21 -0400 Subject: Rename extensions to plugins, since extensions reminds me of parts of filenames --HG-- rename : coverage/extension.py => coverage/plugin.py --- coverage/config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'coverage/config.py') diff --git a/coverage/config.py b/coverage/config.py index 064bc1ca..1826e5c2 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -140,7 +140,7 @@ class CoverageConfig(object): self.timid = False self.source = None self.debug = [] - self.extensions = [] + self.plugins = [] # Defaults for [report] self.exclude_list = DEFAULT_EXCLUDE[:] @@ -172,7 +172,7 @@ class CoverageConfig(object): if env: self.timid = ('--timid' in env) - MUST_BE_LIST = ["omit", "include", "debug", "extensions"] + MUST_BE_LIST = ["omit", "include", "debug", "plugins"] def from_args(self, **kwargs): """Read config values from `kwargs`.""" @@ -224,7 +224,7 @@ class CoverageConfig(object): ('cover_pylib', 'run:cover_pylib', 'boolean'), ('data_file', 'run:data_file'), ('debug', 'run:debug', 'list'), - ('extensions', 'run:extensions', 'list'), + ('plugins', 'run:plugins', 'list'), ('include', 'run:include', 'list'), ('omit', 'run:omit', 'list'), ('parallel', 'run:parallel', 'boolean'), -- cgit v1.2.1 From 44238cb66d14a6fb2f4d30f1cef9fdf0bb5f2e2d Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 21 Aug 2014 10:35:15 -0400 Subject: More-serious plugin support --- coverage/config.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'coverage/config.py') diff --git a/coverage/config.py b/coverage/config.py index 1826e5c2..c671ef75 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -37,6 +37,13 @@ class HandyConfigParser(configparser.RawConfigParser): section = self.section_prefix + section return configparser.RawConfigParser.options(self, section) + def get_section(self, section): + """Get the contents of a section, as a dictionary.""" + d = {} + for opt in self.options(section): + d[opt] = self.get(section, opt) + return d + def get(self, section, *args, **kwargs): """Get a value, replacing environment variables also. @@ -163,6 +170,9 @@ class CoverageConfig(object): # Defaults for [paths] self.paths = {} + # Options for plugins + self.plugin_options = {} + def from_environment(self, env_var): """Read configuration from the `env_var` environment variable.""" # Timidity: for nose users, read an environment variable. This is a @@ -200,17 +210,22 @@ class CoverageConfig(object): self.config_files.extend(files_read) for option_spec in self.CONFIG_FILE_OPTIONS: - self.set_attr_from_config_option(cp, *option_spec) + self._set_attr_from_config_option(cp, *option_spec) # [paths] is special if cp.has_section('paths'): for option in cp.options('paths'): self.paths[option] = cp.getlist('paths', option) + # plugins can have options + for plugin in self.plugins: + if cp.has_section(plugin): + self.plugin_options[plugin] = cp.get_section(plugin) + return True CONFIG_FILE_OPTIONS = [ - # These are *args for set_attr_from_config_option: + # These are *args for _set_attr_from_config_option: # (attr, where, type_="") # # attr is the attribute to set on the CoverageConfig object. @@ -250,9 +265,13 @@ class CoverageConfig(object): ('xml_output', 'xml:output'), ] - def set_attr_from_config_option(self, cp, attr, where, type_=''): + def _set_attr_from_config_option(self, cp, attr, where, type_=''): """Set an attribute on self if it exists in the ConfigParser.""" section, option = where.split(":") if cp.has_option(section, option): method = getattr(cp, 'get'+type_) setattr(self, attr, method(section, option)) + + def get_plugin_options(self, plugin): + """Get a dictionary of options for the plugin named `plugin`.""" + return self.plugin_options.get(plugin, {}) -- cgit v1.2.1