Skip to content

Commit

Permalink
main: add FORCE_COLOR
Browse files Browse the repository at this point in the history
Signed-off-by: Filipe Laíns <lains@riseup.net>
  • Loading branch information
FFY00 committed Jul 28, 2021
1 parent dfa7b6f commit dbff04b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Unreleased

- Improved output (`PR #333`_, Fixes `#142`_)
- The CLI now honnors `NO_COLOR`_ (`PR #333`_)
- The CLI can now be forced to colorize the output by setting the ``FORCE_COLOR`` environment variable (`PR #335`_)
- Added logging to ``build`` and ``build.env`` (`PR #333`_)


Expand All @@ -17,6 +18,7 @@ Breaking Changes
- Dropped support for Python 2 and 3.5.

.. _PR #333: https://github.com/pypa/build/pull/333
.. _PR #335: https://github.com/pypa/build/pull/335
.. _#142: https://github.com/pypa/build/issues/142
.. _NO_COLOR: https://no-color.org

Expand Down
2 changes: 1 addition & 1 deletion src/build/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
'underline': '\33[4m',
'reset': '\33[0m',
}
if not sys.stdout.isatty() or 'NO_COLOR' in os.environ:
if 'FORCE_COLOR' not in os.environ and not sys.stdout.isatty() or 'NO_COLOR' in os.environ:
_STYLES = {color: '' for color in _STYLES}


Expand Down
5 changes: 3 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,9 @@ def test_output_env_subprocess_error(
stdout_body,
stdout_error,
):
mocker.patch('sys.stdout.isatty', return_value=True)
if not color:
if color:
monkeypatch.setenv('FORCE_COLOR', '')
else:
monkeypatch.setenv('NO_COLOR', '')

importlib.reload(build.__main__) # reload module to set _STYLES
Expand Down

0 comments on commit dbff04b

Please sign in to comment.