Skip to content

Commit 4974cef

Browse files
committed
Merge the Report._files/_chunks
Instead of maintaining two separate fields, this merges the previous `_files` which was a dict from filename to `totals`, and the `_chunks` which was either a fully parsed `ReportFile`, or just a shallow `list` of lines. Maintaining only a single structure for the list of files makes a ton of internals of the `Report` simpler. It also solves the problem of `file_totals` getting out of sync with the `ReportFile.totals`.
1 parent 02c0986 commit 4974cef

File tree

6 files changed

+141
-936
lines changed

6 files changed

+141
-936
lines changed

shared/reports/carryforward.py

+10-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import re
33
from typing import Mapping, Sequence
44

5-
from shared.reports.editable import EditableReport
65
from shared.reports.resources import Report
76
from shared.utils.match import Matcher
87
from shared.utils.sessions import SessionType
@@ -36,7 +35,7 @@ def generate_carryforward_report(
3635
flags: Sequence[str],
3736
paths: Sequence[str],
3837
session_extras: Mapping[str, str] | None = None,
39-
) -> EditableReport:
38+
) -> Report:
4039
"""
4140
Generates a carriedforward report starting from report `report`, flags `flags`
4241
and paths `paths`
@@ -66,19 +65,16 @@ def generate_carryforward_report(
6665
Returns:
6766
EditableReport: A new report with only the info related to `flags` on it, as described above
6867
"""
69-
new_report = EditableReport(
70-
chunks=report._chunks,
71-
files=report._files,
72-
sessions=report.sessions,
73-
totals=None,
74-
)
7568
if paths:
7669
matcher = Matcher(paths)
77-
for filename in new_report.files:
78-
if not matcher.match(filename):
79-
del new_report[filename]
70+
files_to_delete = {
71+
filename for filename in report._files.keys() if not matcher.match(filename)
72+
}
73+
for filename in files_to_delete:
74+
del report[filename]
75+
8076
sessions_to_delete = []
81-
for sid, session in new_report.sessions.items():
77+
for sid, session in report.sessions.items():
8278
if not contain_any_of_the_flags(flags, session.flags):
8379
sessions_to_delete.append(int(sid))
8480
else:
@@ -89,8 +85,8 @@ def generate_carryforward_report(
8985
"Removing sessions that are not supposed to carryforward",
9086
extra=dict(deleted_sessions=sessions_to_delete),
9187
)
92-
new_report.delete_multiple_sessions(sessions_to_delete)
93-
return new_report
88+
report.delete_multiple_sessions(sessions_to_delete)
89+
return report
9490

9591

9692
def contain_any_of_the_flags(expected_flags, actual_flags):

shared/reports/reportfile.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
log = logging.getLogger(__name__)
1414

1515

16-
class ReportFile(object):
16+
class ReportFile:
17+
name: str
18+
_totals: ReportTotals | None = None
19+
_lines: list[None | str | ReportLine] = []
20+
_details: dict[str, Any] = {}
21+
__present_sessions: set[int] | None = None
22+
1723
def __init__(
1824
self,
1925
name: str,
@@ -32,10 +38,7 @@ def __init__(
3238
{eof:N, lines:[1,10]}
3339
"""
3440
self.name = name
35-
self._details: dict[str, Any] = {}
3641

37-
# lines = [<details dict()>, <Line #1>, ....]
38-
self._lines: list[None | str | ReportLine] = []
3942
if lines:
4043
if isinstance(lines, list):
4144
self._lines = lines
@@ -54,13 +57,11 @@ def __init__(
5457
# All mutating methods (like `append`, `merge`, etc) will either re-calculate these values
5558
# directly, or clear them so the `@property` accessors re-calculate them when needed.
5659

57-
self._totals: ReportTotals | None = None
5860
if isinstance(totals, ReportTotals):
5961
self._totals = totals
6062
elif totals:
6163
self._totals = ReportTotals(*totals)
6264

63-
self.__present_sessions: set[int] | None = None
6465
if present_sessions := self._details.get("present_sessions"):
6566
self.__present_sessions = set(present_sessions)
6667

@@ -84,12 +85,9 @@ def details(self):
8485
@property
8586
def totals(self):
8687
if not self._totals:
87-
self._totals = self._process_totals()
88+
self._totals = get_line_totals(line for _ln, line in self.lines)
8889
return self._totals
8990

90-
def _process_totals(self) -> ReportTotals:
91-
return get_line_totals(line for _ln, line in self.lines)
92-
9391
def __repr__(self):
9492
try:
9593
return "<%s name=%s lines=%s>" % (

0 commit comments

Comments
 (0)