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

Add flag for printing reports in colour #89

Merged
merged 8 commits into from
Jan 3, 2024
Merged

Add flag for printing reports in colour #89

merged 8 commits into from
Jan 3, 2024

Conversation

meshy
Copy link
Collaborator

@meshy meshy commented Jan 2, 2024

With this new --color (or --colour, or -c) flag, the error report can now be printed in colour.

The selected colour scheme (mostly) matches that of Mypy. (I didn't bother adding URL highlighting in notes. Please let me know if you want this.)

I used ANSI colour codes for this to avoid adding a dependency, but please let me know if you would prefer this to make use of a library such as rich or colorist.

image
image
image
image

Happy New Year!

meshy added 2 commits January 2, 2024 16:01
This was last referenced in 44a7fed.
Before this change the logic for writing the report to stdout was a part
of ChangeTracker.

By extracting this to a separate class, we allow for other writer
classes to be implemented.
@meshy meshy marked this pull request as ready for review January 2, 2024 22:53
@meshy meshy requested a review from Tenzer January 2, 2024 22:53
@meshy meshy marked this pull request as draft January 3, 2024 11:59
@meshy meshy removed the request for review from Tenzer January 3, 2024 11:59
@meshy
Copy link
Collaborator Author

meshy commented Jan 3, 2024

I've taken this out of review for a moment, because I intend to do a refactor PR first, and land this afterwards. That'll make it easier to revamp #18

Copy link
Member

@Tenzer Tenzer left a comment

Choose a reason for hiding this comment

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

Happy new year Charlie!

Thank you for this, I've raised a few suggestions.

mypy_json_report.py Show resolved Hide resolved
tests/test_mypy_json_report.py Outdated Show resolved Hide resolved
mypy_json_report.py Outdated Show resolved Hide resolved
mypy_json_report.py Outdated Show resolved Hide resolved
mypy_json_report.py Outdated Show resolved Hide resolved
mypy_json_report.py Outdated Show resolved Hide resolved
mypy_json_report.py Outdated Show resolved Hide resolved
@meshy
Copy link
Collaborator Author

meshy commented Jan 3, 2024

Thanks for the review! I'll address your points so we can get this in, and then in contrast to what I said earlier, I'll do the refactor after :)

@meshy
Copy link
Collaborator Author

meshy commented Jan 3, 2024

@Tenzer I've addressed your points an rebased them in.

The commit which changes is "Add ColorChangeReportWriter", and I have created one new commit, "Change spacing around report summary".

Copy link
Member

@Tenzer Tenzer left a comment

Choose a reason for hiding this comment

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

One minor thing left, then I think this is good to merge (assuming that you're ready for it - the PR is currently a draft).

I'll make a release when this has been merged in.

mypy_json_report.py Outdated Show resolved Hide resolved
@meshy meshy force-pushed the color-report branch 2 times, most recently from aef0e35 to 2530a10 Compare January 3, 2024 15:21
@meshy meshy marked this pull request as ready for review January 3, 2024 15:21
@meshy
Copy link
Collaborator Author

meshy commented Jan 3, 2024

All updated -- thank you!

meshy added 6 commits January 3, 2024 15:22
This class can be used to print out change reports in colour.

The colours selected closely match those output by Mypy, with the
exception that links are not highlighted in notes.

The logic is inspired by Mypy's highlighting code.
(See https://github.com/python/mypy/blob/f9e8e0bda5cfbb54d6a8f9e482aa25da28a1a635/mypy/util.py#L761)

This supports only ANSI colours, so I suspect that this will not work on
Windows.
Before this change an empty line would be printed above the summary when
there were no new errors, and no empty line would be printed when there
were errors.

This change reverses that. An empty line is printed to separate the
summary from the new errors only if there are new errors.
@Tenzer Tenzer merged commit df7c82f into main Jan 3, 2024
6 checks passed
@Tenzer Tenzer deleted the color-report branch January 3, 2024 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants