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

mypy output is limited to 80 characters wide and no colours #16451

Closed
huonw opened this issue Aug 9, 2022 · 0 comments · Fixed by #16586
Closed

mypy output is limited to 80 characters wide and no colours #16451

huonw opened this issue Aug 9, 2022 · 0 comments · Fixed by #16586
Labels
backend: Python Python backend-related issues bug

Comments

@huonw
Copy link
Contributor

huonw commented Aug 9, 2022

Describe the bug

Mypy has various nifty affordances to make it easier to understand its errors, e.g. colours and (with --pretty) printing the relevant line. It seems like pants currently gets in the way of these, presumably because mypy is detecting the non-tty output buffering.

For instance, https://gist.github.com/ce2e03d8788848ad6db27df6d66cde6d

a_really_really_really_long_variable_name = 12345678901234567890 + "this makes the line really long"

Running mypy via ./pants check :: gives output:

image

While running it normally mypy --pretty broken.py (with the same version 0.961 installed via pip) gives output:

image

The first output is worse:

  • line truncation despite (much) wider terminal (if the main error message was longer, it'd be wrapped, too, which makes it extra hard to read)
  • lack of colours/bold

Pants version

  • 2.12.0
  • 2.14.0.dev5

OS
macOS

Additional info

Exact reproduction steps:

git clone https://gist.github.com/ce2e03d8788848ad6db27df6d66cde6d
cd ce2e03d8788848ad6db27df6d66cde6d

./pants check ::

mypy --version
mypy --pretty broken.py
@huonw huonw added the bug label Aug 9, 2022
Eric-Arellano pushed a commit that referenced this issue Aug 19, 2022
This fixes part of #16451 by ensuring that the mypy output isn't truncated/hard-wrapped at all. In particular: the terminal width is forcibly set to be very wide ("infinite") because soft-wrapped display in a wide terminal is nicer than it being hard-wrapped/truncated to 80 cols.

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

[ci skip-rust]
@thejcannon thejcannon added the backend: Python Python backend-related issues label Aug 19, 2022
cczona pushed a commit to cczona/pants that referenced this issue Sep 1, 2022
This fixes part of pantsbuild#16451 by ensuring that the mypy output isn't truncated/hard-wrapped at all. In particular: the terminal width is forcibly set to be very wide ("infinite") because soft-wrapped display in a wide terminal is nicer than it being hard-wrapped/truncated to 80 cols.

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

[ci skip-rust]
stuhood pushed a commit that referenced this issue Sep 9, 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]
stuhood pushed a commit to stuhood/pants that referenced this issue 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 issue 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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Python Python backend-related issues bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants