Skip to content

Commit

Permalink
Merge pull request #1950 from jeremyheiler/black-config-lookup-fix
Browse files Browse the repository at this point in the history
Use black for loading black config
  • Loading branch information
gopar committed Dec 8, 2021
2 parents 8d0de31 + 0803e76 commit a7c72a4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion elpy/blackutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def parse_version(*arg, **kwargs):
black = None
else:
import black
current_version = parse_version(black.__version__)
if current_version >= parse_version("21.5b1"):
from black.files import find_pyproject_toml
elif current_version >= parse_version("20.8b0"):
from black import find_pyproject_toml
else:
find_pyproject_toml = None

except ImportError: # pragma: no cover
black = None

Expand All @@ -43,7 +51,10 @@ def fix_code(code, directory):
# Get black config from pyproject.toml
line_length = black.DEFAULT_LINE_LENGTH
string_normalization = True
pyproject_path = os.path.join(directory, "pyproject.toml")
if find_pyproject_toml:
pyproject_path = find_pyproject_toml((directory,))
else:
pyproject_path = os.path.join(directory, "pyproject.toml")
if toml is not None and os.path.exists(pyproject_path):
pyproject_config = toml.load(pyproject_path)
black_config = pyproject_config.get("tool", {}).get("black", {})
Expand Down

0 comments on commit a7c72a4

Please sign in to comment.