Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify ReportBuilderSession usage within LanguageProcessors #684

Merged
merged 7 commits into from
Sep 10, 2024

Conversation

Swatinem
Copy link
Contributor

@Swatinem Swatinem commented Sep 4, 2024

This includes various refactorings:

Switches to using create_coverage_line instead of creating ReportLines directly.
And switches to using .append() instead of relying on an assignment operator.

This also includes some simplifications like moving read_yaml_field out of loops, etc.

Switches all LanguageProcessors to using ReportBuilderSession, and pass such a ReportBuilderSession to the process method.

Simplifies the signature of create_coverage_line and its usage, and introduces a new create_coverage_file method as well which incorporates the PathFixer application and the ignored lines.


fixes codecov/engineering-team#2392

@Swatinem Swatinem self-assigned this Sep 4, 2024
@codecov-staging
Copy link

codecov-staging bot commented Sep 4, 2024

Codecov Report

Attention: Patch coverage is 93.48110% with 50 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files Patch % Lines
services/report/languages/jetbrainsxml.py 16.66% 15 Missing ⚠️
services/report/languages/mono.py 23.07% 10 Missing ⚠️
services/report/languages/xcode.py 84.61% 6 Missing ⚠️
services/report/languages/elm.py 28.57% 5 Missing ⚠️
services/report/languages/node.py 95.34% 4 Missing ⚠️
services/report/languages/gcov.py 90.00% 2 Missing ⚠️
services/report/languages/vb2.py 88.23% 2 Missing ⚠️
services/report/languages/base.py 66.66% 1 Missing ⚠️
services/report/languages/bullseye.py 96.00% 1 Missing ⚠️
services/report/languages/pycoverage.py 92.30% 1 Missing ⚠️
... and 3 more

Impacted file tree graph

@@           Coverage Diff            @@
##             main     #684    +/-   ##
========================================
  Coverage   98.09%   98.09%            
========================================
  Files         433      434     +1     
  Lines       36752    36548   -204     
========================================
- Hits        36051    35852   -199     
+ Misses        701      696     -5     
Flag Coverage Δ
integration 98.09% <93.48%> (+<0.01%) ⬆️
latest-uploader-overall 98.09% <93.48%> (+<0.01%) ⬆️
unit 98.09% <93.48%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 96.01% <90.25%> (+<0.01%) ⬆️
OutsideTasks 98.09% <93.48%> (+<0.01%) ⬆️
Files Coverage Δ
services/report/languages/clover.py 98.33% <100.00%> (-0.22%) ⬇️
services/report/languages/cobertura.py 96.26% <100.00%> (+0.03%) ⬆️
services/report/languages/coveralls.py 100.00% <100.00%> (ø)
services/report/languages/csharp.py 98.36% <100.00%> (-0.11%) ⬇️
services/report/languages/dlst.py 100.00% <100.00%> (ø)
services/report/languages/flowcover.py 91.30% <100.00%> (+2.01%) ⬆️
services/report/languages/gap.py 100.00% <100.00%> (+4.44%) ⬆️
services/report/languages/go.py 98.01% <100.00%> (-0.10%) ⬇️
services/report/languages/jacoco.py 100.00% <100.00%> (ø)
services/report/languages/lcov.py 96.80% <100.00%> (-0.04%) ⬇️
... and 53 more

@codecov-qa
Copy link

codecov-qa bot commented Sep 4, 2024

Codecov Report

Attention: Patch coverage is 93.48110% with 50 lines in your changes missing coverage. Please review.

Project coverage is 98.09%. Comparing base (a4ee062) to head (b82aab4).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
services/report/languages/jetbrainsxml.py 16.66% 15 Missing ⚠️
services/report/languages/mono.py 23.07% 10 Missing ⚠️
services/report/languages/xcode.py 84.61% 6 Missing ⚠️
services/report/languages/elm.py 28.57% 5 Missing ⚠️
services/report/languages/node.py 95.34% 4 Missing ⚠️
services/report/languages/gcov.py 90.00% 2 Missing ⚠️
services/report/languages/vb2.py 88.23% 2 Missing ⚠️
services/report/languages/base.py 66.66% 1 Missing ⚠️
services/report/languages/bullseye.py 96.00% 1 Missing ⚠️
services/report/languages/pycoverage.py 92.30% 1 Missing ⚠️
... and 3 more

Impacted file tree graph

@@           Coverage Diff            @@
##             main     #684    +/-   ##
========================================
  Coverage   98.09%   98.09%            
========================================
  Files         433      434     +1     
  Lines       36752    36548   -204     
========================================
- Hits        36051    35852   -199     
+ Misses        701      696     -5     
Flag Coverage Δ
integration 98.09% <93.48%> (+<0.01%) ⬆️
latest-uploader-overall 98.09% <93.48%> (+<0.01%) ⬆️
unit 98.09% <93.48%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 96.01% <90.25%> (+<0.01%) ⬆️
OutsideTasks 98.09% <93.48%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
services/report/languages/clover.py 98.33% <100.00%> (-0.22%) ⬇️
services/report/languages/cobertura.py 96.26% <100.00%> (+0.03%) ⬆️
services/report/languages/coveralls.py 100.00% <100.00%> (ø)
services/report/languages/csharp.py 98.36% <100.00%> (-0.11%) ⬇️
services/report/languages/dlst.py 100.00% <100.00%> (ø)
services/report/languages/flowcover.py 91.30% <100.00%> (+2.01%) ⬆️
services/report/languages/gap.py 100.00% <100.00%> (+4.44%) ⬆️
services/report/languages/go.py 98.01% <100.00%> (-0.10%) ⬇️
services/report/languages/jacoco.py 100.00% <100.00%> (ø)
services/report/languages/lcov.py 96.80% <100.00%> (-0.04%) ⬇️
... and 53 more

Copy link

codecov-public-qa bot commented Sep 4, 2024

Codecov Report

Attention: Patch coverage is 93.48110% with 50 lines in your changes missing coverage. Please review.

Project coverage is 98.09%. Comparing base (a4ee062) to head (b82aab4).

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@           Coverage Diff            @@
##             main     #684    +/-   ##
========================================
  Coverage   98.09%   98.09%            
========================================
  Files         433      434     +1     
  Lines       36752    36548   -204     
========================================
- Hits        36051    35852   -199     
+ Misses        701      696     -5     
Flag Coverage Δ
integration 98.09% <93.48%> (+<0.01%) ⬆️
latest-uploader-overall 98.09% <93.48%> (+<0.01%) ⬆️
unit 98.09% <93.48%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 96.01% <90.25%> (+<0.01%) ⬆️
OutsideTasks 98.09% <93.48%> (+<0.01%) ⬆️
Files Coverage Δ
services/report/languages/clover.py 98.33% <100.00%> (-0.22%) ⬇️
services/report/languages/cobertura.py 96.26% <100.00%> (+0.03%) ⬆️
services/report/languages/coveralls.py 100.00% <100.00%> (ø)
services/report/languages/csharp.py 98.36% <100.00%> (-0.11%) ⬇️
services/report/languages/dlst.py 100.00% <100.00%> (ø)
services/report/languages/flowcover.py 91.30% <100.00%> (+2.01%) ⬆️
services/report/languages/gap.py 100.00% <100.00%> (+4.44%) ⬆️
services/report/languages/go.py 98.01% <100.00%> (-0.10%) ⬇️
services/report/languages/jacoco.py 100.00% <100.00%> (ø)
services/report/languages/lcov.py 96.80% <100.00%> (-0.04%) ⬇️
... and 53 more

Copy link

codecov bot commented Sep 4, 2024

Codecov Report

Attention: Patch coverage is 93.48110% with 50 lines in your changes missing coverage. Please review.

Project coverage is 98.13%. Comparing base (a4ee062) to head (b82aab4).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
services/report/languages/jetbrainsxml.py 16.66% 15 Missing ⚠️
services/report/languages/mono.py 23.07% 10 Missing ⚠️
services/report/languages/xcode.py 84.61% 6 Missing ⚠️
services/report/languages/elm.py 28.57% 5 Missing ⚠️
services/report/languages/node.py 95.34% 4 Missing ⚠️
services/report/languages/gcov.py 90.00% 2 Missing ⚠️
services/report/languages/vb2.py 88.23% 2 Missing ⚠️
services/report/languages/base.py 66.66% 1 Missing ⚠️
services/report/languages/bullseye.py 96.00% 1 Missing ⚠️
services/report/languages/pycoverage.py 92.30% 1 Missing ⚠️
... and 3 more
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main     #684    +/-   ##
========================================
  Coverage   98.13%   98.13%            
========================================
  Files         475      475            
  Lines       38107    37903   -204     
