1- import dataclasses
21import logging
32from enum import Enum
4- from typing import Any , List , Sequence
3+ from typing import Any , Sequence
54
65from shared .reports .resources import LineSession , Report , ReportFile , ReportLine
7- from shared .reports .types import CoverageDatapoint
86from shared .yaml .user_yaml import UserYaml
97
10- from helpers .labels import SpecialLabelsEnum
118from services .path_fixer import PathFixer
129from services .yaml .reader import read_yaml_field
1310
@@ -36,8 +33,6 @@ def __init__(
3633 self .filepath = report_filepath
3734 self ._report_builder = report_builder
3835 self ._report = Report ()
39- self .label_index = {}
40- self ._present_labels = set ()
4136
4237 @property
4338 def path_fixer (self ):
@@ -53,109 +48,11 @@ def get_file(self, filename: str) -> ReportFile | None:
5348 return self ._report .get (filename )
5449
5550 def append (self , file : ReportFile ):
56- if file is not None :
57- for line_number , line in file .lines :
58- if line .datapoints :
59- for datapoint in line .datapoints :
60- if datapoint .label_ids :
61- for label in datapoint .label_ids :
62- self ._present_labels .add (label )
6351 return self ._report .append (file )
6452
6553 def output_report (self ) -> Report :
66- """
67- Outputs a Report.
68- This function applies all the needed modifications before a report
69- can be output
70-
71- Returns:
72- Report: The legacy report desired
73- """
74- if self ._present_labels :
75- if self ._present_labels and self ._present_labels == {
76- SpecialLabelsEnum .CODECOV_ALL_LABELS_PLACEHOLDER
77- }:
78- log .warning (
79- "Report only has SpecialLabels. Might indicate it was not generated with contexts"
80- )
81- for file in self ._report :
82- for line_number , line in file .lines :
83- self ._possibly_modify_line_to_account_for_special_labels (
84- file , line_number , line
85- )
86- self ._report ._totals = None
8754 return self ._report
8855
89- def _possibly_modify_line_to_account_for_special_labels (
90- self , file : ReportFile , line_number : int , line : ReportLine
91- ) -> None :
92- """Possibly modify the report line in the file
93- to account for any label in the SpecialLabelsEnum
94-
95- Args:
96- file (ReportFile): The file we want to modify
97- line_number (int): The line number in case we
98- need to set the new line back into the files
99- line (ReportLine): The original line
100- """
101- if not line .datapoints :
102- return
103-
104- new_datapoints = [
105- item
106- for datapoint in line .datapoints
107- for item in self ._possibly_convert_datapoints (datapoint )
108- ]
109- if new_datapoints and new_datapoints != line .datapoints :
110- # A check to avoid unnecessary replacement
111- file [line_number ] = dataclasses .replace (
112- line ,
113- datapoints = sorted (
114- new_datapoints ,
115- key = lambda x : (
116- x .sessionid ,
117- x .coverage ,
118- x .coverage_type ,
119- ),
120- ),
121- )
122- file ._totals = None
123-
124- # TODO: This can be removed after label indexing is rolled out for all customers
125- def _possibly_convert_datapoints (
126- self , datapoint : CoverageDatapoint
127- ) -> List [CoverageDatapoint ]:
128- """Possibly convert datapoints
129- The datapoint that might need to be converted
130-
131- Args:
132- datapoint (CoverageDatapoint): The datapoint to convert
133- """
134- if datapoint .label_ids and any (
135- label == SpecialLabelsEnum .CODECOV_ALL_LABELS_PLACEHOLDER
136- for label in datapoint .label_ids
137- ):
138- new_label = (
139- SpecialLabelsEnum .CODECOV_ALL_LABELS_PLACEHOLDER .corresponding_label
140- )
141- return [
142- dataclasses .replace (
143- datapoint ,
144- label_ids = sorted (
145- set (
146- [
147- label
148- for label in datapoint .label_ids
149- if label
150- != SpecialLabelsEnum .CODECOV_ALL_LABELS_PLACEHOLDER
151- ]
152- + [new_label ]
153- )
154- ),
155- )
156- ]
157- return [datapoint ]
158-
15956 def create_coverage_file (
16057 self , path : str , do_fix_path : bool = True
16158 ) -> ReportFile | None :
@@ -171,30 +68,12 @@ def create_coverage_line(
17168 self ,
17269 coverage : int | str ,
17370 coverage_type : CoverageType | None = None ,
174- labels_list_of_lists : list [list [str | SpecialLabelsEnum ]]
175- | list [list [int ]]
176- | None = None ,
17771 partials = None ,
17872 missing_branches = None ,
17973 complexity = None ,
18074 ) -> ReportLine :
18175 sessionid = self ._report_builder .sessionid
18276 coverage_type_str = coverage_type .map_to_string () if coverage_type else None
183- datapoints = (
184- [
185- CoverageDatapoint (
186- sessionid = sessionid ,
187- coverage = coverage ,
188- coverage_type = coverage_type_str ,
189- label_ids = label_ids ,
190- )
191- # Avoid creating datapoints that don't contain any labels
192- for label_ids in (labels_list_of_lists or [])
193- if label_ids
194- ]
195- if self ._report_builder .supports_labels ()
196- else None
197- )
19877 return ReportLine .create (
19978 coverage = coverage ,
20079 type = coverage_type_str ,
@@ -209,7 +88,6 @@ def create_coverage_line(
20988 )
21089 )
21190 ],
212- datapoints = datapoints ,
21391 complexity = complexity ,
21492 )
21593
0 commit comments