-
Notifications
You must be signed in to change notification settings - Fork 287
Add interface to writer modules #755
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
Add interface to writer modules #755
Conversation
Add read_report interface to format objects.
Codecov ReportPatch coverage:
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
Flags with carried forward coverage won't be shown. Click here to find out 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. |
There was a problem hiding this 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`) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
It was also a long wish from my side.
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'll push new commits for your suggestions. |
Use PascalCase for all classes.
f2502ba to
22a1e78
Compare
22a1e78 to
c0f2709
Compare
* 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 --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]>
* 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 --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]>
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 thegcovformat 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-tracefiledoesn'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.