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

Force colors from mypy always, strip in pants when --no-colors #16586

Merged
merged 2 commits into from
Sep 9, 2022

Conversation

huonw
Copy link
Contributor

@huonw huonw commented Aug 19, 2022

This fixes #16451 by continuing the color half of #16488 (terminal width).

It does this by forcing mypy to always include color escapes, and then stripping them out in pants, based on the [GLOBAL].colors setting.

This seems to only be possible via an undocumented environment variable: MYPY_FORCE_COLOR: python/mypy#7771, https://github.com/python/mypy/blob/03638dd670373db0b8f00cc3bcec256d09729d06/mypy/util.py#L543

Doing this also requires setting TERM=linux so that curses can find appropriate info in the terminfo database.

[ci skip-rust]

[ci skip-build-wheels]

@huonw
Copy link
Contributor Author

huonw commented Aug 19, 2022

NB. this is exactly the removed code from #16488, without fixing the linux-specific problems described in #16488 (comment). If someone else hasn't magically solved them for me, I'll try to work through it sometime next week.

[ci skip-rust]

[ci skip-build-wheels]
@huonw
Copy link
Contributor Author

huonw commented Sep 9, 2022

TERM=ansi seems to be even simpler, without the annoying extra characters, based on infocmp ansi both on my macOS machine and in a ubuntu:20.04 container.

Copy link
Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Awesome, thanks a lot!

report: Digest = EMPTY_DIGEST,
) -> CheckResult:
def prep_output(s: bytes) -> str:
return strip_v2_chroot_path(s) if strip_chroot_path else s.decode()
chroot = strip_v2_chroot_path(s) if strip_chroot_path else s.decode()
formatting = cast(str, colors.strip_color(chroot)) if strip_formatting else chroot
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure this cast is safe, because strip_colors uses a str regex rather than a binary one?

@stuhood stuhood added this to the 2.14.x milestone Sep 9, 2022
@stuhood stuhood marked this pull request as ready for review September 9, 2022 18:20
@stuhood stuhood merged commit cef98ae into pantsbuild:main Sep 9, 2022
@huonw
Copy link
Contributor Author

huonw commented Sep 9, 2022

Yay, thanks!

stuhood pushed a commit to stuhood/pants that referenced this pull request Sep 9, 2022
…build#16586)

This fixes pantsbuild#16451 by continuing the color half of pantsbuild#16488 (terminal width).

It does this by forcing mypy to always include color escapes, and then stripping them out in pants, based on the [GLOBAL].colors setting.

This seems to only be possible via an undocumented environment variable: `MYPY_FORCE_COLOR`: python/mypy#7771, https://github.com/python/mypy/blob/03638dd670373db0b8f00cc3bcec256d09729d06/mypy/util.py#L543

Doing this also requires setting `TERM=linux` so that curses can find appropriate info in the terminfo database.

[ci skip-rust]
[ci skip-build-wheels]
stuhood added a commit that referenced this pull request Sep 9, 2022
…y-pick of #16586) (#16808)

This fixes #16451 by continuing the color half of #16488 (terminal width).

It does this by forcing mypy to always include color escapes, and then stripping them out in pants, based on the [GLOBAL].colors setting.

This seems to only be possible via an undocumented environment variable: `MYPY_FORCE_COLOR`: python/mypy#7771, https://github.com/python/mypy/blob/03638dd670373db0b8f00cc3bcec256d09729d06/mypy/util.py#L543

Doing this also requires setting `TERM=linux` so that curses can find appropriate info in the terminfo database.

[ci skip-rust]
[ci skip-build-wheels]
@huonw huonw deleted the bugfix/16451-mypy-colors branch September 11, 2022 22:52
Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Thanks!! Exciting :)

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.

mypy output is limited to 80 characters wide and no colours
3 participants