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

Integrate verbose logging with get_sources #3749

Merged
merged 4 commits into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<!-- Changes to Black's terminal output and error messages -->

- Use aware UTC datetimes internally, avoids deprecation warning on Python 3.12 (#3728)
- Change verbose logging to exactly mirror _Black_'s logic for source discovery (#3749)

### _Blackd_

Expand Down
30 changes: 10 additions & 20 deletions src/black/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,26 +481,6 @@ def main( # noqa: C901
fg="blue",
)

normalized = [
(
(source, source)
if source == "-"
else (normalize_path_maybe_ignore(Path(source), root), source)
)
for source in src
]
srcs_string = ", ".join(
[
(
f'"{_norm}"'
if _norm
else f'\033[31m"{source} (skipping - invalid)"\033[34m'
)
for _norm, source in normalized
]
)
out(f"Sources to be formatted: {srcs_string}", fg="blue")

if config:
config_source = ctx.get_parameter_source("config")
user_level_config = str(find_user_pyproject_toml())
Expand Down Expand Up @@ -653,7 +633,11 @@ def get_sources(
if is_stdin or p.is_file():
normalized_path = normalize_path_maybe_ignore(p, ctx.obj["root"], report)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the mypyc build is broken here (see the diff-shades output in CI); it infers None for this variable.

if normalized_path is None:
if verbose:
out(f'Skipping invalid source: "{normalized_path}"', fg="red")
continue
if verbose:
out(f'Found input source: "{normalized_path}"', fg="blue")

normalized_path = "/" + normalized_path
# Hard-exclude any files that matches the `--force-exclude` regex.
Expand All @@ -676,6 +660,9 @@ def get_sources(
sources.add(p)
elif p.is_dir():
p = root / normalize_path_maybe_ignore(p, ctx.obj["root"], report)
if verbose:
out(f'Found input source directory: "{p}"', fg="blue")

if using_default_exclude:
gitignore = {
root: root_gitignore,
Expand All @@ -696,9 +683,12 @@ def get_sources(
)
)
elif s == "-":
if verbose:
out("Found input source stdin", fg="blue")
sources.add(p)
else:
err(f"invalid path: {s}")

return sources


Expand Down