Skip to content

Commit

Permalink
Merge pull request #356 from akaihola/no-color-env-var
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola authored Apr 20, 2022
2 parents 5ec6580 + 838d2c1 commit 9033d01
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 98 deletions.
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

0 comments on commit 9033d01

Please sign in to comment.