@@ -121,7 +121,8 @@ def iter_source_code(paths: Iterable[str], config: Config, skipped: List[str]) -
121
121
122
122
resolved_path = full_path .resolve ()
123
123
if resolved_path in visited_dirs : # pragma: no cover
124
- warn (f"Likely recursive symlink detected to { resolved_path } " )
124
+ if not config .quiet :
125
+ warn (f"Likely recursive symlink detected to { resolved_path } " )
125
126
dirnames .remove (dirname )
126
127
else :
127
128
visited_dirs .add (resolved_path )
@@ -723,20 +724,16 @@ def _build_arg_parser() -> argparse.ArgumentParser:
723
724
724
725
def parse_args (argv : Optional [Sequence [str ]] = None ) -> Dict [str , Any ]:
725
726
argv = sys .argv [1 :] if argv is None else list (argv )
727
+ remapped_deprecated_args = []
726
728
for index , arg in enumerate (argv ):
727
729
if arg in DEPRECATED_SINGLE_DASH_ARGS :
728
- warn (
729
- f"\n \n The following deprecated single dash CLI flags was used: { arg } !\n "
730
- f"It is being auto translated to -{ arg } to maintain backward compatibility.\n "
731
- f"This behavior will be REMOVED in the 6.x.x release and is not guaranteed across"
732
- f" 5.x.x releases.\n \n "
733
- "Please see the 5.0.0 upgrade guide:\n "
734
- "\t https://timothycrosley.github.io/isort/docs/upgrade_guides/5.0.0/\n "
735
- )
730
+ remapped_deprecated_args .append (arg )
736
731
argv [index ] = f"-{ arg } "
737
732
738
733
parser = _build_arg_parser ()
739
734
arguments = {key : value for key , value in vars (parser .parse_args (argv )).items () if value }
735
+ if remapped_deprecated_args :
736
+ arguments ["remapped_deprecated_args" ] = remapped_deprecated_args
740
737
if "dont_order_by_type" in arguments :
741
738
arguments ["order_by_type" ] = False
742
739
multi_line_output = arguments .get ("multi_line_output" , None )
@@ -790,15 +787,6 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
790
787
sys .exit ("Error: arguments passed in without any paths or content." )
791
788
else :
792
789
return
793
- elif file_names == ["-" ] and not show_config :
794
- arguments .setdefault ("settings_path" , os .getcwd ())
795
- api .sort_stream (
796
- input_stream = sys .stdin if stdin is None else stdin ,
797
- output_stream = sys .stdout ,
798
- ** arguments ,
799
- )
800
- return
801
-
802
790
if "settings_path" not in arguments :
803
791
arguments ["settings_path" ] = (
804
792
os .path .abspath (file_names [0 ] if file_names else "." ) or os .getcwd ()
@@ -813,13 +801,8 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
813
801
show_diff = config_dict .pop ("show_diff" , False )
814
802
write_to_stdout = config_dict .pop ("write_to_stdout" , False )
815
803
deprecated_flags = config_dict .pop ("deprecated_flags" , False )
816
-
817
- if deprecated_flags : # pragma: no cover
818
- warn (
819
- f"\n \n The following deprecated CLI flags were used: { ', ' .join (deprecated_flags )} !\n "
820
- "Please see the 5.0.0 upgrade guide:\n "
821
- "\t https://timothycrosley.github.io/isort/docs/upgrade_guides/5.0.0/\n "
822
- )
804
+ remapped_deprecated_args = config_dict .pop ("remapped_deprecated_args" , False )
805
+ wrong_sorted_files = False
823
806
824
807
if "src_paths" in config_dict :
825
808
config_dict ["src_paths" ] = {
@@ -830,74 +813,98 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
830
813
if show_config :
831
814
print (json .dumps (config .__dict__ , indent = 4 , separators = ("," , ": " ), default = _preconvert ))
832
815
return
833
-
834
- wrong_sorted_files = False
835
- skipped : List [str ] = []
836
-
837
- if config .filter_files :
838
- filtered_files = []
839
- for file_name in file_names :
840
- if config .is_skipped (Path (file_name )):
841
- skipped .append (file_name )
842
- else :
843
- filtered_files .append (file_name )
844
- file_names = filtered_files
845
-
846
- file_names = iter_source_code (file_names , config , skipped )
847
- num_skipped = 0
848
- if config .verbose :
849
- print (ASCII_ART )
850
-
851
- if jobs :
852
- import multiprocessing
853
-
854
- executor = multiprocessing .Pool (jobs )
855
- attempt_iterator = executor .imap (
856
- functools .partial (
857
- sort_imports ,
858
- config = config ,
859
- check = check ,
860
- ask_to_apply = ask_to_apply ,
861
- write_to_stdout = write_to_stdout ,
862
- ),
863
- file_names ,
816
+ elif file_names == ["-" ]:
817
+ arguments .setdefault ("settings_path" , os .getcwd ())
818
+ api .sort_stream (
819
+ input_stream = sys .stdin if stdin is None else stdin ,
820
+ output_stream = sys .stdout ,
821
+ ** arguments ,
864
822
)
865
823
else :
866
- # https://github.com/python/typeshed/pull/2814
867
- attempt_iterator = (
868
- sort_imports ( # type: ignore
869
- file_name ,
870
- config = config ,
871
- check = check ,
872
- ask_to_apply = ask_to_apply ,
873
- show_diff = show_diff ,
874
- write_to_stdout = write_to_stdout ,
824
+ skipped : List [str ] = []
825
+
826
+ if config .filter_files :
827
+ filtered_files = []
828
+ for file_name in file_names :
829
+ if config .is_skipped (Path (file_name )):
830
+ skipped .append (file_name )
831
+ else :
832
+ filtered_files .append (file_name )
833
+ file_names = filtered_files
834
+
835
+ file_names = iter_source_code (file_names , config , skipped )
836
+ num_skipped = 0
837
+ if config .verbose :
838
+ print (ASCII_ART )
839
+
840
+ if jobs :
841
+ import multiprocessing
842
+
843
+ executor = multiprocessing .Pool (jobs )
844
+ attempt_iterator = executor .imap (
845
+ functools .partial (
846
+ sort_imports ,
847
+ config = config ,
848
+ check = check ,
849
+ ask_to_apply = ask_to_apply ,
850
+ write_to_stdout = write_to_stdout ,
851
+ ),
852
+ file_names ,
875
853
)
876
- for file_name in file_names
877
- )
854
+ else :
855
+ # https://github.com/python/typeshed/pull/2814
856
+ attempt_iterator = (
857
+ sort_imports ( # type: ignore
858
+ file_name ,
859
+ config = config ,
860
+ check = check ,
861
+ ask_to_apply = ask_to_apply ,
862
+ show_diff = show_diff ,
863
+ write_to_stdout = write_to_stdout ,
864
+ )
865
+ for file_name in file_names
866
+ )
867
+
868
+ for sort_attempt in attempt_iterator :
869
+ if not sort_attempt :
870
+ continue # pragma: no cover - shouldn't happen, satisfies type constraint
871
+ incorrectly_sorted = sort_attempt .incorrectly_sorted
872
+ if arguments .get ("check" , False ) and incorrectly_sorted :
873
+ wrong_sorted_files = True
874
+ if sort_attempt .skipped :
875
+ num_skipped += (
876
+ 1 # pragma: no cover - shouldn't happen, due to skip in iter_source_code
877
+ )
878
878
879
- for sort_attempt in attempt_iterator :
880
- if not sort_attempt :
881
- continue # pragma: no cover - shouldn't happen, satisfies type constraint
882
- incorrectly_sorted = sort_attempt .incorrectly_sorted
883
- if arguments .get ("check" , False ) and incorrectly_sorted :
884
- wrong_sorted_files = True
885
- if sort_attempt .skipped :
886
- num_skipped += 1 # pragma: no cover - shouldn't happen, due to skip in iter_source_code
879
+ num_skipped += len (skipped )
880
+ if num_skipped and not arguments .get ("quiet" , False ):
881
+ if config .verbose :
882
+ for was_skipped in skipped :
883
+ warn (
884
+ f"{ was_skipped } was skipped as it's listed in 'skip' setting"
885
+ " or matches a glob in 'skip_glob' setting"
886
+ )
887
+ print (f"Skipped { num_skipped } files" )
888
+
889
+ if not config .quiet and (remapped_deprecated_args or deprecated_flags ): # pragma: no cover
890
+ if remapped_deprecated_args :
891
+ warn (
892
+ "W0502: The following deprecated single dash CLI flags were used and translated: "
893
+ f"{ ', ' .join (remapped_deprecated_args )} !"
894
+ )
895
+ if deprecated_flags :
896
+ warn (
897
+ "W0501: The following deprecated CLI flags were used and ignored: "
898
+ f"{ ', ' .join (deprecated_flags )} !"
899
+ )
900
+ warn (
901
+ "W0500: Please see the 5.0.0 Upgrade guide: "
902
+ "https://timothycrosley.github.io/isort/docs/upgrade_guides/5.0.0/"
903
+ )
887
904
888
905
if wrong_sorted_files :
889
906
sys .exit (1 )
890
907
891
- num_skipped += len (skipped )
892
- if num_skipped and not arguments .get ("quiet" , False ):
893
- if config .verbose :
894
- for was_skipped in skipped :
895
- warn (
896
- f"{ was_skipped } was skipped as it's listed in 'skip' setting"
897
- " or matches a glob in 'skip_glob' setting"
898
- )
899
- print (f"Skipped { num_skipped } files" )
900
-
901
908
902
909
if __name__ == "__main__" :
903
910
main ()
0 commit comments