Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 66ca059

Browse files
authored
Improve typing of LanguageProcessors (#666)
1 parent 748d759 commit 66ca059

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+408
-415
lines changed
Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +0,0 @@
1-
# ruff: noqa: F401
2-
from services.report.languages.bullseye import BullseyeProcessor
3-
from services.report.languages.clover import CloverProcessor
4-
from services.report.languages.cobertura import CoberturaProcessor
5-
from services.report.languages.coveralls import CoverallsProcessor
6-
from services.report.languages.csharp import CSharpProcessor
7-
from services.report.languages.dlst import DLSTProcessor
8-
from services.report.languages.elm import ElmProcessor
9-
from services.report.languages.flowcover import FlowcoverProcessor
10-
from services.report.languages.gap import GapProcessor
11-
from services.report.languages.gcov import GcovProcessor
12-
from services.report.languages.go import GoProcessor
13-
from services.report.languages.jacoco import JacocoProcessor
14-
from services.report.languages.jetbrainsxml import JetBrainsXMLProcessor
15-
from services.report.languages.lcov import LcovProcessor
16-
from services.report.languages.lua import LuaProcessor
17-
from services.report.languages.mono import MonoProcessor
18-
from services.report.languages.node import NodeProcessor
19-
from services.report.languages.pycoverage import PyCoverageProcessor
20-
from services.report.languages.rlang import RlangProcessor
21-
from services.report.languages.salesforce import SalesforceProcessor
22-
from services.report.languages.scala import ScalaProcessor
23-
from services.report.languages.scoverage import SCoverageProcessor
24-
from services.report.languages.simplecov import SimplecovProcessor
25-
from services.report.languages.v1 import VOneProcessor
26-
from services.report.languages.vb import VbProcessor
27-
from services.report.languages.vb2 import VbTwoProcessor
28-
from services.report.languages.xcode import XCodeProcessor
29-
from services.report.languages.xcodeplist import XCodePlistProcessor

services/report/languages/base.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import typing
21
from typing import Any
32

43
from shared.reports.resources import Report
@@ -7,10 +6,6 @@
76

87

98
class BaseLanguageProcessor(object):
10-
@property
11-
def name(self):
12-
return self.get_processor_name()
13-
149
def __init__(self, *args, **kwargs) -> None:
1510
pass
1611

@@ -37,9 +32,7 @@ def matches_content(self, content: Any, first_line: str, name: str) -> bool:
3732
"""
3833
pass
3934

40-
def process(
41-
self, name: str, content: typing.Any, report_builder: ReportBuilder
42-
) -> Report:
35+
def process(self, name: str, content: Any, report_builder: ReportBuilder) -> Report:
4336
"""Processes a report uploaded by the user, returning a `Report`
4437
4538
This is the base function which we need to implement
@@ -61,7 +54,3 @@ def process(
6154
ReportExpiredException: If the report is considered expired
6255
"""
6356
pass
64-
65-
@classmethod
66-
def get_processor_name(cls) -> str:
67-
return cls.__name__

services/report/languages/bullseye.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import typing
21
from xml.etree.ElementTree import Element
32

3+
import sentry_sdk
44
from shared.reports.resources import Report
55
from timestring import Date
66

@@ -18,17 +18,17 @@ class BullseyeProcessor(BaseLanguageProcessor):
1818
def matches_content(self, content: Element, first_line: str, name: str) -> bool:
1919
return "BullseyeCoverage" in content.tag
2020

21+
@sentry_sdk.trace
2122
def process(
22-
self, name: str, content: typing.Any, report_builder: ReportBuilder
23+
self, name: str, content: Element, report_builder: ReportBuilder
2324
) -> Report:
2425
return from_xml(content, report_builder.create_report_builder_session(name))
2526

2627

27-
def from_xml(xml, report_builder_session: ReportBuilderSession):
28-
path_fixer, ignored_lines, sessionid, yaml = (
28+
def from_xml(xml: Element, report_builder_session: ReportBuilderSession):
29+
path_fixer, ignored_lines, yaml = (
2930
report_builder_session.path_fixer,
3031
report_builder_session.ignored_lines,
31-
report_builder_session.sessionid,
3232
report_builder_session.current_yaml,
3333
)
3434
if read_yaml_field(yaml, ("codecov", "max_report_age"), "12h ago"):

services/report/languages/clover.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import typing
1+
from xml.etree.ElementTree import Element
22

3+
import sentry_sdk
34
from shared.reports.resources import Report
45
from timestring import Date
56

@@ -14,11 +15,12 @@
1415

1516

1617
class CloverProcessor(BaseLanguageProcessor):
17-
def matches_content(self, content, first_line, name):
18-
return bool(content.tag == "coverage" and content.attrib.get("generated"))
18+
def matches_content(self, content: Element, first_line: str, name: str) -> bool:
19+
return content.tag == "coverage" and bool(content.attrib.get("generated"))
1920

21+
@sentry_sdk.trace
2022
def process(
21-
self, name: str, content: typing.Any, report_builder: ReportBuilder
23+
self, name: str, content: Element, report_builder: ReportBuilder
2224
) -> Report:
2325
report_builder_session = report_builder.create_report_builder_session(name)
2426
return from_xml(content, report_builder_session)
@@ -38,11 +40,10 @@ def get_end_of_file(filename, xmlfile):
3840
pass
3941

4042

41-
def from_xml(xml, report_builder_session: ReportBuilderSession) -> Report:
42-
path_fixer, ignored_lines, sessionid, yaml = (
43+
def from_xml(xml: Element, report_builder_session: ReportBuilderSession) -> Report:
44+
path_fixer, ignored_lines, yaml = (
4345
report_builder_session.path_fixer,
4446
report_builder_session.ignored_lines,
45-
report_builder_session.sessionid,
4647
report_builder_session.current_yaml,
4748
)
4849

services/report/languages/cobertura.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import logging
22
import re
3-
import typing
43
from typing import List
4+
from xml.etree.ElementTree import Element
55

6+
import sentry_sdk
67
from shared.reports.resources import Report
78
from timestring import Date, TimestringInvalid
89

@@ -19,13 +20,15 @@
1920

2021

2122
class CoberturaProcessor(BaseLanguageProcessor):
22-
def matches_content(self, content, first_line, name):
23-
if bool(list(content.iter("coverage"))):
24-
return True
25-
return bool(list(content.iter("scoverage")))
23+
def matches_content(self, content: Element, first_line: str, name: str) -> bool:
24+
return bool(
25+
next(content.iter("coverage"), None)
26+
or next(content.iter("scoverage"), None)
27+
)
2628

29+
@sentry_sdk.trace
2730
def process(
28-
self, name: str, content: typing.Any, report_builder: ReportBuilder
31+
self, name: str, content: Element, report_builder: ReportBuilder
2932
) -> Report:
3033
report_builder_session = report_builder.create_report_builder_session(name)
3134
return from_xml(content, report_builder_session)
@@ -43,11 +46,10 @@ def get_sources_to_attempt(xml) -> List[str]:
4346
return [s for s in sources if isinstance(s, str) and s.startswith("/")]
4447

4548

46-
def from_xml(xml, report_builder_session: ReportBuilderSession) -> Report:
47-
path_fixer, ignored_lines, sessionid, repo_yaml = (
49+
def from_xml(xml: Element, report_builder_session: ReportBuilderSession) -> Report:
50+
path_fixer, ignored_lines, repo_yaml = (
4851
report_builder_session.path_fixer,
4952
report_builder_session.ignored_lines,
50-
report_builder_session.sessionid,
5153
report_builder_session.current_yaml,
5254
)
5355

services/report/languages/coveralls.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import typing
2-
1+
import sentry_sdk
32
from shared.reports.resources import Report
43

54
from services.report.languages.base import BaseLanguageProcessor
@@ -11,26 +10,21 @@
1110

1211

1312
class CoverallsProcessor(BaseLanguageProcessor):
14-
def matches_content(self, content, first_line, name):
15-
return detect(content)
13+
def matches_content(self, content: dict, first_line: str, name: str) -> bool:
14+
return "source_files" in content
1615

16+
@sentry_sdk.trace
1717
def process(
18-
self, name: str, content: typing.Any, report_builder: ReportBuilder
18+
self, name: str, content: dict, report_builder: ReportBuilder
1919
) -> Report:
2020
return from_json(content, report_builder.create_report_builder_session(name))
2121

2222

23-
def detect(report):
24-
return "source_files" in report
25-
26-
27-
def from_json(report, report_builder_session: ReportBuilderSession) -> Report:
23+
def from_json(report: dict, report_builder_session: ReportBuilderSession) -> Report:
2824
# https://github.com/codecov/support/issues/253
29-
path_fixer, ignored_lines, sessionid, repo_yaml = (
25+
path_fixer, ignored_lines = (
3026
report_builder_session.path_fixer,
3127
report_builder_session.ignored_lines,
32-
report_builder_session.sessionid,
33-
report_builder_session.current_yaml,
3428
)
3529
for _file in report["source_files"]:
3630
filename = path_fixer(_file["name"])

services/report/languages/csharp.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import typing
21
from collections import defaultdict
32
from itertools import repeat
3+
from xml.etree.ElementTree import Element
44

5+
import sentry_sdk
56
from shared.reports.resources import Report
67

78
from services.report.languages.base import BaseLanguageProcessor
@@ -13,11 +14,12 @@
1314

1415

1516
class CSharpProcessor(BaseLanguageProcessor):
16-
def matches_content(self, content, first_line, name):
17-
return bool(content.tag == "CoverageSession")
17+
def matches_content(self, content: Element, first_line: str, name: str) -> bool:
18+
return content.tag == "CoverageSession"
1819

20+
@sentry_sdk.trace
1921
def process(
20-
self, name: str, content: typing.Any, report_builder: ReportBuilder
22+
self, name: str, content: Element, report_builder: ReportBuilder
2123
) -> Report:
2224
report_builder_session = report_builder.create_report_builder_session(name)
2325
return from_xml(content, report_builder_session)
@@ -38,7 +40,7 @@ def _build_branches(branch_gen):
3840
return branches
3941

4042

41-
def from_xml(xml, report_builder_session: ReportBuilderSession) -> Report:
43+
def from_xml(xml: Element, report_builder_session: ReportBuilderSession) -> Report:
4244
"""
4345
https://github.com/OpenCover/opencover/issues/293#issuecomment-94598145
4446
@sl - start line
@@ -50,13 +52,10 @@ def from_xml(xml, report_builder_session: ReportBuilderSession) -> Report:
5052
@vc - statement executed
5153
<SequencePoint vc="2" uspid="3" ordinal="0" offset="0" sl="35" sc="8" el="35" ec="9" bec="0" bev="0" fileid="1" />
5254
"""
53-
ignored_lines, sessionid = (
54-
report_builder_session.ignored_lines,
55-
report_builder_session.sessionid,
56-
)
55+
ignored_lines = report_builder_session.ignored_lines
56+
5757
# dict of {"fileid": "path"}
5858
file_by_id = {}
59-
file_by_id_get = file_by_id.get
6059
file_by_name = {None: None}
6160
for f in xml.iter("File"):
6261
filename = report_builder_session.path_fixer(

services/report/languages/dlst.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import typing
21
from io import BytesIO
32

3+
import sentry_sdk
44
from shared.reports.resources import Report
55
from shared.reports.types import ReportLine
66

@@ -12,16 +12,17 @@
1212

1313

1414
class DLSTProcessor(BaseLanguageProcessor):
15-
def matches_content(self, content, first_line, name):
16-
return bool(content[-7:] == b"covered")
15+
def matches_content(self, content: bytes, first_line: str, name: str) -> bool:
16+
return content[-7:] == b"covered"
1717

18+
@sentry_sdk.trace
1819
def process(
19-
self, name: str, content: typing.Any, report_builder: ReportBuilder
20+
self, name: str, content: bytes, report_builder: ReportBuilder
2021
) -> Report:
2122
return from_string(content, report_builder.create_report_builder_session(name))
2223

2324

24-
def from_string(string, report_builder_session: ReportBuilderSession) -> Report:
25+
def from_string(string: bytes, report_builder_session: ReportBuilderSession) -> Report:
2526
path_fixer, ignored_lines, sessionid, filename = (
2627
report_builder_session.path_fixer,
2728
report_builder_session.ignored_lines,

services/report/languages/elm.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import typing
2-
1+
import sentry_sdk
32
from shared.reports.resources import Report
43

54
from services.report.languages.base import BaseLanguageProcessor
@@ -11,21 +10,21 @@
1110

1211

1312
class ElmProcessor(BaseLanguageProcessor):
14-
def matches_content(self, content, first_line, name):
13+
def matches_content(self, content: dict, first_line: str, name: str) -> bool:
1514
return isinstance(content, dict) and bool(content.get("coverageData"))
1615

16+
@sentry_sdk.trace
1717
def process(
18-
self, name: str, content: typing.Any, report_builder: ReportBuilder
18+
self, name: str, content: dict, report_builder: ReportBuilder
1919
) -> Report:
2020
report_builder_session = report_builder.create_report_builder_session(name)
2121
return from_json(content, report_builder_session)
2222

2323

24-
def from_json(json, report_builder_session: ReportBuilderSession) -> Report:
25-
path_fixer, ignored_lines, sessionid = (
24+
def from_json(json: dict, report_builder_session: ReportBuilderSession) -> Report:
25+
path_fixer, ignored_lines = (
2626
report_builder_session.path_fixer,
2727
report_builder_session.ignored_lines,
28-
report_builder_session.sessionid,
2928
)
3029
for name, data in json["coverageData"].items():
3130
fn = path_fixer(json["moduleMap"][name])

services/report/languages/flowcover.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import typing
2-
1+
import sentry_sdk
32
from shared.reports.resources import Report
43

54
from services.report.languages.base import BaseLanguageProcessor
@@ -11,23 +10,23 @@
1110

1211

1312
class FlowcoverProcessor(BaseLanguageProcessor):
14-
def matches_content(self, content, first_line, name):
13+
def matches_content(self, content: dict, first_line: str, name: str) -> bool:
1514
return isinstance(content, dict) and bool(content.get("flowStatus"))
1615

16+
@sentry_sdk.trace
1717
def process(
18-
self, name: str, content: typing.Any, report_builder: ReportBuilder
18+
self, name: str, content: dict, report_builder: ReportBuilder
1919
) -> Report:
2020
report_builder_session = report_builder.create_report_builder_session(
2121
filepath=name
2222
)
2323
return from_json(content, report_builder_session)
2424

2525

26-
def from_json(json, report_builder_session: ReportBuilderSession) -> Report:
27-
path_fixer, ignored_lines, sessionid = (
26+
def from_json(json: dict, report_builder_session: ReportBuilderSession) -> Report:
27+
path_fixer, ignored_lines = (
2828
report_builder_session.path_fixer,
2929
report_builder_session.ignored_lines,
30-
report_builder_session.sessionid,
3130
)
3231

3332
for fn, data in json["files"].items():

0 commit comments

Comments
 (0)