Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Spacetown
Copy link
Member

@Spacetown Spacetown commented Mar 23, 2023

This is the second approach to create a interface for the different formats because #474 was outdated.

As suggested in the previous PR the reader and writer code is now loaded on demand which can improve the startup performance of gcovr. Also the gcov format is now handled as a reader and we are open to extend to other input formats.

The whole handling of the exit codes is done in __main__.py. Constants for the exit codes are added. A separate exitcode for the reading code is introduced which results in a different exit code if th option --add-tracefile doesn't match a file (old 1, new 8)

The options are prepared for each format separate to give only the common options and the format specific options to the reader/writer.

@codecov
Copy link

codecov bot commented Mar 24, 2023

Codecov Report

Patch coverage: 94.53% and project coverage change: -0.02 ⚠️

Comparison is base (b448d69) 95.44% compared to head (c0f2709) 95.42%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #755      +/-   ##
==========================================
- Coverage   95.44%   95.42%   -0.02%     
==========================================
  Files          28       40      +12     
  Lines        3796     3979     +183     
  Branches      671      682      +11     
==========================================
+ Hits         3623     3797     +174     
- Misses         95      103       +8     
- Partials       78       79       +1     
Flag Coverage Δ
ubuntu-20.04 94.19% <94.53%> (+0.04%) ⬆️
windows-2019 95.08% <94.53%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
gcovr/formats/gcov/workers.py 98.83% <ø> (ø)
gcovr/formats/base.py 77.77% <77.77%> (ø)
gcovr/formats/html/write.py 95.47% <78.57%> (ø)
gcovr/decision_analysis.py 87.64% <80.00%> (ø)
gcovr/formats/__init__.py 85.13% <85.13%> (ø)
gcovr/formats/gcov/parser.py 97.61% <87.50%> (ø)
gcovr/formats/gcov/read.py 79.60% <88.13%> (ø)
gcovr/formats/json/read.py 94.36% <94.36%> (ø)
gcovr/__main__.py 96.93% <94.54%> (+3.28%) ⬆️
gcovr/options.py 99.34% <99.34%> (ø)
... and 25 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Spacetown Spacetown marked this pull request as ready for review March 26, 2023 18:38
@Spacetown Spacetown requested a review from latk March 26, 2023 18:46
Copy link
Member

@latk latk left a comment

Choose a reason for hiding this comment

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

Thank you for doing this work! I think this refactoring helps make the individual formats more manageable, and editing command line options should now be less scary than having to scroll through a 1000-line file.

I think most formats don't need to be split into separate __init__ and write files. The ability to lazily load implementations is most relevant for the XML and HTML formats, and we now have a very high degree of namespace nesting (from ...utils import foo is not necessarily obvious). However, I don't feel strongly about this.

I have stronger opinions about the design of the handler classes, which I've commented inline.

If there is any doubt about how to proceed, I would suggest to rather merge this as-is, and fix any issues in later PRs. All of these changes should have purely internal effects and are reversible if needed (aside from the new CLI option aliases). This is clearly a step in a good direction.

Internal changes:

- Do not scrub versions in reference data. (:issue:`747`)
- Add interface for the different formats to easily add new formats. (:issue:`755`)
Copy link
Member

Choose a reason for hiding this comment

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

The Changelog does not yet mention the new CLI option aliases like --txt-summary.

Copy link
Member Author

Choose a reason for hiding this comment

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

In my opinion the new options should be the mentioned ones and the ones without the format prefix are only for compatibility reasons.

@Spacetown
Copy link
Member Author

Thank you for doing this work! I think this refactoring helps make the individual formats more manageable, and editing command line options should now be less scary than having to scroll through a 1000-line file.

It was also a long wish from my side.

I think most formats don't need to be split into separate __init__ and write files. The ability to lazily load implementations is most relevant for the XML and HTML formats, and we now have a very high degree of namespace nesting (from ...utils import foo is not necessarily obvious). However, I don't feel strongly about this.

I've done this to have the same structure for each format. How is about json formats, is the loading of the JSON stuff faster than the XML once?

I have stronger opinions about the design of the handler classes, which I've commented inline.
If there is any doubt about how to proceed, I would suggest to rather merge this as-is, and fix any issues in later PRs. All of these changes should have purely internal effects and are reversible if needed (aside from the new CLI option aliases). This is clearly a step in a good direction.

I'll push new commits for your suggestions.

@Spacetown Spacetown force-pushed the add_interface_to_writer_modules branch from f2502ba to 22a1e78 Compare March 28, 2023 19:51
@Spacetown Spacetown force-pushed the add_interface_to_writer_modules branch from 22a1e78 to c0f2709 Compare March 29, 2023 19:13
@Spacetown Spacetown merged commit d6cd30b into gcovr:master Mar 29, 2023
@Spacetown Spacetown deleted the add_interface_to_writer_modules branch March 29, 2023 19:28
@Spacetown Spacetown mentioned this pull request Mar 30, 2023
frankwiles pushed a commit to revsys/gcovr that referenced this pull request Apr 4, 2023
* Move formats to sub directories.
* Move function print_reports from __main__.py to writer/__init__.py.
* Write global logger uppercase because it's constant.
* Move gcov data handling to a own format handler
* Use constants for the exit code.
* Add prefix of format to each option.
* Only forward the options of the format and some generic options to the handler.
* Add one config key for each long option.
Spacetown added a commit that referenced this pull request Aug 14, 2023
* Add --template-dir option to README

* Add to other file

* Add --template-dir argument

* Fix typo

* Finish --template-dir option

Pass options down to `templates()` everywhere it's called.
Change which jinja2 loader is used depending on existence of the
argument.

* Add useful docs for --template-dir

