def run(self): reporter = ProspectorReporter(ignore=self.ignore_codes) for filepath in iter_source_code(self._paths): if any([ip.search(filepath) for ip in self._ignores]): continue check_path(filepath, reporter) return reporter.get_messages()
def main(): warnings = 0 parser = argparse.ArgumentParser(description='Quickly check the correctness of your Python scripts.') parser.add_argument('files', nargs='+', help='One or more Python source files that need their imports sorted.') parser.add_argument('-r', '--recursive', dest='recursive', action='store_true', help='Recursively look for Python files to check') parser.add_argument('-s', '--skip', help='Files that frosted should skip over.', dest='skip', action='append') parser.add_argument('-i', '--ignore', help='Specify error codes that should be ignored.', dest='ignore_frosted_errors', action='append') parser.add_argument('-vb', '--verbose', help='Explicitly separate each section of data when displaying errors.', dest='verbose', action='store_true') parser.add_argument('-v', '--version', action='version', version='frosted {0}'.format(__version__)) arguments = dict((key, value) for (key, value) in itemsview(vars(parser.parse_args())) if value) file_names = arguments.pop('files', []) if file_names == ['-']: check(sys.stdin.read(), '<stdin>', **arguments) elif arguments.get('recursive'): warnings = check_recursive(file_names, **arguments) else: warnings = 0 for file_path in file_names: try: warnings += check_path(file_path, directly_being_checked=len(file_names), **arguments) except IOError as e: print("WARNING: Unable to parse file {0} due to {1}".format(file_name, e)) raise SystemExit(warnings > 0)
def main(): warnings = 0 parser = argparse.ArgumentParser(description='Quickly check the correctness of your Python scripts.') parser.add_argument('files', nargs='+', help='One file or a list of Python source files to check the syntax of.') parser.add_argument('-r', '--recursive', dest='recursive', action='store_true', help='Recursively look for Python files to check') parser.add_argument('-s', '--skip', help='Files that frosted should skip over.', dest='skip', action='append') parser.add_argument('-d', '--with-doctests', help='Run frosted against doctests', dest='run_doctests', action='store_true') parser.add_argument('-i', '--ignore', help='Specify error codes that should be ignored.', dest='ignore_frosted_errors', action='append') parser.add_argument('-di', '--dont-ignore', help='Specify error codes that should not be ignored in any case.', dest='not_ignore_frosted_errors', action='append') parser.add_argument('-vb', '--verbose', help='Explicitly separate each section of data when displaying errors.', dest='verbose', action='store_true') parser.add_argument('-v', '--version', action='version', version='frosted {0}'.format(__version__)) arguments = dict((key, value) for (key, value) in itemsview(vars(parser.parse_args())) if value) file_names = arguments.pop('files', []) if file_names == ['-']: check(sys.stdin.read(), '<stdin>', **arguments) elif arguments.get('recursive'): warnings = check_recursive(file_names, **arguments) else: warnings = 0 for file_path in file_names: try: warnings += check_path(file_path, directly_being_checked=len(file_names), **arguments) except IOError as e: print("WARNING: Unable to parse file {0} due to {1}".format(file_name, e)) raise SystemExit(warnings > 0)
def assert_contains_output(path, flakeList): """Assert that provided causes at minimal the errors provided in the error list.""" out = StringIO() count = check_path(path, Reporter(out, out), verbose=True) out_string = out.getvalue() assert len(flakeList) >= count for flake in flakeList: assert flake in out_string
def assert_contains_errors(path, errorList): """Assert that provided causes at minimal the errors provided in the error list.""" error = StringIO() count = check_path(path, Reporter(sys.stdout, error)) error_string = error.getvalue() assert len(errorList) >= count for error in errorList: assert error in error_string
def run(self): reporter = ProspectorReporter(ignore=self.ignore_codes) for filepath in self._files.iter_module_paths(): # Frosted cannot handle non-utf-8 encoded files at the moment - # see https://github.com/timothycrosley/frosted/issues/53 # Therefore (since pyflakes overlaps heavily and does not have the same # problem) we will simply suppress that error. If you do get it working # correctly, you only end up with a "CannotDecodeFile" error anyway which # is not useful to the user of prospector, nor is it actually a problem # of the file but rather of frosted. try: check_path(filepath, reporter) except UnicodeDecodeError: pass return reporter.get_messages()
def get_errors(path): """ Get any warnings or errors reported by frosted for the file at path """ log = [] reporter = LoggingReporter(log) count = check_path(path, reporter) return count, log
def run(self, found_files): reporter = ProspectorReporter(ignore=self.ignore_codes) for filepath in found_files.iter_module_paths(): # Frosted cannot handle non-utf-8 encoded files at the moment - # see https://github.com/timothycrosley/frosted/issues/53 # Therefore (since pyflakes overlaps heavily and does not have the same # problem) we will simply suppress that error. If you do get it working # correctly, you only end up with a "CannotDecodeFile" error anyway which # is not useful to the user of prospector, nor is it actually a problem # of the file but rather of frosted. try: check_path(filepath, reporter) except UnicodeDecodeError: # pylint:disable=pointless-except pass return reporter.get_messages()
def assert_contains_errors(path, errorList): """ Assert that provided causes at minimal the errors provided in the error list """ error = StringIO() (outer, sys.stderr) = (sys.stderr, error) try: count = check_path(path) finally: sys.stderr = outer error_string = error.getvalue() assert len(errorList) >= count for error in errorList: assert error in error_string