How to use the vulture.utils.get_modules function in vulture

To help you get started, we’ve selected a few vulture examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jendrikseipp / vulture / vulture / core.py View on Github external
def scavenge(self, paths, exclude=None):
        def prepare_pattern(pattern):
            if not any(char in pattern for char in ['*', '?', '[']):
                pattern = '*{pattern}*'.format(**locals())
            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)