Skip to content

Commit bdafe67

Browse files
authored
Hard-enable the RustReport (#582)
It turns out that the `ComparisonProxy.get_impacted_files` function within `worker` is depending on the `RustReport` being enabled and present. So lets just remove the feature flag and hard-enable this, to make it clear that other code actually depends on this.
1 parent 87e3404 commit bdafe67

File tree

3 files changed

+21
-105
lines changed

3 files changed

+21
-105
lines changed

shared/reports/readonly.py

+18-32
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import logging
2-
import os
3-
import random
42
from typing import Any
53

64
import orjson
75
import sentry_sdk
86
from cc_rustyribs import FilterAnalyzer, SimpleAnalyzer, parse_report
97

108
from shared.helpers.flag import Flag
11-
from shared.reports.resources import (
12-
END_OF_HEADER,
13-
Report,
14-
ReportTotals,
15-
)
9+
from shared.reports.resources import END_OF_HEADER, Report, ReportTotals
1610
from shared.utils.match import Matcher
1711

1812
log = logging.getLogger(__name__)
@@ -45,10 +39,6 @@ def get_report(self):
4539

4640

4741
class ReadOnlyReport(object):
48-
@classmethod
49-
def should_load_rust_version(cls):
50-
return random.random() < float(os.getenv("RUST_ENABLE_RATE", "1.0"))
51-
5242
def __init__(self, rust_analyzer, rust_report, inner_report, totals=None):
5343
self.rust_analyzer = rust_analyzer
5444
self.rust_report = rust_report
@@ -70,9 +60,7 @@ def from_chunks(cls, files=None, sessions=None, totals=None, chunks=None):
7060
session_mapping = {
7161
sid: (session.flags or []) for sid, session in inner_report.sessions.items()
7262
}
73-
rust_report = None
74-
if cls.should_load_rust_version():
75-
rust_report = LazyRustReport(filename_mapping, chunks, session_mapping)
63+
rust_report = LazyRustReport(filename_mapping, chunks, session_mapping)
7664
return cls(rust_analyzer, rust_report, inner_report, totals=totals)
7765

7866
@classmethod
@@ -128,24 +116,22 @@ def get(self, *args, **kwargs):
128116
def _process_totals(self):
129117
if self.inner_report.has_precalculated_totals():
130118
return self.inner_report.totals
131-
if self.rust_report:
132-
res = self.rust_analyzer.get_totals(self.rust_report.get_report())
133-
return ReportTotals(
134-
files=res.files,
135-
lines=res.lines,
136-
hits=res.hits,
137-
misses=res.misses,
138-
partials=res.partials,
139-
coverage=res.coverage,
140-
branches=res.branches,
141-
methods=res.methods,
142-
messages=0,
143-
sessions=res.sessions,
144-
complexity=res.complexity,
145-
complexity_total=res.complexity_total,
146-
diff=0,
147-
)
148-
return self.inner_report.totals
119+
res = self.rust_analyzer.get_totals(self.rust_report.get_report())
120+
return ReportTotals(
121+
files=res.files,
122+
lines=res.lines,
123+
hits=res.hits,
124+
misses=res.misses,
125+
partials=res.partials,
126+
coverage=res.coverage,
127+
branches=res.branches,
128+
methods=res.methods,
129+
messages=0,
130+
sessions=res.sessions,
131+
complexity=res.complexity,
132+
complexity_total=res.complexity_total,
133+
diff=0,
134+
)
149135

150136
@property
151137
def totals(self):

tests/unit/reports/test_changes.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515

1616

1717
@pytest.fixture
18-
def sample_rust_report(mocker):
19-
mocker.patch.object(ReadOnlyReport, "should_load_rust_version", return_value=True)
18+
def sample_rust_report():
2019
with open(current_file.parent / "samples" / "chunks_01.txt", "r") as f:
2120
chunks = f.read()
2221
files_dict = {

tests/unit/reports/test_readonly.py

+2-71
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111

1212
@pytest.fixture
13-
def sample_rust_report(mocker):
14-
mocker.patch.object(ReadOnlyReport, "should_load_rust_version", return_value=True)
13+
def sample_rust_report():
1514
with open(current_file.parent / "samples" / "chunks_01.txt", "r") as f:
1615
chunks = f.read()
1716
files_dict = {
@@ -74,10 +73,7 @@ class TestReadOnly(object):
7473
@pytest.mark.parametrize(
7574
"report_header", [{}, {"labels_index": {0: "special_label", 1: "some_test"}}]
7675
)
77-
def test_create_from_report(self, sample_report, mocker, report_header):
78-
mocker.patch.object(
79-
ReadOnlyReport, "should_load_rust_version", return_value=True
80-
)
76+
def test_create_from_report(self, sample_report, report_header):
8177
sample_report._header = report_header
8278
r = ReadOnlyReport.create_from_report(sample_report)
8379
assert r.rust_report is not None
@@ -220,9 +216,6 @@ def test_get_file_totals(self, sample_report, mocker):
220216

221217
def test_from_chunks_with_totals(self, mocker):
222218
mocked_process_totals = mocker.patch.object(ReadOnlyReport, "_process_totals")
223-
mocker.patch.object(
224-
ReadOnlyReport, "should_load_rust_version", return_value=True
225-
)
226219
with open(current_file.parent / "samples" / "chunks_01.txt", "r") as f:
227220
chunks = f.read()
228221
files_dict = {
@@ -320,68 +313,6 @@ def test_filter_none(self, sample_rust_report):
320313
assert sample_rust_report.rust_report.get_report() is not None
321314
assert sample_rust_report.filter() is sample_rust_report
322315

323-
def test_init_no_loading_rust(self, mocker):
324-
chunks = "\n".join(
325-
["{}", "", "", "[1, null, [[0, 1], [1, 0]]]", "[0, null, [[0, 0], [1, 0]]]"]
326-
)
327-
files_dict = {
328-
"awesome/__init__.py": [
329-
2,
330-
[0, 10, 8, 2, 0, "80.00000", 0, 0, 0, 0, 0, 0, 0],
331-
[[0, 10, 8, 2, 0, "80.00000", 0, 0, 0, 0, 0, 0, 0]],
332-
[0, 2, 1, 1, 0, "50.00000", 0, 0, 0, 0, 0, 0, 0],
333-
],
334-
"tests/__init__.py": [
335-
0,
336-
[0, 3, 2, 1, 0, "66.66667", 0, 0, 0, 0, 0, 0, 0],
337-
[[0, 3, 2, 1, 0, "66.66667", 0, 0, 0, 0, 0, 0, 0]],
338-
None,
339-
],
340-
"tests/test_sample.py": [
341-
1,
342-
[0, 7, 7, 0, 0, "100", 0, 0, 0, 0, 0, 0, 0],
343-
[[0, 7, 7, 0, 0, "100", 0, 0, 0, 0, 0, 0, 0]],
344-
None,
345-
],
346-
}
347-
sessions_dict = {
348-
"0": {
349-
"N": None,
350-
"a": "v4/raw/2019-01-10/4434BC2A2EC4FCA57F77B473D83F928C/abf6d4df662c47e32460020ab14abf9303581429/9ccc55a1-8b41-4bb1-a946-ee7a33a7fb56.txt",
351-
"c": None,
352-
"d": 1547084427,
353-
"e": None,
354-
"f": ["unit"],
355-
"j": None,
356-
"n": None,
357-
"p": None,
358-
"t": [3, 20, 17, 3, 0, "85.00000", 0, 0, 0, 0, 0, 0, 0],
359-
"": None,
360-
}
361-
}
362-
mocker.patch.object(
363-
ReadOnlyReport, "should_load_rust_version", return_value=False
364-
)
365-
r = ReadOnlyReport.from_chunks(
366-
chunks=chunks, files=files_dict, sessions=sessions_dict
367-
)
368-
assert r.rust_report is None
369-
assert r.totals == ReportTotals(
370-
files=3,
371-
lines=20,
372-
hits=17,
373-
misses=3,
374-
partials=0,
375-
coverage="85.00000",
376-
branches=0,
377-
methods=0,
378-
messages=0,
379-
sessions=1,
380-
complexity=0,
381-
complexity_total=0,
382-
diff=0,
383-
)
384-
385316
def test_init(self, sample_rust_report):
386317
report = sample_rust_report
387318
assert report.totals.asdict() == {

0 commit comments

Comments
 (0)