Commits

Lorenzo Gil Sánchez committed d442387

Make it compatible with newer versions of pep8

Comments (0)

Files changed (1)

 try:
     import pep8
     HAS_PEP8 = True
+    PEP8_VERSION = tuple([int(x) for x in pep8.__version__.split('.')])
 except ImportError:
     HAS_PEP8 = False
 
                 os.makedirs(parentdir)
             open(filename, 'w').write(data)
 
-        # monkey patch sys.argv options so we can call pep8
-        old_args = sys.argv
-        sys.argv = ['pep8'] + files_to_check.keys() + extra_args
-        options, args = pep8.process_options()
-        sys.argv = old_args
-        for path in args:
-            pep8.input_file(path)
 
-        return pep8.get_count()
+        if PEP8_VERSION > (1, 2):
+            args = files_to_check.keys() + extra_args
+            options, paths = pep8.process_options(args)
+            options_dict = options.__dict__.copy()
+            options_dict['paths'] = paths
+            style_guide = pep8.StyleGuide(**options_dict)
+            report = style_guide.check_files()
+            return report.total_errors
+
+        else:
+            # monkey patch sys.argv options so we can call pep8
+            old_args = sys.argv
+            sys.argv = ['pep8'] + files_to_check.keys() + extra_args
+            options, args = pep8.process_options()
+            sys.argv = old_args
+            for path in args:
+                pep8.input_file(path)
+
+            return pep8.get_count()
 
     return check_pep8