Generate the diff coverage report, using kwargs from `parse_args()`.
195317
def generate_coverage_report(coverage_xml, compare_branch,
                             html_report=None, css_file=None,
                             ignore_staged=False, ignore_unstaged=False,
                             exclude=None, src_roots=None):
    
    diff = GitDiffReporter(
        compare_branch, git_diff=GitDiffTool(), ignore_staged=ignore_staged,
        ignore_unstaged=ignore_unstaged, exclude=exclude)

    xml_roots = [cElementTree.parse(xml_root) for xml_root in coverage_xml]
    coverage = XmlCoverageReporter(xml_roots, src_roots)

    # Build a report generator
    if html_report is not None:
        css_url = css_file
        if css_url is not None:
            css_url = os.path.relpath(css_file, os.path.dirname(html_report))
        reporter = HtmlReportGenerator(coverage, diff, css_url=css_url)
        with open(html_report, "wb") as output_file:
            reporter.generate_report(output_file)
        if css_file is not None:
            with open(css_file, "wb") as output_file:
                reporter.generate_css(output_file)

    reporter = StringReportGenerator(coverage, diff)
    output_file = sys.stdout if six.PY2 else sys.stdout.buffer

    # Generate the report
    reporter.generate_report(output_file)
    return reporter.total_percent_covered()
398120
def build_stack_changes(stack_name, new_stack, old_stack, new_params,
                        old_params):
    """"""
    from_file = "old_%s" % (stack_name,)
    to_file = "new_%s" % (stack_name,)
    lines = difflib.context_diff(
        old_stack, new_stack,
        fromfile=from_file, tofile=to_file,
        n=7)  # ensure at least a few lines of context are displayed afterward

    template_changes = list(lines)
    log_lines = []
    if not template_changes:
        log_lines.append("*** No changes to template ***")
    param_diffs = diff_parameters(old_params, new_params)
    if param_diffs:
        log_lines.append(format_params_diff(param_diffs))
    if template_changes:
        log_lines.append("".join(template_changes))
    return log_lines
522379
def main():
    """"""
    desc = 'Benchmark the files generated by generate.py'
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument(
        '--src',
        dest='src_dir',
        default='generated',
        help='The directory containing the sources to benchmark'
    )
    parser.add_argument(
        '--out',
        dest='out_dir',
        default='../../doc',
        help='The output directory'
    )
    parser.add_argument(
        '--include',
        dest='include',
        default='include',
        help='The directory containing the headeres for the benchmark'
    )
    parser.add_argument(
        '--boost_headers',
        dest='boost_headers',
        default='../../../..',
        help='The directory containing the Boost headers (the boost directory)'
    )
    parser.add_argument(
        '--compiler',
        dest='compiler',
        default='g++',
        help='The compiler to do the benchmark with'
    )
    parser.add_argument(
        '--repeat_count',
        dest='repeat_count',
        type=int,
        default=5,
        help='How many times a measurement should be repeated.'
    )

    args = parser.parse_args()

    compiler = compiler_info(args.compiler)
    results = benchmark(
        args.src_dir,
        args.compiler,
        [args.include, args.boost_headers],
        args.repeat_count
    )

    plot_diagrams(results, configs_in(args.src_dir), compiler, args.out_dir)
1354067
def get_config(args):
    
    options, _ = defaults.DEFAULT_OPTIONS.parse(args, ignore_errors=True)
    read_config = not options.skip_default_config
    cfg = CoverageReporterConfig(read_config)
    for path in options.config_file:
        cfg.read(path)
    cfg.plugin_dirs.extend(options.plugin_dir)
    cfg.plugins.extend(options.plugin)
    return cfg
623964
def diff_lines(self):
    """"""
    start_lines = self._build_file_source_lines[:]
    end_lines = self.build_file_lines()
    diff_generator = unified_diff(start_lines,
                                  end_lines,
                                  fromfile=self.build_file.relpath,
                                  tofile=self.build_file.relpath,
                                  lineterm='')
    return list(diff_generator)
1086400
def coverage(args):
    
    from jcvi.graphics.base import savefig

    p = OptionParser(coverage.__doc__)
    opts, args, iopts = p.set_image_options(args, format="png")

    if len(args) != 1:
        sys.exit(not p.print_help())

    covfile, = args
    df = pd.read_csv(covfile, sep='\t', names=["Ref", "Position", "Depth"])

    xlabel, ylabel = "Position", "Depth"
    df.plot(xlabel, ylabel, color='g')

    image_name = covfile + "." + iopts.format
    savefig(image_name)
626949
def print_diff(self, style=no_style()):
        
        if self.options['sql']:
            self.print_diff_sql(style)
        else:
            self.print_diff_text(style)
587729
def coverage(reportdir=None, extra=None):
    """"""

    import coverage as coverage_api
    cov = coverage_api.coverage()
    opts = {'directory': reportdir} if reportdir else {}

    cov.start()
    test(extra)
    cov.stop()
    cov.html_report(**opts)
1285806
def html(self, diff, f):
        
        env = Environment(loader=PackageLoader('clan', 'templates'))

        template = env.get_template('diff.html')

        def number_class(v):
            if v is None:
                return ''

            if v > 0:
                return 'positive'
            elif v < 0:
                return 'negative'

            return ''

        context = {
            'diff': diff,
            'GLOBAL_ARGUMENTS': GLOBAL_ARGUMENTS,
            'format_comma': format_comma,
            'format_duration': format_duration,
            'number_class': number_class

        }

        f.write(template.render(**context).encode('utf-8'))
305651
def run_diff(self):
        
        files = tuple(self.files)
        # Use same header as more.
        header, footer = (termcolor.colored("{0}\n{{}}\n{0}\n".format(
            ":" * 14), "cyan"), "\n") if len(files) > 1 else ("", "")

        for file in files:
            print(header.format(file), end="")
            try:
                results = self._check(file)
            except Error as e:
                termcolor.cprint(e.msg, "yellow", file=sys.stderr)
                continue

            # Display results
            if results.diffs:
                print()
                print(*self.diff(results.original, results.styled), sep="\n")
                print()
                conjunction = "And"
            else:
                termcolor.cprint("Looks good!", "green")
                conjunction = "But"

            if results.diffs:
                for type, c in sorted(self._warn_chars):
                    color, verb = ("on_green", "insert") if type == "+" else ("on_red", "delete")
                    termcolor.cprint(c, None, color, end="")
                    termcolor.cprint(" means that you should {} a {}.".format(
                        verb, "newline" if c == "\\n" else "tab"), "yellow")

            if results.comment_ratio < results.COMMENT_MIN:
                termcolor.cprint("{} consider adding more comments!".format(conjunction), "yellow")

            if (results.comment_ratio < results.COMMENT_MIN or self._warn_chars) and results.diffs:
                print()
984734
def diff_iter(self, other, **kwargs):
        
        for diff in super(JsonRecord, self).diff_iter(other, **kwargs):
            # TODO: object copy/upgrade constructor
            newargs = diff.__getstate__()
            yield JsonDiffInfo(**(newargs))
923734
def parse_coverage(coverage_report, parser):
    
    if parser in PARSERS:
        if coverage_report:
            return PARSERS[parser].parse_coverage_report(coverage_report)
        return None
    return NotImplemented
587996
def generateDiff(self, oldWarnings, newWarnings):
        
        diffWarnings = {}

        for modulename in newWarnings:
            diffInModule = (
                newWarnings[modulename] -
                oldWarnings.get(modulename, set()))
            if diffInModule:
                diffWarnings[modulename] = diffInModule

        return diffWarnings
