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

Fix compatibility with Black >= 21.7b1.dev9 #183

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Added
- Terminate with an error if non-existing files or directories are passed on the command
line. This also improves the error from misquoted parameters like ``"--lint pylint"``.
- Allow Git test case to run slower when checking file timestamps. CI can be slow.
- Fix compatibility with Black >= 21.7b1.dev9

Fixed
-----
Expand Down
11 changes: 10 additions & 1 deletion src/darker/black_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@

import logging
import sys
from distutils.version import LooseVersion
akaihola marked this conversation as resolved.
Show resolved Hide resolved
from pathlib import Path
from typing import Collection, Optional, Pattern, Set, Tuple

# `FileMode as Mode` required to satisfy mypy==0.782. Strange.
from black import FileMode as Mode
from black import TargetVersion
from black import __version__ as black_version
from black import (
TargetVersion,
find_pyproject_toml,
format_str,
parse_pyproject_toml,
Expand All @@ -65,6 +67,7 @@

DEFAULT_EXCLUDE_RE = re_compile_maybe_verbose(DEFAULT_EXCLUDES)
DEFAULT_INCLUDE_RE = re_compile_maybe_verbose(DEFAULT_INCLUDES)
BLACK_VERSION = LooseVersion(black_version)


class BlackConfig(TypedDict, total=False):
Expand Down Expand Up @@ -131,6 +134,11 @@ def apply_black_excludes(
:return: Absolute paths of files which should be reformatted using Black

"""
kwargs = (
{}
if BLACK_VERSION < LooseVersion("21.7b1.dev9")
else {"quiet": True, "verbose": False}
)
return set(
gen_python_files(
(root / path for path in paths),
Expand All @@ -141,6 +149,7 @@ def apply_black_excludes(
force_exclude=black_config.get("force_exclude"),
report=Report(),
gitignore=None,
**kwargs,
)
)

Expand Down