Plugins/CheckerPlugins/CodeStyleChecker/pycodestyle.py

changeset 5288
ff831e3e383e
parent 5147
d39dd5cee0c8
child 5290
174dae2b91c3
diff -r 971f24c89e6b -r ff831e3e383e Plugins/CheckerPlugins/CodeStyleChecker/pycodestyle.py
--- a/Plugins/CheckerPlugins/CodeStyleChecker/pycodestyle.py	Thu Nov 03 22:30:07 2016 +0100
+++ b/Plugins/CheckerPlugins/CodeStyleChecker/pycodestyle.py	Fri Nov 04 22:05:33 2016 +0100
@@ -2,6 +2,7 @@
 # -*- coding: utf-8 -*-
 
 # pycodestyle.py - Check Python source code formatting, according to PEP 8
+#
 # Copyright (C) 2006-2009 Johann C. Rocholl <johann@rocholl.net>
 # Copyright (C) 2009-2014 Florent Xicluna <florent.xicluna@gmail.com>
 # Copyright (C) 2014-2016 Ian Lee <ianlee1521@gmail.com>
@@ -67,16 +68,18 @@
 import sys
 import time
 import tokenize
-##import ast
+import warnings
+
 from fnmatch import fnmatch
 from optparse import OptionParser
+
 try:
     from configparser import RawConfigParser
     from io import TextIOWrapper
 except ImportError:
     from ConfigParser import RawConfigParser            # __IGNORE_WARNING__
 
-__version__ = '2.1.0.dev0'
+__version__ = '2.1.0'
 
 DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__,.tox'
 DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704,W503'
@@ -281,7 +284,7 @@
             yield 0, "E304 blank lines found after function decorator"
     elif blank_lines > 2 or (indent_level and blank_lines == 2):
         yield 0, "E303 too many blank lines (%d)", blank_lines
-    elif logical_line.startswith(('def ', 'async def ', 'class ', '@')):
+    elif logical_line.startswith(('def ', 'async def', 'class ', '@')):
         if indent_level:
             if not (blank_before or previous_indent_level < indent_level or
                     DOCSTRING_REGEX.match(previous_logical)):
@@ -988,7 +991,6 @@
     E702: do_one(); do_two(); do_three()
     E703: do_four();  # useless semicolon
     E704: def f(x): return 2*x
-    E705: async def f(x): return 2*x
     E731: f = lambda x: 2*x
     """
     line = logical_line
@@ -1010,8 +1012,6 @@
                 break
             if line.startswith('def '):
                 yield 0, "E704 multiple statements on one line (def)"
-            elif line.startswith('async def '):
-                yield 0, "E705 multiple statements on one line (async def)"
             else:
                 yield found, "E701 multiple statements on one line (colon)"
         prev_found = found
@@ -1573,7 +1573,7 @@
         return check(*arguments)
 
     def init_checker_state(self, name, argument_names):
-        """ Prepare custom state for the specific checker plugin."""
+        """Prepare custom state for the specific checker plugin."""
         if 'checker_state' in argument_names:
             self.checker_state = self._checker_states.setdefault(name, {})
 
@@ -1885,6 +1885,7 @@
 
 class FileReport(BaseReport):
     """Collect the results of the checks and print only the filenames."""
+
     print_filename = True
 
 
@@ -2166,7 +2167,7 @@
 
 
 def read_config(options, args, arglist, parser):
-    """Read and parse configurations
+    """Read and parse configurations.
 
     If a config file is specified on the command line with the "--config"
     option, then only it is used for configuration.
@@ -2200,8 +2201,14 @@
             print('cli configuration: %s' % cli_conf)
         config.read(cli_conf)
 
-    pep8_section = parser.prog
-    if config.has_section(pep8_section):
+    pycodestyle_section = None
+    if config.has_section(parser.prog):
+        pycodestyle_section = parser.prog
+    elif config.has_section('pep8'):
+        pycodestyle_section = 'pep8'  # Deprecated
+        warnings.warn('[pep8] section is deprecated. Use [pycodestyle].')
+
+    if pycodestyle_section:
         option_list = dict([(o.dest, o.type or o.action)
                             for o in parser.option_list])
 
@@ -2209,20 +2216,21 @@
         (new_options, __) = parser.parse_args([])
 
         # Second, parse the configuration
-        for opt in config.options(pep8_section):
+        for opt in config.options(pycodestyle_section):
             if opt.replace('_', '-') not in parser.config_options:
                 print("  unknown option '%s' ignored" % opt)
                 continue
             if options.verbose > 1:
-                print("  %s = %s" % (opt, config.get(pep8_section, opt)))
+                print("  %s = %s" % (opt,
+                                     config.get(pycodestyle_section, opt)))
             normalized_opt = opt.replace('-', '_')
             opt_type = option_list[normalized_opt]
             if opt_type in ('int', 'count'):
-                value = config.getint(pep8_section, opt)
+                value = config.getint(pycodestyle_section, opt)
             elif opt_type in ('store_true', 'store_false'):
-                value = config.getboolean(pep8_section, opt)
+                value = config.getboolean(pycodestyle_section, opt)
             else:
-                value = config.get(pep8_section, opt)
+                value = config.get(pycodestyle_section, opt)
                 if normalized_opt == 'exclude':
                     value = normalize_paths(value, local_dir)
             setattr(new_options, normalized_opt, value)
@@ -2333,7 +2341,8 @@
             sys.stderr.write(str(report.total_errors) + '\n')
         sys.exit(1)
 
+
 if __name__ == '__main__':
     _main()
 #
-# eflag: noqa = M702
+# eflag: noqa = D2, M601, M701, M702, M801

eric ide

mercurial