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

feat: GitHub and JSON formatted printers #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

estahn
Copy link

@estahn estahn commented Jul 22, 2023

The issue with print_lines using logger.info still persists. The issue being that docstr_coverage > results.txt does contain the progress bar. I suggest either add a parameter for an output file or remove the progress bar.

This is how it looks like:

📚 docstr_coverage status: ❌ FAILED

Overall coverage: 76% (required 80%)

Additional details and impacted files
Filename Needed Found Missing Coverage
docstr_coverage/__init__.py 1 0 1 0.0%
docstr_coverage/badge.py 7 6 1 85.7%
docstr_coverage/cli.py 9 7 2 77.8%
docstr_coverage/config_file.py 3 3 0 100.0%
docstr_coverage/coverage.py 5 5 0 100.0%
docstr_coverage/ignore_config.py 12 11 1 91.7%
docstr_coverage/printers.py 16 9 7 56.2%
docstr_coverage/result_collection.py 29 20 9 69.0%
docstr_coverage/visitor.py 14 12 2 85.7%

Copy link
Collaborator

@MiWeiss MiWeiss left a comment

Choose a reason for hiding this comment

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

Hi @estahn

Thanks a lot for opening the PR. This is a big step towards a very useful feature. I did not yet do a full review, but left some comments which I spotted on a quick glimpse.

In addition, we would need the following before merging:

  • Tests of the new functionality
  • Type-Hints, where possible
  • Docstrings ;-)

raise NotImplementedError()


class LegacyPrinter(Printer):
"""Printing functionality consistent with the original early-versions docstr-coverage outputs.

In future versions, the interface of this class will be refined and an abstract superclass
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we can remove this comment in the docstring


success = total_results["coverage"] >= self.fail_under

print_line("## [:books: docstr_coverage](https://docstr-coverage.readthedocs.io/en/latest/api_essentials.html) status: %s **%s**" % (self._status_icon(success), self._status_text(success)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably link to the github readme instead of the RTD (which should be significantly improved or disabled anyways)

@@ -147,3 +164,63 @@ def _print_overall_statistics(self, results):
)

print_line("Total coverage: {:.1f}% - Grade: {}".format(count.coverage(), grade))


class JsonPrinter(Printer):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume that the JsonPrinter is primarily used in use cases where the output is interpreted by a machine (which thus allows easy deserialization). We've had such feature requests in the past.

Thus, the printer should provide the maximum amount of available information. The results.to_legacy() only provides an aggregated overview; it would be better to serialize all information present in results (which, as opposed to results.to_legacy(), may also be extended with additional fields in the future).

If that's too much work, we can of course remove the JsonPrinter in this PR and open a dedicated issue/PR for that.

print(json.dumps({"files": file_results, "result": total_results}))


class GitHubCommentPrinter(Printer):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am understanding it correctly that this is indeed Github specific (and not plain markdown) because of the icons you use, right? Just asking to double-check to understand why the class is named as it is. Maybe we should call it GithubMarkdownPrinter?

In either case, some docstring could not hurt ;-)

@@ -5,6 +5,7 @@
import enum
import functools
import operator
import os
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need this?

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.

None yet

2 participants