@@ -61,18 +61,18 @@ def iter_source_code(paths, config, skipped):
6161 """Iterate over all Python source files defined in paths."""
6262 for path in paths :
6363 if os .path .isdir (path ):
64- if should_skip (path , config ):
64+ if should_skip (path , config , os . getcwd () ):
6565 skipped .append (path )
6666 continue
6767
6868 for dirpath , dirnames , filenames in os .walk (path , topdown = True ):
6969 for dirname in list (dirnames ):
70- if should_skip (dirname , config ):
70+ if should_skip (dirname , config , dirpath ):
7171 skipped .append (dirname )
7272 dirnames .remove (dirname )
7373 for filename in filenames :
7474 if filename .endswith ('.py' ):
75- if should_skip (filename , config ):
75+ if should_skip (filename , config , dirpath ):
7676 skipped .append (filename )
7777 else :
7878 yield os .path .join (dirpath , filename )
@@ -162,6 +162,8 @@ def create_parser():
162162 help = 'Force sortImports to recognize a module as being part of a third party library.' )
163163 parser .add_argument ('-p' , '--project' , dest = 'known_first_party' , action = 'append' ,
164164 help = 'Force sortImports to recognize a module as being part of the current python project.' )
165+ parser .add_argument ('--virtual-env' , dest = 'virtual_env' ,
166+ help = 'Virtual environment to use for determining whether a package is third-party' )
165167 parser .add_argument ('-m' , '--multi_line' , dest = 'multi_line_output' , type = int , choices = [0 , 1 , 2 , 3 , 4 , 5 ],
166168 help = 'Multi line output (0-grid, 1-vertical, 2-hanging, 3-vert-hanging, 4-vert-grid, '
167169 '5-vert-grid-grouped).' )
@@ -181,10 +183,14 @@ def create_parser():
181183 parser .add_argument ('-c' , '--check-only' , action = 'store_true' , default = False , dest = "check" ,
182184 help = 'Checks the file for unsorted / unformatted imports and prints them to the '
183185 'command line without modifying the file.' )
186+ parser .add_argument ('-ws' , '--enforce-white-space' , action = 'store_true' , default = False , dest = "enforce_white_space" ,
187+ help = 'Tells isort to enforce white space difference when --check-only is being used.' )
184188 parser .add_argument ('-sl' , '--force-single-line-imports' , dest = 'force_single_line' , action = 'store_true' ,
185189 help = 'Forces all from imports to appear on their own line' )
186190 parser .add_argument ('--force_single_line_imports' , dest = 'force_single_line' , action = 'store_true' ,
187191 help = argparse .SUPPRESS )
192+ parser .add_argument ('-ds' , '--no-sections' , help = 'Put all imports into the same section bucket' , dest = 'no_sections' ,
193+ action = 'store_true' )
188194 parser .add_argument ('-sd' , '--section-default' , dest = 'default_section' ,
189195 help = 'Sets the default section for imports (by default FIRSTPARTY) options: ' +
190196 str (DEFAULT_SECTIONS ))
@@ -197,6 +203,8 @@ def create_parser():
197203 help = 'Recursively look for Python files of which to sort imports' )
198204 parser .add_argument ('-ot' , '--order-by-type' , dest = 'order_by_type' ,
199205 action = 'store_true' , help = 'Order imports by type in addition to alphabetically' )
206+ parser .add_argument ('-dt' , '--dont-order-by-type' , dest = 'dont_order_by_type' ,
207+ action = 'store_true' , help = 'Only order imports alphabetically, do not attempt type ordering' )
200208 parser .add_argument ('-ac' , '--atomic' , dest = 'atomic' , action = 'store_true' ,
201209 help = "Ensures the output doesn't save if the resulting file contains syntax errors." )
202210 parser .add_argument ('-cs' , '--combine-star' , dest = 'combine_star' , action = 'store_true' ,
@@ -218,13 +226,18 @@ def create_parser():
218226 help = "Specifies how long lines that are wrapped should be, if not set line_length is used." )
219227 parser .add_argument ('-fgw' , '--force-grid-wrap' , action = 'store_true' , dest = "force_grid_wrap" ,
220228 help = 'Force from imports to be grid wrapped regardless of line length' )
229+ parser .add_argument ('-fass' , '--force-alphabetical-sort-within-sections' , action = 'store_true' ,
230+ dest = "force_alphabetical_sort" , help = 'Force all imports to be sorted alphabetically within a '
231+ 'section' )
221232 parser .add_argument ('-fas' , '--force-alphabetical-sort' , action = 'store_true' , dest = "force_alphabetical_sort" ,
222233 help = 'Force all imports to be sorted as a single section' )
223234 parser .add_argument ('-fss' , '--force-sort-within-sections' , action = 'store_true' , dest = "force_sort_within_sections" ,
224- help = 'Force imports to be sorted by module, independant of import_type' )
225-
235+ help = 'Force imports to be sorted by module, independent of import_type' )
236+ parser . add_argument ( '-lbt' , '--lines-between-types' , dest = 'lines_between_types' , type = int )
226237
227238 arguments = dict ((key , value ) for (key , value ) in itemsview (vars (parser .parse_args ())) if value )
239+ if 'dont_order_by_type' in arguments :
240+ arguments ['order_by_type' ] = False
228241 return arguments
229242
230243
@@ -234,6 +247,10 @@ def main():
234247 print (INTRO )
235248 return
236249
250+ if 'settings_path' in arguments :
251+ sp = arguments ['settings_path' ]
252+ arguments ['settings_path' ] = os .path .abspath (sp ) if os .path .isdir (sp ) else os .path .dirname (os .path .abspath (sp ))
253+
237254 file_names = arguments .pop ('files' , [])
238255 if file_names == ['-' ]:
239256 SortImports (file_contents = sys .stdin .read (), write_to_stdout = True , ** arguments )
0 commit comments