Beispiel #1
0
def read_config_file(config, filename):
    if filename == '.coveragerc':
        rc_file = True
    elif filename in ('tox.ini', 'setup.cfg'):
        rc_file = False
    else:
        # Very likely all other config files are 'own rc' files.
        # However the cost here is minimal for correctness and this
        # reduces the chance it can be broken by future childishness :P
        parser = configparser.RawConfigParser()
        parser.read(filename)
        sections = parser.sections()
        rc_file = not any(
            section.startswith('coverage:') for section in sections)

    # Try the old pre 4.4.1 invocation
    try:
        return config.from_file(filename,
                                section_prefix='' if rc_file else 'coverage:')
    except TypeError:
        pass

    # coverage 5+
    if hasattr(config, 'config_file'):
        config.config_file = filename

    # coverage 4.4.1+
    return config.from_file(filename, our_file=rc_file)
Beispiel #2
0
    def from_file(self, *files):
        """Read configuration from .rc files.

        Each argument in `files` is a file name to read.

        """
        cp = configparser.RawConfigParser()
        cp.read(files)

        # [run]
        if cp.has_option('run', 'branch'):
            self.branch = cp.getboolean('run', 'branch')
        if cp.has_option('run', 'cover_pylib'):
            self.cover_pylib = cp.getboolean('run', 'cover_pylib')
        if cp.has_option('run', 'data_file'):
            self.data_file = cp.get('run', 'data_file')
        if cp.has_option('run', 'include'):
            self.include = self.get_list(cp, 'run', 'include')
        if cp.has_option('run', 'omit'):
            self.omit = self.get_list(cp, 'run', 'omit')
        if cp.has_option('run', 'parallel'):
            self.parallel = cp.getboolean('run', 'parallel')
        if cp.has_option('run', 'source'):
            self.source = self.get_list(cp, 'run', 'source')
        if cp.has_option('run', 'timid'):
            self.timid = cp.getboolean('run', 'timid')

        # [report]
        if cp.has_option('report', 'exclude_lines'):
            self.exclude_list = \
                self.get_line_list(cp, 'report', 'exclude_lines')
        if cp.has_option('report', 'ignore_errors'):
            self.ignore_errors = cp.getboolean('report', 'ignore_errors')
        if cp.has_option('report', 'include'):
            self.include = self.get_list(cp, 'report', 'include')
        if cp.has_option('report', 'omit'):
            self.omit = self.get_list(cp, 'report', 'omit')
        if cp.has_option('report', 'partial_branches'):
            self.partial_list = \
                self.get_line_list(cp, 'report', 'partial_branches')
        if cp.has_option('report', 'partial_branches_always'):
            self.partial_always_list = \
                self.get_line_list(cp, 'report', 'partial_branches_always')
        if cp.has_option('report', 'precision'):
            self.precision = cp.getint('report', 'precision')

        # [html]
        if cp.has_option('html', 'directory'):
            self.html_dir = cp.get('html', 'directory')

        # [xml]
        if cp.has_option('xml', 'output'):
            self.xml_output = cp.get('xml', 'output')

        # [paths]
        if cp.has_section('paths'):
            for option in cp.options('paths'):
                self.paths[option] = self.get_list(cp, 'paths', option)
Beispiel #3
0
    def from_file(self, *files):
        """Read configuration from .rc files.

        Each argument in `files` is a file name to read.

        """
        cp = configparser.RawConfigParser()
        cp.read(files)

        # [run]
        if cp.has_option('run', 'branch'):
            self.branch = cp.getboolean('run', 'branch')
        if cp.has_option('run', 'cover_pylib'):
            self.cover_pylib = cp.getboolean('run', 'cover_pylib')
        if cp.has_option('run', 'data_file'):
            self.data_file = cp.get('run', 'data_file')
        if cp.has_option('run', 'parallel'):
            self.parallel = cp.getboolean('run', 'parallel')
        if cp.has_option('run', 'timid'):
            self.timid = cp.getboolean('run', 'timid')
        if cp.has_option('run', 'source'):
            self.source = self.get_list(cp, 'run', 'source')
        if cp.has_option('run', 'omit'):
            self.omit = self.get_list(cp, 'run', 'omit')
        if cp.has_option('run', 'include'):
            self.include = self.get_list(cp, 'run', 'include')

        # [report]
        if cp.has_option('report', 'exclude_lines'):
            # exclude_lines is a list of lines, leave out the blank ones.
            exclude_list = cp.get('report', 'exclude_lines')
            self.exclude_list = list(filter(None, exclude_list.split('\n')))
        if cp.has_option('report', 'ignore_errors'):
            self.ignore_errors = cp.getboolean('report', 'ignore_errors')
        if cp.has_option('report', 'omit'):
            self.omit = self.get_list(cp, 'report', 'omit')
        if cp.has_option('report', 'include'):
            self.include = self.get_list(cp, 'report', 'include')
        if cp.has_option('report', 'precision'):
            self.precision = cp.getint('report', 'precision')

        # [html]
        if cp.has_option('html', 'directory'):
            self.html_dir = cp.get('html', 'directory')

        # [xml]
        if cp.has_option('xml', 'output'):
            self.xml_output = cp.get('xml', 'output')