1000254
def main(argv=None):
    ''''''

    if argv is None:
        argv = sys.argv
    else:
        sys.argv.extend(argv)

    parser = ArgumentParser()
    parser.add_argument('-u', '--url', dest='url', required=True, help="base url (has to contain versions json)")
    parser.add_argument('-o', '--output', dest='output')
    parser.add_argument('-a', '--add_version', dest='version')
    parser.add_argument('-v', '--verbose', dest='verbose', action='store_true')
    parser.add_argument('-l', '--latest-version', dest='latest', action='store_true')

    args = parser.parse_args()

    URL = args.url
    # get dict
    versions = json.load(urlopen(URL + '/versions.json'))
    # add new version
    if args.version:
        versions.append(make_version_dict(URL, args.version))

    # create Version objects to compare them
    version_objs = [parse(s['version']) for s in versions]

    # unify and sort
    version_objs = set(version_objs)
    version_objs = sorted(list(version_objs))

    versions = [make_version_dict(URL, str(v)) for v in version_objs if v != 'devel']

    # last element should be the highest version
    versions[-1]['latest'] = True
    versions.append(make_version_dict(URL, 'devel', '', False))

    if args.verbose:
        print("new versions json:")
        json.dump(versions, sys.stdout, indent=1)
        print()

    if args.latest:
        print(find_latest(versions)['version'])
        return 0

    if args.output:
        with open(args.output, 'w') as v:
            json.dump(versions, v, indent=1)
            v.flush()
558665
def create_report(self):
        """"""
        data = self.create_data()
        try:
            json_string = json.dumps(data)
        except UnicodeDecodeError as e:
            log.error('ERROR: While preparing JSON:', exc_info=e)
            self.debug_bad_encoding(data)
            raise

        log_string = re.sub(r'"repo_token": "(.+?)"',
                            '"repo_token": "[secure]"', json_string)
        log.debug(log_string)
        log.debug('==\nReporting %s files\n==\n', len(data['source_files']))
        for source_file in data['source_files']:
            log.debug('%s - %s/%s', source_file['name'],
                      sum(filter(None, source_file['coverage'])),
                      len(source_file['coverage']))
        return json_string
1332882
def run(args):
    
    (opts, args) = PARSER.parse_args(args) if args else PARSER.parse_args()
    if not len(args):
        PARSER.print_usage()
        sys.exit(1)

    outfilename = args[0] + ".html"
    if len(args) > 1:
        outfilename = args[1]

    report = parser.Junit(args[0])
    html = report.html()

    with open(outfilename, "wb") as outfile:
        outfile.write(html.encode('utf-8'))
1180288
def _compute_diff(expected_endpoints, configured_endpoints):
    '''
    
    '''
    new_endpoints = []
    update_endpoints = []
    remove_endpoints = []

    ret = _compute_diff_ret()

    # noth configured => configure with expected endpoints
    if not configured_endpoints:
        ret.update({
            'add': expected_endpoints
        })
        return ret

    # noting expected => remove everything
    if not expected_endpoints:
        ret.update({
            'remove': configured_endpoints
        })
        return ret

    expected_endpoints_clear = _clear_ignore_list(expected_endpoints)
    configured_endpoints_clear = _clear_ignore_list(configured_endpoints)

    for expected_endpoint_clear in expected_endpoints_clear:
        if expected_endpoint_clear not in configured_endpoints_clear:
            # none equal => add or update
            matching_ele = _find_match(expected_endpoint_clear, configured_endpoints_clear)
            if not matching_ele:
                # new element => add
                new_endpoints.append(expected_endpoint_clear)
            else:
                # element matched, but some fields are different
                update_fields = _update_on_fields(matching_ele, expected_endpoint_clear)
                if update_fields:
                    update_endpoints.append(update_fields)
    for configured_endpoint_clear in configured_endpoints_clear:
        if configured_endpoint_clear not in expected_endpoints_clear:
            matching_ele = _find_match(configured_endpoint_clear, expected_endpoints_clear)
            if not matching_ele:
                #  no match found => remove
                remove_endpoints.append(configured_endpoint_clear)

    return {
        'add': new_endpoints,
        'update': update_endpoints,
        'remove': remove_endpoints
    }