1414 StatementLinesCollector ,
1515 decorate_diff_with_color ,
1616 GlobalFormattingConfig ,
17- ModelWriter
17+ ModelWriter ,
1818)
1919
2020
2121class Robotidy :
22- def __init__ (self ,
23- transformers : List [Tuple [str , List ]],
24- transformers_config : List [Tuple [str , List ]],
25- src : Tuple [str , ...],
26- exclude : Pattern ,
27- extend_exclude : Pattern ,
28- overwrite : bool ,
29- show_diff : bool ,
30- formatting_config : GlobalFormattingConfig ,
31- verbose : bool ,
32- check : bool ,
33- output : Optional [Path ],
34- force_order : bool
35- ):
22+ def __init__ (
23+ self ,
24+ transformers : List [Tuple [str , List ]],
25+ transformers_config : List [Tuple [str , List ]],
26+ src : Tuple [str , ...],
27+ exclude : Pattern ,
28+ extend_exclude : Pattern ,
29+ overwrite : bool ,
30+ show_diff : bool ,
31+ formatting_config : GlobalFormattingConfig ,
32+ verbose : bool ,
33+ check : bool ,
34+ output : Optional [Path ],
35+ force_order : bool ,
36+ ):
3637 self .sources = get_paths (src , exclude , extend_exclude )
3738 self .overwrite = overwrite
3839 self .show_diff = show_diff
@@ -44,20 +45,20 @@ def __init__(self,
4445 self .transformers = load_transformers (transformers , transformers_config , force_order = force_order )
4546 for transformer in self .transformers :
4647 # inject global settings TODO: handle it better
47- setattr (transformer , ' formatting_config' , self .formatting_config )
48+ setattr (transformer , " formatting_config" , self .formatting_config )
4849
4950 def transform_files (self ):
5051 changed_files = 0
5152 for source in self .sources :
5253 try :
5354 stdin = False
54- if str (source ) == '-' :
55+ if str (source ) == "-" :
5556 stdin = True
5657 if self .verbose :
57- click .echo (' Loading file from stdin' )
58+ click .echo (" Loading file from stdin" )
5859 source = self .load_from_stdin ()
5960 elif self .verbose :
60- click .echo (f' Transforming { source } file' )
61+ click .echo (f" Transforming { source } file" )
6162 model = get_model (source )
6263 diff , old_model , new_model = self .transform (model )
6364 if diff :
@@ -97,16 +98,21 @@ def save_model(self, model):
9798 output = self .output or model .source
9899 ModelWriter (output = output , newline = self .formatting_config .line_sep ).write (model )
99100
100- def output_diff (self , path : str , old_model : StatementLinesCollector , new_model : StatementLinesCollector ):
101+ def output_diff (
102+ self ,
103+ path : str ,
104+ old_model : StatementLinesCollector ,
105+ new_model : StatementLinesCollector ,
106+ ):
101107 if not self .show_diff :
102108 return
103- old = [l + ' \n ' for l in old_model .text .splitlines ()]
104- new = [l + ' \n ' for l in new_model .text .splitlines ()]
105- lines = list (unified_diff (old , new , fromfile = f' { path } \t before' , tofile = f' { path } \t after' ))
109+ old = [l + " \n " for l in old_model .text .splitlines ()]
110+ new = [l + " \n " for l in new_model .text .splitlines ()]
111+ lines = list (unified_diff (old , new , fromfile = f" { path } \t before" , tofile = f" { path } \t after" ))
106112 if not lines :
107113 return
108114 colorized_output = decorate_diff_with_color (lines )
109- click .echo (colorized_output .encode (' ascii' , ' ignore' ).decode (' ascii' ), color = True )
115+ click .echo (colorized_output .encode (" ascii" , " ignore" ).decode (" ascii" ), color = True )
110116
111117 @staticmethod
112118 def convert_configure (configure : List [Tuple [str , List ]]) -> Dict [str , List ]:
0 commit comments