From be8afd0bc3f173926fc751c50f9975543f301a91 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 28 Nov 2009 14:01:13 -0500 Subject: Read a config file to get some of our configuration. --HG-- branch : config --- coverage/config.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 coverage/config.py (limited to 'coverage/config.py') diff --git a/coverage/config.py b/coverage/config.py new file mode 100644 index 00000000..ca7bab61 --- /dev/null +++ b/coverage/config.py @@ -0,0 +1,45 @@ +"""Config file for coverage.py""" + +import ConfigParser, os + + +class CoverageConfig(object): + def __init__(self): + # Defaults. + self.cover_pylib = False + self.timid = False + self.branch = False + self.exclude_list = ['# *pragma[: ]*[nN][oO] *[cC][oO][vV][eE][rR]'] + + def from_environment(self, env_var): + # Timidity: for nose users, read an environment variable. This is a + # cheap hack, since the rest of the command line arguments aren't + # recognized, but it solves some users' problems. + env = os.environ.get(env_var, '') + if env: + self.timid = ('--timid' in env) + + def from_args(self, **kwargs): + for k, v in kwargs.items(): + if v is not None: + setattr(self, k, v) + + def from_file(self, *files): + cp = ConfigParser.RawConfigParser() + cp.read(files) + + if cp.has_option('run', 'timid'): + self.timid = cp.getboolean('run', 'timid') + if cp.has_option('run', 'cover_pylib'): + self.cover_pylib = cp.getboolean('run', 'cover_pylib') + if cp.has_option('run', 'branch'): + self.branch = cp.getboolean('run', 'branch') + if cp.has_option('report', 'exclude'): + self.exclude_list = filter(None, cp.get('report', 'exclude').split('\n')) + + +if __name__ == '__main__': + cc = CoverageConfig() + cc.from_file(".coveragerc", ".coverage.ini") + import pdb;pdb.set_trace() + print cc -- cgit v1.2.1 From 81a363edf04f614af736ce32d79791a210e1e1fd Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 28 Nov 2009 16:59:58 -0500 Subject: Read .coveragerc by default. --HG-- branch : config --- coverage/config.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'coverage/config.py') diff --git a/coverage/config.py b/coverage/config.py index ca7bab61..0596cc04 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -35,11 +35,6 @@ class CoverageConfig(object): if cp.has_option('run', 'branch'): self.branch = cp.getboolean('run', 'branch') if cp.has_option('report', 'exclude'): - self.exclude_list = filter(None, cp.get('report', 'exclude').split('\n')) - - -if __name__ == '__main__': - cc = CoverageConfig() - cc.from_file(".coveragerc", ".coverage.ini") - import pdb;pdb.set_trace() - print cc + # Exclude is a list of lines, leave out the blank ones. + exclude_list = cp.get('report', 'exclude') + self.exclude_list = filter(None, exclude_list.split('\n')) -- cgit v1.2.1 From 49ede2bdf54a12e4eaa9472785cc5544040c077a Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 28 Nov 2009 17:30:59 -0500 Subject: Test the config file support. --HG-- branch : config --- coverage/config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'coverage/config.py') diff --git a/coverage/config.py b/coverage/config.py index 0596cc04..e95b74eb 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -1,6 +1,7 @@ """Config file for coverage.py""" -import ConfigParser, os +import os +from coverage.backward import configparser # pylint: disable-msg=W0622 class CoverageConfig(object): @@ -25,7 +26,7 @@ class CoverageConfig(object): setattr(self, k, v) def from_file(self, *files): - cp = ConfigParser.RawConfigParser() + cp = configparser.RawConfigParser() cp.read(files) if cp.has_option('run', 'timid'): -- cgit v1.2.1 From c72bfe70f9f8ac6d573689798b364bd664b93444 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 28 Nov 2009 20:24:23 -0500 Subject: Add data_file to the .coveragerc file. --HG-- branch : config --- coverage/config.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'coverage/config.py') diff --git a/coverage/config.py b/coverage/config.py index e95b74eb..125121b8 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -11,6 +11,7 @@ class CoverageConfig(object): self.timid = False self.branch = False self.exclude_list = ['# *pragma[: ]*[nN][oO] *[cC][oO][vV][eE][rR]'] + self.data_file = ".coverage" def from_environment(self, env_var): # Timidity: for nose users, read an environment variable. This is a @@ -39,3 +40,5 @@ class CoverageConfig(object): # Exclude is a list of lines, leave out the blank ones. exclude_list = cp.get('report', 'exclude') self.exclude_list = filter(None, exclude_list.split('\n')) + if cp.has_option('run', 'data_file'): + self.data_file = cp.get('run', 'data_file') -- cgit v1.2.1 From 3416380e8e46d839c3111d9f82a5f7d93a218821 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 28 Nov 2009 22:06:57 -0500 Subject: Docstrings for the new file. --HG-- branch : config --- coverage/config.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'coverage/config.py') diff --git a/coverage/config.py b/coverage/config.py index 125121b8..d779048c 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -5,7 +5,15 @@ from coverage.backward import configparser # pylint: disable-msg=W0622 class CoverageConfig(object): + """Coverage.py configuration. + + The attributes of this class are the various settings that control the + operation of coverage.py. + + """ + def __init__(self): + """Initialize the configuration attributes to their defaults.""" # Defaults. self.cover_pylib = False self.timid = False @@ -14,6 +22,7 @@ class CoverageConfig(object): self.data_file = ".coverage" 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 # cheap hack, since the rest of the command line arguments aren't # recognized, but it solves some users' problems. @@ -22,11 +31,17 @@ class CoverageConfig(object): self.timid = ('--timid' in env) def from_args(self, **kwargs): + """Read config values from `kwargs`.""" for k, v in kwargs.items(): if v is not None: setattr(self, k, v) def from_file(self, *files): + """Read configurating from .rc files. + + Each argument in `files` is a file name to read. + + """ cp = configparser.RawConfigParser() cp.read(files) -- cgit v1.2.1 From 30af11a626ef2ac748fa5b098166b5c626b36ef1 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 3 Dec 2009 08:58:17 -0500 Subject: Clean trailing whitespace. --HG-- branch : config --- coverage/config.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'coverage/config.py') diff --git a/coverage/config.py b/coverage/config.py index d779048c..0955347b 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -6,12 +6,12 @@ from coverage.backward import configparser # pylint: disable-msg=W0622 class CoverageConfig(object): """Coverage.py configuration. - + The attributes of this class are the various settings that control the operation of coverage.py. - + """ - + def __init__(self): """Initialize the configuration attributes to their defaults.""" # Defaults. @@ -38,13 +38,13 @@ class CoverageConfig(object): def from_file(self, *files): """Read configurating from .rc files. - + Each argument in `files` is a file name to read. - + """ cp = configparser.RawConfigParser() cp.read(files) - + if cp.has_option('run', 'timid'): self.timid = cp.getboolean('run', 'timid') if cp.has_option('run', 'cover_pylib'): -- cgit v1.2.1