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

Support the NO_COLOR environment variable #356

Merged
merged 14 commits into from
Apr 20, 2022
Merged
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ Added
- Sort imports only if the range of modified lines overlaps with changes resulting from
sorting the imports.
- Allow force enabling/disabling of syntax highlighting using the ``color`` option in
``pyproject.toml``, the ``PY_COLORS`` environment variable, and the
``pyproject.toml``, the ``PY_COLORS`` and ``NO_COLOR`` environment variables, and the
``--color``/``--no-color`` command line options.
- Syntax highlighting is now enabled by default in the GitHub Action.
- ``pytest>=6.2.0`` now required for the test suite due to type hinting issues.

Fixed
-----
Expand Down
2 changes: 1 addition & 1 deletion constraints-oldest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ flake8-bugbear==22.1.11
flake8-comprehensions==3.7.0
mypy==0.940
Pygments==2.4.0
pytest==6.1.0
pytest==6.2.0
pytest-flake8==1.0.6
pytest-isort==1.1.0
pytest-kwparametrize==0.0.3
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test =
mypy>=0.940
pygments
pylint
pytest>=6.1.0
pytest>=6.2.0
pytest-darker
pytest-flake8>=1.0.6
pytest-isort>=1.1.0
Expand Down
11 changes: 7 additions & 4 deletions src/darker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,14 @@ def override_color_with_environment(pyproject_config: DarkerConfig) -> DarkerCon
:return: The modified configuration
"""
py_colors = os.getenv("PY_COLORS")
if py_colors not in {"0", "1"}:
return pyproject_config
config = pyproject_config.copy()
config["color"] = py_colors == "1"
py_colors = os.getenv("PY_COLORS")
if py_colors in {"0", "1"}:
config["color"] = py_colors == "1"
elif os.getenv("NO_COLOR") is not None:
config["color"] = False
elif os.getenv("FORCE_COLOR") is not None:
config["color"] = True
return config


Expand Down
Loading