Repository navigation
main: fix replacing color codes in tracebacks - #335
Conversation
Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
gaborbernat
left a comment
There was a problem hiding this comment.
Can we add a test to validate the change?
|
I think adding a test for this that would actually be helpful in development would be very tricky, and I feel like it might not be worth the time. The code that we would be covering would only generate formatting errors, not functional ones which would prevent people from working. |
|
Why would it be tricky? If now the contract is that the output is nicely colored, why would a test validating that be not worth it? tox threats output similarly. We run the code in a subprocess, and then assert the stdout/stderr contains the right series of bytes. If you can run it without needing a new subprocess you can assert on capsys/capfd and do the same. Doesn't have to test color output for all functional cases, just one run that covers all cases. Bugs related to the coloring helper function can be tested by directly calling the helper function from your test. |
Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
gaborbernat
left a comment
There was a problem hiding this comment.
In general looks good, let's just add an environmetn variable to enable color mode 😊
| for name, code in _STYLES.items(): | ||
| message = message.replace(f'[{name}]', code if color else '') | ||
| print(message) | ||
| if not sys.stdout.isatty() or 'NO_COLOR' in os.environ: |
There was a problem hiding this comment.
I like that we have an environment variable to disable color, however can we have also one that force enables it? (e.g. tox 4 cannot forward the tty state into a subprocess yet, so is handy in such cases to force color mode). Perhaps FORCE_COLOR? And if neither set then check the tty state 😊
There was a problem hiding this comment.
Sure. What happens with both FORCE_COLOR and NO_COLOR?
There was a problem hiding this comment.
In my implementation NO_COLOR wins, but 🤷
There was a problem hiding this comment.
See e.g. how this would be used https://github.com/tox-dev/tox/blob/rewrite/tox.ini#L79 (this shows how mypy handles it).
There was a problem hiding this comment.
Shouldn't empty values translate as false for these flags?
There was a problem hiding this comment.
https://no-color.org/ says the mere presence enables the behavior, the value is irrelevant. I think we should have the same behavior in FORCE_COLOR.
There was a problem hiding this comment.
I'm a fan of having a FORCE_COLOR too, as often on GHA (which supports color) things can be missing color. I think no-color.org went overboard - it's a pretty well established practice for an empty environment variable to be the same as unsetting it. It's not always easy to unset an environment variable, and the disconnect there is irritating. But I'd follow what the spec dictates. :(
There was a problem hiding this comment.
I understand the concern and share a similar opinion. IMO, coloring should be disabled if NO_COLOR is present and is not no/false. But given that it is already a pretty well established standard, I think the best option is to follow what is defined.
Signed-off-by: Filipe Laíns <[email protected]>
|
It's not entirely clear what this is fixing. Are you trying to avoid replacing "[dim]" and "[reset]" in the traceback itself? |
|
Yes, as @henryiii pointed out. |
73b44db to
7ec79db
Compare
|
The tests are failing on Windows and I don't really get why. Since I don't have any Windows setup right now, it might be a little while before I am able to set one up and debug the issues. If anyone is able to look into it, I would really appreciate it. |
|
It was colorama. It's a bit weird since this test was passing previously. |
Signed-off-by: Filipe Laíns <[email protected]>
Signed-off-by: Filipe Laíns <[email protected]>
Sorry, wasn't around a computer much this weekend. I technically have a Windows box I boot up once in a while when I'm stuck debugging Windows issues in various packages. I'm perfectly fine to keep that a secret, though. 😅 |
Bumps [build](https://github.com/pypa/build) from 0.5.1 to 0.6.0.post1. <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/pypa/build/blob/main/CHANGELOG.rst">build's changelog</a>.</em></p> <blockquote> <h1>0.6.0.post1 (05-08-2021)</h1> <ul> <li>Fix compability with Python 3.6 and 3.7 (<code>PR [#339](https://github.com/pypa/build/issues/339)</code><em>, Fixes <code>[#338](https://github.com/pypa/build/issues/338)</code></em>)</li> </ul> <p>.. _PR <a href="https://github-redirect.dependabot.com/pypa/build/issues/339">#339</a>: <a href="https://github-redirect.dependabot.com/pypa/build/pull/339">pypa/build#339</a> .. _<a href="https://github-redirect.dependabot.com/pypa/build/issues/338">#338</a>: <a href="https://github-redirect.dependabot.com/pypa/build/issues/338">pypa/build#338</a></p> <h1>0.6.0 (02-08-2021)</h1> <ul> <li>Improved output (<code>PR [#333](https://github.com/pypa/build/issues/333)</code><em>, Fixes <code>[#142](https://github.com/pypa/build/issues/142)</code></em>)</li> <li>The CLI now honnors <code>NO_COLOR</code>_ (<code>PR [#333](https://github.com/pypa/build/issues/333)</code>_)</li> <li>The CLI can now be forced to colorize the output by setting the <code>FORCE_COLOR</code> environment variable (<code>PR [#335](https://github.com/pypa/build/issues/335)</code>_)</li> <li>Added logging to <code>build</code> and <code>build.env</code> (<code>PR [#333](https://github.com/pypa/build/issues/333)</code>_)</li> <li>Switch to a TOML v1 compliant parser (<code>PR [#336](https://github.com/pypa/build/issues/336)</code><em>, Fixes <code>[#308](https://github.com/pypa/build/issues/308)</code></em>)</li> </ul> <h2>Breaking Changes</h2> <ul> <li>Dropped support for Python 2 and 3.5.</li> </ul> <p>.. _PR <a href="https://github-redirect.dependabot.com/pypa/build/issues/333">#333</a>: <a href="https://github-redirect.dependabot.com/pypa/build/pull/333">pypa/build#333</a> .. _PR <a href="https://github-redirect.dependabot.com/pypa/build/issues/335">#335</a>: <a href="https://github-redirect.dependabot.com/pypa/build/pull/335">pypa/build#335</a> .. _PR <a href="https://github-redirect.dependabot.com/pypa/build/issues/336">#336</a>: <a href="https://github-redirect.dependabot.com/pypa/build/pull/336">pypa/build#336</a> .. _<a href="https://github-redirect.dependabot.com/pypa/build/issues/142">#142</a>: <a href="https://github-redirect.dependabot.com/pypa/build/issues/142">pypa/build#142</a> .. _<a href="https://github-redirect.dependabot.com/pypa/build/issues/308">#308</a>: <a href="https://github-redirect.dependabot.com/pypa/build/issues/308">pypa/build#308</a> .. _NO_COLOR: <a href="https://no-color.org">https://no-color.org</a></p> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/pypa/build/commit/018a6f81cca1b26d9bf754eb91a64667c3847d28"><code>018a6f8</code></a> release 0.6.0.post1</li> <li><a href="https://github.com/pypa/build/commit/84412dbbb29f08fdc0040ce75c81107843f7c496"><code>84412db</code></a> changelog: add Python 3.6 and 3.7 compability fix</li> <li><a href="https://github.com/pypa/build/commit/c3f9e6d8c11c6ca3f71159a0347de171395cddd9"><code>c3f9e6d</code></a> build: restore compatibility with Python 3.6 and 3.7</li> <li><a href="https://github.com/pypa/build/commit/720d69dadc1641769be89e3630b12b207e157ca3"><code>720d69d</code></a> tests: enable pytest strict mode</li> <li><a href="https://github.com/pypa/build/commit/4cb0c1ec375aeff3e681855fdb37cf8f47e0fa93"><code>4cb0c1e</code></a> setup.cfg: fix typo in version</li> <li><a href="https://github.com/pypa/build/commit/48c68979d95f070c093125b663dbd074399b5619"><code>48c6897</code></a> release 0.6.0</li> <li><a href="https://github.com/pypa/build/commit/612dde4a4d538d1f0547ee524667b11534cba2cd"><code>612dde4</code></a> build: switch to tomli for TOML v1 compliant parser</li> <li><a href="https://github.com/pypa/build/commit/7ed0a6bf06e05e6ccc72a99fe8194ebb9a2f1d20"><code>7ed0a6b</code></a> main: add line between backend output and missing dependencies error</li> <li><a href="https://github.com/pypa/build/commit/79e777452cf3a75392b858f5ec41fc41eb4403b7"><code>79e7774</code></a> main: refactor color detection</li> <li><a href="https://github.com/pypa/build/commit/03ad5d4af2cb23c13ab2de4672c359afbb99ab6b"><code>03ad5d4</code></a> main: add FORCE_COLOR</li> <li>Additional commits viewable in <a href="https://github.com/pypa/build/compare/0.5.1...0.6.0.post1">compare view</a></li> </ul> </details> <br /> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details>

Signed-off-by: Filipe Laíns [email protected]