File tree 3 files changed +32
-11
lines changed 3 files changed +32
-11
lines changed Original file line number Diff line number Diff line change 34
34
### Configuration
35
35
36
36
- Add support for single-line format skip with other comments on the same line (#3959 )
37
-
37
+ - Consistently apply force exclusion logic before resolving symlinks ( # 4015 )
38
38
- Fix a bug in the matching of absolute path names in ` --include ` (#3976 )
39
39
40
40
### Packaging
Original file line number Diff line number Diff line change @@ -682,24 +682,26 @@ def get_sources(
682
682
path = Path (s )
683
683
is_stdin = False
684
684
685
+ # Compare the logic here to the logic in `gen_python_files`.
685
686
if is_stdin or path .is_file ():
687
+ root_relative_path = path .absolute ().relative_to (root ).as_posix ()
688
+
689
+ root_relative_path = "/" + root_relative_path
690
+
691
+ # Hard-exclude any files that matches the `--force-exclude` regex.
692
+ if path_is_excluded (root_relative_path , force_exclude ):
693
+ report .path_ignored (
694
+ path , "matches the --force-exclude regular expression"
695
+ )
696
+ continue
697
+
686
698
normalized_path : Optional [str ] = normalize_path_maybe_ignore (
687
699
path , root , report
688
700
)
689
701
if normalized_path is None :
690
702
if verbose :
691
703
out (f'Skipping invalid source: "{ normalized_path } "' , fg = "red" )
692
704
continue
693
- if verbose :
694
- out (f'Found input source: "{ normalized_path } "' , fg = "blue" )
695
-
696
- normalized_path = "/" + normalized_path
697
- # Hard-exclude any files that matches the `--force-exclude` regex.
698
- if path_is_excluded (normalized_path , force_exclude ):
699
- report .path_ignored (
700
- path , "matches the --force-exclude regular expression"
701
- )
702
- continue
703
705
704
706
if is_stdin :
705
707
path = Path (f"{ STDIN_PLACEHOLDER } { str (path )} " )
@@ -709,6 +711,8 @@ def get_sources(
709
711
):
710
712
continue
711
713
714
+ if verbose :
715
+ out (f'Found input source: "{ normalized_path } "' , fg = "blue" )
712
716
sources .add (path )
713
717
elif path .is_dir ():
714
718
path = root / (path .resolve ().relative_to (root ))
Original file line number Diff line number Diff line change @@ -2637,6 +2637,23 @@ def test_get_sources_with_stdin_filename_and_force_exclude(self) -> None:
2637
2637
stdin_filename = stdin_filename ,
2638
2638
)
2639
2639
2640
+ @patch ("black.find_project_root" , lambda * args : (THIS_DIR .resolve (), None ))
2641
+ def test_get_sources_with_stdin_filename_and_force_exclude_and_symlink (
2642
+ self ,
2643
+ ) -> None :
2644
+ # Force exclude should exclude a symlink based on the symlink, not its target
2645
+ path = THIS_DIR / "data" / "include_exclude_tests"
2646
+ stdin_filename = str (path / "symlink.py" )
2647
+ expected = [f"__BLACK_STDIN_FILENAME__{ stdin_filename } " ]
2648
+ target = path / "b/exclude/a.py"
2649
+ with patch ("pathlib.Path.resolve" , return_value = target ):
2650
+ assert_collected_sources (
2651
+ src = ["-" ],
2652
+ expected = expected ,
2653
+ force_exclude = r"exclude/a\.py" ,
2654
+ stdin_filename = stdin_filename ,
2655
+ )
2656
+
2640
2657
2641
2658
class TestDeFactoAPI :
2642
2659
"""Test that certain symbols that are commonly used externally keep working.
You can’t perform that action at this time.
0 commit comments