Skip to content

Commit

Permalink
Add special config verbose log case when black is using user-level co…
Browse files Browse the repository at this point in the history
…nfig (#2861)
  • Loading branch information
Shivansh-007 committed Feb 21, 2022
1 parent 8089aaa commit c26c772
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

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

- In verbose, mode, log when _Black_ is using user-level config (#2861)

### Packaging

<!-- Changes to how Black is packaged, such as dependency requirements -->
Expand Down
21 changes: 18 additions & 3 deletions src/black/__init__.py
Original file line number Diff line number Diff line change
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

0 comments on commit c26c772

Please sign in to comment.