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

Add special config verbose log case when black is using user-level config #2861

Merged
merged 5 commits into from Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -34,6 +34,8 @@

<!-- Changes to Black's terminal output and error messages -->

- Add special config verbose log case when black is using user-level config (#2861)
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved

### Packaging

<!-- Changes to how Black is packaged, such as dependency requirements -->
Expand Down
21 changes: 18 additions & 3 deletions src/black/__init__.py
Expand Up @@ -49,7 +49,12 @@
from black.concurrency import cancel, shutdown, maybe_install_uvloop
from black.output import dump_to_file, ipynb_diff, diff, color_diff, out, err
from black.report import Report, Changed, NothingChanged
from black.files import find_project_root, find_pyproject_toml, parse_pyproject_toml
from black.files import (
find_project_root,
find_pyproject_toml,
parse_pyproject_toml,
find_user_pyproject_toml,
)
from black.files import gen_python_files, get_gitignore, normalize_path_maybe_ignore
from black.files import wrap_stream_for_windows
from black.parsing import InvalidInput # noqa F401
Expand Down Expand Up @@ -402,7 +407,7 @@ def validate_regex(
help="Read configuration from FILE path.",
)
@click.pass_context
def main(
def main( # noqa: C901
ctx: click.Context,
code: Optional[str],
line_length: int,
Expand Down Expand Up @@ -469,7 +474,17 @@ def main(

if config:
config_source = ctx.get_parameter_source("config")
if config_source in (ParameterSource.DEFAULT, ParameterSource.DEFAULT_MAP):
user_level_config = str(find_user_pyproject_toml())
if config == user_level_config:
out(
f"Using configuration from user-level config at "
f"'{user_level_config}'.",
fg="blue",
)
elif config_source in (
ParameterSource.DEFAULT,
ParameterSource.DEFAULT_MAP,
):
out("Using configuration from project root.", fg="blue")
else:
out(f"Using configuration in '{config}'.", fg="blue")
Expand Down