]>
git.madduck.net Git - etc/vim.git/blobdiff - src/black/__init__.py
madduck's git repository
Every one of the projects in this repository is available at the canonical
URL git://git.madduck.net/madduck/pub/<projectpath> — see
each project's metadata for the exact URL.
All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@ git. madduck. net .
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
SSH access, as well as push access can be individually
arranged .
If you use my repositories frequently, consider adding the following
snippet to ~/.gitconfig and using the third clone URL listed for each
project:
[url "git://git.madduck.net/madduck/"]
insteadOf = madduck:
from black.mode import Mode, TargetVersion
from black.mode import Feature, supports_feature, VERSION_TO_FEATURES
from black.cache import read_cache, write_cache, get_cache_info, filter_cached, Cache
from black.mode import Mode, TargetVersion
from black.mode import Feature, supports_feature, VERSION_TO_FEATURES
from black.cache import read_cache, write_cache, get_cache_info, filter_cached, Cache
-from black.concurrency import cancel, shutdown
+from black.concurrency import cancel, shutdown, maybe_install_uvloop
from black.output import dump_to_file, diff, color_diff, out, err
from black.report import Report, Changed
from black.files import find_project_root, find_pyproject_toml, parse_pyproject_toml
from black.output import dump_to_file, diff, color_diff, out, err
from black.report import Report, Changed
from black.files import find_project_root, find_pyproject_toml, parse_pyproject_toml
from _black_version import version as __version__
from _black_version import version as __version__
-# If our environment has uvloop installed lets use it
-try:
- import uvloop
-
- uvloop.install()
-except ImportError:
- pass
-
# types
FileContent = str
Encoding = str
# types
FileContent = str
Encoding = str
is_flag=True,
help="If --fast given, skip temporary sanity checks. [default: --safe]",
)
is_flag=True,
help="If --fast given, skip temporary sanity checks. [default: --safe]",
)
+@click.option(
+ "--required-version",
+ type=str,
+ help=(
+ "Require a specific version of Black to be running (useful for unifying results"
+ " across many environments e.g. with a pyproject.toml file)."
+ ),
+)
@click.option(
"--include",
type=str,
@click.option(
"--include",
type=str,
exists=True, file_okay=True, dir_okay=True, readable=True, allow_dash=True
),
is_eager=True,
exists=True, file_okay=True, dir_okay=True, readable=True, allow_dash=True
),
is_eager=True,
)
@click.option(
"--config",
)
@click.option(
"--config",
experimental_string_processing: bool,
quiet: bool,
verbose: bool,
experimental_string_processing: bool,
quiet: bool,
verbose: bool,
include: Pattern,
exclude: Optional[Pattern],
extend_exclude: Optional[Pattern],
include: Pattern,
exclude: Optional[Pattern],
extend_exclude: Optional[Pattern],
config: Optional[str],
) -> None:
"""The uncompromising code formatter."""
config: Optional[str],
) -> None:
"""The uncompromising code formatter."""
+ if config and verbose:
+ out(f"Using configuration from {config}.", bold=False, fg="blue")
+
+ error_msg = "Oh no! 💥 💔 💥"
+ if required_version and required_version != __version__:
+ err(
+ f"{error_msg} The required version `{required_version}` does not match"
+ f" the running version `{__version__}`!"
+ )
+ ctx.exit(1)
+
write_back = WriteBack.from_configuration(check=check, diff=diff, color=color)
if target_version:
versions = set(target_version)
write_back = WriteBack.from_configuration(check=check, diff=diff, color=color)
if target_version:
versions = set(target_version)
magic_trailing_comma=not skip_magic_trailing_comma,
experimental_string_processing=experimental_string_processing,
)
magic_trailing_comma=not skip_magic_trailing_comma,
experimental_string_processing=experimental_string_processing,
)
- if config and verbose:
- out(f"Using configuration from {config}.", bold=False, fg="blue")
if code is not None:
# Run in quiet mode by default with -c; the extra output isn't useful.
if code is not None:
# Run in quiet mode by default with -c; the extra output isn't useful.
)
if verbose or not quiet:
)
if verbose or not quiet:
- out("Oh no! 💥 💔 💥" if report.return_code else "All done! ✨ 🍰 ✨")
+ out(error_msg if report.return_code else "All done! ✨ 🍰 ✨")
- click.s echo(str(report), err=True)
+ click.echo(str(report), err=True)
ctx.exit(report.return_code)
ctx.exit(report.return_code)
)
if write_back == WriteBack.YES:
# Make sure there's a newline after the content
)
if write_back == WriteBack.YES:
# Make sure there's a newline after the content
- dst += "" if dst[-1] == "\n" else "\n"
+ if dst and dst[-1] != "\n":
+ dst += "\n"
f.write(dst)
elif write_back in (WriteBack.DIFF, WriteBack.COLOR_DIFF):
now = datetime.utcnow()
f.write(dst)
elif write_back in (WriteBack.DIFF, WriteBack.COLOR_DIFF):
now = datetime.utcnow()
def patched_main() -> None:
def patched_main() -> None:
freeze_support()
patch_click()
main()
freeze_support()
patch_click()
main()