Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return pattern
exclude = [prepare_pattern(pattern) for pattern in (exclude or [])]
def exclude_file(name):
return any(fnmatch(name, pattern) for pattern in exclude)
for module in utils.get_modules(paths):
if exclude_file(module):
self._log('Excluded:', module)
continue
self._log('Scanning:', module)
try:
module_string = utils.read_file(module)
except utils.VultureInputException as err: # noqa: F841
print(
'Error: Could not read file {module} - {err}\n'
'Try to change the encoding to UTF-8.'.format(**locals()),
file=sys.stderr)
self.found_dead_code_or_error = True
else:
self.scan(module_string, filename=module)
unique_imports = {item.name for item in self.defined_imports}
for import_name in unique_imports:
path = os.path.join('whitelists', import_name) + '_whitelist.py'
if exclude_file(path):
self._log('Excluded whitelist:', path)
else:
try:
module_data = pkgutil.get_data('vulture', path)
def scavenge(self, finder): # pylint: disable=arguments-differ
self._tidypy_issues = []
if self.config['options']['whitelist']:
self.scan(
'\n'.join(self.config['options']['whitelist']),
filename='VultureWhitelist',
)
for filepath in finder.files(self.config['filters']):
try:
source = finder.read_file(filepath)
except VultureInputException as exc:
self._tidypy_issues.append(ParseIssue(exc, filepath))
continue
except EnvironmentError as exc:
self._tidypy_issues.append(AccessIssue(exc, filepath))
continue
self.scan(source, filename=filepath)
def read_file(filename):
# Python >= 3.2
try:
# Use encoding detected by tokenize.detect_encoding().
with tokenize.open(filename) as f:
return f.read()
except (SyntaxError, UnicodeDecodeError) as err:
raise VultureInputException(err)
except AttributeError:
# tokenize.open was added in Python 3.2.
pass
# Python < 3.2
try:
with codecs.open(filename, encoding=ENCODING) as f:
return f.read()
except UnicodeDecodeError as err:
raise VultureInputException(err)