========================================
- Hits        37396    37198   -198     
+ Misses        711      705     -6     
Flag Coverage Δ
integration 98.09% <93.48%> (+<0.01%) ⬆️
latest-uploader-overall 98.09% <93.48%> (+<0.01%) ⬆️
unit 98.09% <93.48%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 96.11% <90.25%> (+<0.01%) ⬆️
OutsideTasks 98.09% <93.48%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
services/report/languages/clover.py 98.33% <100.00%> (-0.22%) ⬇️
services/report/languages/cobertura.py 96.26% <100.00%> (+0.03%) ⬆️
services/report/languages/coveralls.py 100.00% <100.00%> (ø)
services/report/languages/csharp.py 98.36% <100.00%> (-0.11%) ⬇️
services/report/languages/dlst.py 100.00% <100.00%> (ø)
services/report/languages/flowcover.py 91.30% <100.00%> (+2.01%) ⬆️
services/report/languages/gap.py 100.00% <100.00%> (+4.44%) ⬆️
services/report/languages/go.py 98.01% <100.00%> (-0.10%) ⬇️
services/report/languages/jacoco.py 100.00% <100.00%> (ø)
services/report/languages/lcov.py 96.93% <100.00%> (-0.04%) ⬇️
... and 53 more
Related Entrypoints
run/app.tasks.profiling.normalizer
run/app.tasks.upload.UploadProcessor

Copy link
Contributor

@giovanni-guidini giovanni-guidini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

Copy link
Contributor

@matt-codecov matt-codecov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whew, that was a lot

looks great except for a type annotation for coverage in create_coverage_line

services/report/languages/gcov.py Outdated Show resolved Hide resolved
def create_coverage_line(
self,
coverage,
coverage: int,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't always an int :( sometimes it is a fraction represented as a string (example: https://github.com/codecov/worker/blob/50142115/services/report/languages/bullseye.py#L73)

according to the types in shared, it's actually a Decimal, but i have not seen that be true https://github.com/codecov/shared/blob/36c00afb1ad34185c795227816ceb9eaa252645d/shared/reports/types.py#L135

in Node it can apparently be a Fraction https://github.com/codecov/worker/blob/50142115/services/report/languages/node.py#L308. except that's just in the partials field, which according to the types in shared is Sequence[int] (which is wrong, i've only ever seen [(start_col, end_col, coverage)] (we drop the start/end lines))

as an aside: my local https://livegrep.com/search/linux instance is really helpful for codebase exploration like this. i searched cov(erage)? = path:services/report/langu and (Fraction|Decimal) repo:worker|shared -path:migrations|models to find those code pointers. my setup indexes worker, shared, api, codecov-rs, and more, is much faster/more responsive than github search, and is written up at https://l.codecov.dev/kPqYLC (open on VPN) if you want to run your own

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to int | str now. The type in shared being wider than this is fine.

Also in general I don’t really trust the type annotations at all (yet), so there might be some followups to do.

Comment on lines +26 to +31
filename = method.attrib["filename"]
if filename not in files:
_file = report_builder_session.create_coverage_file(filename)
files[filename] = _file
_file = files[filename]
if _file is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be thorough: it's okay that the key in files is the unfixed path, right? it doesn't look like we try to use the fixed filename from the coverage file as a key ever, so i think so

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I think thats fine, I even think it might be good for perf as the path fixing can be slow sometimes. Some other language processors seem to cache that stuff, but usage is definitely not consistent.

services/report/languages/vb.py Show resolved Hide resolved
report_builder_session.ignored_lines,
)

files: dict[str, ReportFile] = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably fine, but this has changed scope and will not clear files between "modules"

wish i understood this format to know whether that's important

@@ -70,12 +67,6 @@ def get_partials_in_line(line):


def from_txt(content: bytes, report_builder_session: ReportBuilderSession) -> Report:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one day codecov-rs will have samples and documentation for this so reviewing it isn't so difficult :P

Switches to using `create_coverage_line` instead of creating `ReportLine`s directly.
And switches to using `.append()` instead of relying on an assignment operator.

This also includes some simplifications like moving `read_yaml_field` out of loops, etc.
@Swatinem Swatinem force-pushed the swatinem/report-builder branch from d798aa0 to b82aab4 Compare September 10, 2024 08:39
@Swatinem Swatinem enabled auto-merge September 10, 2024 08:39
@Swatinem Swatinem added this pull request to the merge queue Sep 10, 2024
Merged via the queue into main with commit ab427f8 Sep 10, 2024
24 of 27 checks passed
@Swatinem Swatinem deleted the swatinem/report-builder branch September 10, 2024 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[codecov-rs/python] Make all our old parsers use ReportBuilderSession
3 participants