-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve Black import error [optional-black-improvement]
- Loading branch information
Showing
5 changed files
with
63 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Attempt to import Black internals needed by the Black formatter plugin.""" | ||
|
||
import logging | ||
|
||
from darker.exceptions import DependencyError | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
try: | ||
import black # noqa: F401 # pylint: disable=unused-import | ||
except ImportError as exc: | ||
logger.warning( | ||
"To re-format code using Black, install it using e.g." | ||
" `pip install 'darker[black]'` or" | ||
" `pip install black`" | ||
) | ||
logger.warning( | ||
"To use a different formatter or no formatter, select it on the" | ||
" command line (e.g. `--formatter=none`) or configuration" | ||
" (e.g. `formatter=none`)" | ||
) | ||
MESSAGE = "Can't find the Black package" | ||
raise DependencyError(MESSAGE) from exc | ||
|
||
from black import ( # noqa: E402 # pylint: disable=unused-import,wrong-import-position | ||
FileMode, | ||
TargetVersion, | ||
format_str, | ||
parse_pyproject_toml, | ||
re_compile_maybe_verbose, | ||
) | ||
|
||
|
||
__all__ = [ | ||
"FileMode", | ||
"TargetVersion", | ||
"format_str", | ||
"parse_pyproject_toml", | ||
"re_compile_maybe_verbose", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters