1
- import dataclasses
2
1
import logging
3
2
from enum import Enum
4
- from typing import Any , List , Sequence
3
+ from typing import Any , Sequence
5
4
6
5
from shared .reports .resources import LineSession , Report , ReportFile , ReportLine
7
- from shared .reports .types import CoverageDatapoint
8
6
from shared .yaml .user_yaml import UserYaml
9
7
10
- from helpers .labels import SpecialLabelsEnum
11
8
from services .path_fixer import PathFixer
12
9
from services .yaml .reader import read_yaml_field
13
10
@@ -36,8 +33,6 @@ def __init__(
36
33
self .filepath = report_filepath
37
34
self ._report_builder = report_builder
38
35
self ._report = Report ()
39
- self .label_index = {}
40
- self ._present_labels = set ()
41
36
42
37
@property
43
38
def path_fixer (self ):
@@ -53,109 +48,11 @@ def get_file(self, filename: str) -> ReportFile | None:
53
48
return self ._report .get (filename )
54
49
55
50
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 )
63
51
return self ._report .append (file )
64
52
65
53
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
87
54
return self ._report
88
55
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
-
159
56
def create_coverage_file (
160
57
self , path : str , do_fix_path : bool = True
161
58
) -> ReportFile | None :
@@ -171,30 +68,12 @@ def create_coverage_line(
171
68
self ,
172
69
coverage : int | str ,
173
70
coverage_type : CoverageType | None = None ,
174
- labels_list_of_lists : list [list [str | SpecialLabelsEnum ]]
175
- | list [list [int ]]
176
- | None = None ,
177
71
partials = None ,
178
72
missing_branches = None ,
179
73
complexity = None ,
180
74
) -> ReportLine :
181
75
sessionid = self ._report_builder .sessionid
182
76
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
- )
198
77
return ReportLine .create (
199
78
coverage = coverage ,
200
79
type = coverage_type_str ,
@@ -209,7 +88,6 @@ def create_coverage_line(
209
88
)
210
89
)
211
90
],
212
- datapoints = datapoints ,
213
91
complexity = complexity ,
214
92
)
215
93
0 commit comments