X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/df1c86cbe7cf0727d81e526e904b0752d7371da0..6380b9f2f6e53748360a120ed9acb874a35885e0:/src/black/__init__.py?ds=sidebyside diff --git a/src/black/__init__.py b/src/black/__init__.py index d95e9b1..a985926 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -241,6 +241,14 @@ def validate_regex( 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, @@ -351,6 +359,7 @@ def main( experimental_string_processing: bool, quiet: bool, verbose: bool, + required_version: str, include: Pattern, exclude: Optional[Pattern], extend_exclude: Optional[Pattern], @@ -360,6 +369,17 @@ def main( 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) @@ -374,8 +394,6 @@ def main( 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. @@ -428,9 +446,9 @@ def main( ) 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! ✨ 🍰 ✨") if code is None: - click.secho(str(report), err=True) + click.echo(str(report), err=True) ctx.exit(report.return_code)