diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-11-28 14:01:13 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-11-28 14:01:13 -0500 |
commit | be8afd0bc3f173926fc751c50f9975543f301a91 (patch) | |
tree | 6bb3ce8ba6c4e20c75871f06786113e515cc0a1c /coverage/config.py | |
parent | 0fd1a4a46c59ddf5c018364226c5d8a1525aff8c (diff) | |
download | python-coveragepy-git-be8afd0bc3f173926fc751c50f9975543f301a91.tar.gz |
Read a config file to get some of our configuration.
--HG--
branch : config
Diffstat (limited to 'coverage/config.py')
-rw-r--r-- | coverage/config.py | 45 |
1 files changed, 45 insertions, 0 deletions
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 |