* Add thread information to logging (#752)

* Add thread to log messages if multithreading is active.

* Fix nested report if only one directory in root is present. (#750)

- Add comments and to collapse code and remove not needed endless loop.
The loop is always executed only once because because the first statement in the block isn't changed in a second iteration.
- Collapse also the data in the root.
- Use `pop(key)` instead of copying the whole dict ignoring the value.
- Fix evaluating of common path in nested HTML report.
The root_filter wasn't applied to the root directory in HTML report since there is no trailing path separator at the end. Now the directories always have a trailing path separator which is removed in the report generation. To get the common path part the root directory is excluded.
- Replace recursive generation of directory stats with a loop.
- Use a object instead of a dataclass and remove the recursive function and the tests for it.
- Improve detection of root directory.

* Add interface to writer modules (#755)

* Move formats to sub directories.
* Move function print_reports from __main__.py to writer/__init__.py.
* Write global logger uppercase because it's constant.
* Move gcov data handling to a own format handler
* Use constants for the exit code.
* Add prefix of format to each option.
* Only forward the options of the format and some generic options to the handler.
* Add one config key for each long option.

* Add --html-template-dir argument

* Finish --html-template-dir option

Pass options down to `templates()` everywhere it's called.
Change which jinja2 loader is used depending on existence of the
argument.

* Resolve merge issue and refactor

- Refactor based on suggestion

* Fix merge and refactor to new output layout

- Refactors code to use new `gcovr/formats/` layout
- Renames option to `--html-template-dir`
- Fixes merge artifacts I created on accident

* Add Frank Wiles to AUTHORS.txt

* Use Jinja2 ChoiceLoader

This allows the user to only have to override the certain templates
they wish to adjust and it will fall through to using the included
ones for any template names the user has not overriden in
`--html-template-dir`

* Update documentation to reflect ChoiceLoader

* Fix docs typo

* Fix README typo

* Remove merge mistake

* Update CHANGELOG

* Add --html-template-dir test

* Change what we're testing on --html-template-dir

* Fix test again

* Improve template-dir option docs

* Improve template-dir docs

* Add tests to ensure templates are overridden

- Ensure the two we override are indeed overidden
- Ensure we fall through to default templates if not

* Remove debugging print

* Add template test

* Forgot to save Makefile change

* Update failing HTML/CSS comparison

* Update gcovr/tests/test_html_generator.py

Co-authored-by: Michael Förderer <[email protected]>

* Fix linting issue

* Remove test that behaves oddly in CI

* Fix CI run

* Update documentation

* Update reference data

* Fix documentation error

---------

Co-authored-by: Michael Förderer <[email protected]>
@Spacetown Spacetown removed this from the Upcoming release milestone Jan 26, 2024
D-Walther pushed a commit to D-Walther/gcovr that referenced this pull request Jun 16, 2025
* Move formats to sub directories.
* Move function print_reports from __main__.py to writer/__init__.py.
* Write global logger uppercase because it's constant.
* Move gcov data handling to a own format handler
* Use constants for the exit code.
* Add prefix of format to each option.
* Only forward the options of the format and some generic options to the handler.
* Add one config key for each long option.
D-Walther pushed a commit to D-Walther/gcovr that referenced this pull request Jun 16, 2025
* Add --template-dir option to README

* Add to other file

* Add --template-dir argument

* Fix typo

* Finish --template-dir option

Pass options down to `templates()` everywhere it's called.
Change which jinja2 loader is used depending on existence of the
argument.

* Add useful docs for --template-dir

* Add thread information to logging (gcovr#752)

* Add thread to log messages if multithreading is active.

* Fix nested report if only one directory in root is present. (gcovr#750)

- Add comments and to collapse code and remove not needed endless loop.
The loop is always executed only once because because the first statement in the block isn't changed in a second iteration.
- Collapse also the data in the root.
- Use `pop(key)` instead of copying the whole dict ignoring the value.
- Fix evaluating of common path in nested HTML report.
The root_filter wasn't applied to the root directory in HTML report since there is no trailing path separator at the end. Now the directories always have a trailing path separator which is removed in the report generation. To get the common path part the root directory is excluded.
- Replace recursive generation of directory stats with a loop.
- Use a object instead of a dataclass and remove the recursive function and the tests for it.
- Improve detection of root directory.

* Add interface to writer modules (gcovr#755)

* Move formats to sub directories.
* Move function print_reports from __main__.py to writer/__init__.py.
* Write global logger uppercase because it's constant.
* Move gcov data handling to a own format handler
* Use constants for the exit code.
* Add prefix of format to each option.
* Only forward the options of the format and some generic options to the handler.
* Add one config key for each long option.

* Add --html-template-dir argument

* Finish --html-template-dir option

Pass options down to `templates()` everywhere it's called.
Change which jinja2 loader is used depending on existence of the
argument.

* Resolve merge issue and refactor

- Refactor based on suggestion

* Fix merge and refactor to new output layout

- Refactors code to use new `gcovr/formats/` layout
- Renames option to `--html-template-dir`
- Fixes merge artifacts I created on accident

* Add Frank Wiles to AUTHORS.txt

* Use Jinja2 ChoiceLoader

This allows the user to only have to override the certain templates
they wish to adjust and it will fall through to using the included
ones for any template names the user has not overriden in
`--html-template-dir`

* Update documentation to reflect ChoiceLoader

* Fix docs typo

* Fix README typo

* Remove merge mistake

* Update CHANGELOG

* Add --html-template-dir test

* Change what we're testing on --html-template-dir

* Fix test again

* Improve template-dir option docs

* Improve template-dir docs

* Add tests to ensure templates are overridden

- Ensure the two we override are indeed overidden
- Ensure we fall through to default templates if not

* Remove debugging print

* Add template test

* Forgot to save Makefile change

* Update failing HTML/CSS comparison

* Update gcovr/tests/test_html_generator.py

Co-authored-by: Michael Förderer <[email protected]>

* Fix linting issue

* Remove test that behaves oddly in CI

* Fix CI run

* Update documentation

* Update reference data

* Fix documentation error

---------

Co-authored-by: Michael Förderer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants