Skip to content

Commit

Permalink
Check excludes before symlink resolution for command line parameters
Browse files Browse the repository at this point in the history
This adjusts exclusion checking for command line parameters the same way
as psf#3846 did for other files. Specifically, --force-exclude is now
checked before symlink resolution. This way symlink handling is
consistent between command line parameters and other collected files.

Fixes psf#3826.
  • Loading branch information
sth committed Oct 27, 2023
1 parent c369e44 commit 221fed3
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/black/__init__.py
Expand Up @@ -50,6 +50,7 @@
get_gitignore,
normalize_path_maybe_ignore,
parse_pyproject_toml,
path_is_excluded,
wrap_stream_for_windows,
)
from black.handle_ipynb_magics import (
Expand Down Expand Up @@ -639,25 +640,26 @@ def get_sources(
is_stdin = False

if is_stdin or p.is_file():
root_relative_path = p.absolute().relative_to(root).as_posix()

root_relative_path = "/" + root_relative_path
if p.is_dir():
root_relative_path += "/"

# Hard-exclude any files that matches the `--force-exclude` regex.
if path_is_excluded(root_relative_path, force_exclude):
report.path_ignored(p, "matches the --force-exclude regular expression")
continue

normalized_path: Optional[str] = normalize_path_maybe_ignore(
p, root, report
)
if normalized_path is None:
if verbose:
out(f'Skipping invalid source: "{normalized_path}"', fg="red")
out(f'Skipping invalid source: "{p}"', 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.
if force_exclude:
force_exclude_match = force_exclude.search(normalized_path)
else:
force_exclude_match = None
if force_exclude_match and force_exclude_match.group(0):
report.path_ignored(p, "matches the --force-exclude regular expression")
continue
out(f'Found input source: "{p}"', fg="blue")

if is_stdin:
p = Path(f"{STDIN_PLACEHOLDER}{str(p)}")
Expand Down

0 comments on commit 221fed3

Please sign in to comment.