Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def iter_source_code(paths, config, skipped):
"""Iterate over all Python source files defined in paths."""
if 'not_skip' in config:
config['skip'] = list(set(config['skip']).difference(config['not_skip']))
for path in paths:
if os.path.isdir(path):
for dirpath, dirnames, filenames in os.walk(path, topdown=True, followlinks=True):
for dirname in list(dirnames):
if should_skip(dirname, config, dirpath):
skipped.append(dirname)
dirnames.remove(dirname)
for filename in filenames:
filepath = os.path.join(dirpath, filename)
if is_python_file(filepath):
relative_file = os.path.relpath(filepath, path)
if should_skip(relative_file, config, path):
skipped.append(filename)
else:
yield filepath
else:
yield path
def iter_source_code(paths, config, skipped):
"""Iterate over all Python source files defined in paths."""
for path in paths:
if os.path.isdir(path):
if should_skip(path, config, os.getcwd()):
skipped.append(path)
continue
for dirpath, dirnames, filenames in os.walk(path, topdown=True):
for dirname in list(dirnames):
if should_skip(dirname, config, dirpath):
skipped.append(dirname)
dirnames.remove(dirname)
for filename in filenames:
if filename.endswith('.py'):
if should_skip(filename, config, dirpath):
skipped.append(filename)
else:
yield os.path.join(dirpath, filename)
else:
yield path
else:
if not file_names:
file_names = ['.']
arguments['recursive'] = True
if not arguments.get('apply', False):
arguments['ask_to_apply'] = True
config = from_path(arguments.get('settings_path', '') or os.path.abspath(file_names[0]) or os.getcwd()).copy()
config.update(arguments)
wrong_sorted_files = False
skipped = []
if config.get('filter_files'):
filtered_files = []
for file_name in file_names:
if should_skip(file_name, config):
skipped.append(file_name)
else:
filtered_files.append(file_name)
file_names = filtered_files
if arguments.get('recursive', False):
file_names = iter_source_code(file_names, config, skipped)
num_skipped = 0
if config['verbose'] or config.get('show_logo', False):
print(INTRO)
jobs = arguments.get('jobs')
if jobs:
import multiprocessing
executor = multiprocessing.Pool(jobs)
attempt_iterator = executor.imap(functools.partial(sort_imports, **arguments), file_names)
def iter_source_code(paths, config, skipped):
"""Iterate over all Python source files defined in paths."""
for path in paths:
if os.path.isdir(path):
if should_skip(path, config, os.getcwd()):
skipped.append(path)
continue
for dirpath, dirnames, filenames in os.walk(path, topdown=True):
for dirname in list(dirnames):
if should_skip(dirname, config, dirpath):
skipped.append(dirname)
dirnames.remove(dirname)
for filename in filenames:
if filename.endswith('.py'):
if should_skip(filename, config, dirpath):
skipped.append(filename)
else:
yield os.path.join(dirpath, filename)
else:
yield path
"""Iterate over all Python source files defined in paths."""
if 'not_skip' in config:
config['skip'] = list(set(config['skip']).difference(config['not_skip']))
for path in paths:
if os.path.isdir(path):
for dirpath, dirnames, filenames in os.walk(path, topdown=True, followlinks=True):
for dirname in list(dirnames):
if should_skip(dirname, config, dirpath):
skipped.append(dirname)
dirnames.remove(dirname)
for filename in filenames:
filepath = os.path.join(dirpath, filename)
if is_python_file(filepath):
relative_file = os.path.relpath(filepath, path)
if should_skip(relative_file, config, path):
skipped.append(filename)
else:
yield filepath
else:
yield path
def iter_source_code(paths, config, skipped):
"""Iterate over all Python source files defined in paths."""
for path in paths:
if os.path.isdir(path):
if should_skip(path, config, os.getcwd()):
skipped.append(path)
continue
for dirpath, dirnames, filenames in os.walk(path, topdown=True):
for dirname in list(dirnames):
if should_skip(dirname, config, dirpath):
skipped.append(dirname)
dirnames.remove(dirname)
for filename in filenames:
if filename.endswith('.py'):
if should_skip(filename, config, dirpath):
skipped.append(filename)
else:
yield os.path.join(dirpath, filename)
else:
yield path