def _outputter_codecovio()

in glean_parser/coverage.py [0:0]


def _outputter_codecovio(metrics: ObjectTree, output_path: Path):
    """
    Output coverage in codecov.io format as defined here:

        https://docs.codecov.io/docs/codecov-custom-coverage-format

    :param metrics: The tree of metrics, already annotated with coverage by
        `_annotate_coverage`.
    :param output_path: The file to output to.
    """
    coverage: Dict[str, List] = {}
    for category in metrics.values():
        for metric in category.values():
            defined_in = metric.defined_in
            if defined_in is not None:
                path = defined_in["filepath"]
                if path not in coverage:
                    with open(path) as fd:
                        nlines = len(list(fd.readlines()))
                    lines = [None] * nlines
                    coverage[path] = lines
                file_section = coverage[path]
                file_section[int(defined_in["line"])] = getattr(metric, "covered", 0)

    with open(output_path, "w") as fd:
        json.dump({"coverage": coverage}, fd)