[Python-modules-commits] [python-flake8] 01/05: Import python-flake8_3.0.4+dfsg1.orig.tar.gz

Ondřej Nový onovy at moszumanska.debian.org
Wed Aug 10 15:45:38 UTC 2016


This is an automated email from the git hooks/post-receive script.

onovy pushed a commit to branch master
in repository python-flake8.

commit a7766c12080ab8db65aa9a24ff3b249035cf132d
Author: Ondřej Nový <onovy at debian.org>
Date:   Wed Aug 10 17:39:08 2016 +0200

    Import python-flake8_3.0.4+dfsg1.orig.tar.gz
---
 PKG-INFO                                           |  2 +-
 .../plugin-development/plugin-parameters.rst       |  6 +++
 docs/source/release-notes/3.0.4.rst                | 20 +++++++++
 docs/source/release-notes/index.rst                |  1 +
 docs/source/user/error-codes.rst                   | 49 ++++++++++++++++++++++
 docs/source/user/index.rst                         |  1 +
 src/flake8.egg-info/PKG-INFO                       |  2 +-
 src/flake8.egg-info/SOURCES.txt                    |  2 +
 src/flake8/__init__.py                             |  2 +-
 src/flake8/checker.py                              | 48 +++++++++++----------
 src/flake8/exceptions.py                           | 21 ++++++----
 src/flake8/plugins/manager.py                      | 24 +++++++++++
 src/flake8/plugins/pyflakes.py                     |  3 ++
 src/flake8/processor.py                            | 14 ++-----
 tests/integration/test_checker.py                  |  6 ++-
 tests/unit/test_checker_manager.py                 |  8 +++-
 16 files changed, 163 insertions(+), 46 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index b9f8212..578a535 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: flake8
-Version: 3.0.3
+Version: 3.0.4
 Summary: the modular source code checker: pep8, pyflakes and co
 Home-page: https://gitlab.com/pycqa/flake8
 Author: Ian Cordasco
diff --git a/docs/source/plugin-development/plugin-parameters.rst b/docs/source/plugin-development/plugin-parameters.rst
index a0e0177..fd644bc 100644
--- a/docs/source/plugin-development/plugin-parameters.rst
+++ b/docs/source/plugin-development/plugin-parameters.rst
@@ -54,6 +54,12 @@ which is not supplied as a parameter of
 :class:`~flake8.processor.FileProcessor`, which will be a parsed abstract
 syntax tree. It is used by plugins like PyFlakes and McCabe.
 
+When the plugin is run depends on the first parameter, not counting ``self``.
+It can be either ``physical_line``, ``logical_line`` or ``tree``. If the
+parameter is ``tree``, it is run once per file, otherwise once per physical
+line or logical line respectively. If the plugin is using neither of them it
+won't be run at all.
+
 
 Registering Options
 ===================
diff --git a/docs/source/release-notes/3.0.4.rst b/docs/source/release-notes/3.0.4.rst
new file mode 100644
index 0000000..bdea279
--- /dev/null
+++ b/docs/source/release-notes/3.0.4.rst
@@ -0,0 +1,20 @@
+3.0.4 -- 2016-08-08
+-------------------
+
+- Side-step a Pickling Error when using Flake8 with multiprocessing on Unix
+  systems. (See also `GitLab#164`_)
+
+- Fix an Attribute Error raised when dealing with Invalid Syntax. (See also
+  `GitLab#203`_)
+
+- Fix an unhandled Syntax Error when tokenizing files. (See also
+  `GitLab#205`_)
+
+
+.. links
+.. _GitLab#164:
+    https://gitlab.com/pycqa/flake8/issues/164
+.. _GitLab#203:
+    https://gitlab.com/pycqa/flake8/issues/203
+.. _GitLab#205:
+    https://gitlab.com/pycqa/flake8/issues/205
diff --git a/docs/source/release-notes/index.rst b/docs/source/release-notes/index.rst
index 81cd1ab..07b9cd6 100644
--- a/docs/source/release-notes/index.rst
+++ b/docs/source/release-notes/index.rst
@@ -6,6 +6,7 @@ All of the release notes that have been recorded for Flake8 are organized here
 with the newest releases first.
 
 .. toctree::
+    3.0.4
     3.0.3
     3.0.2
     3.0.1
diff --git a/docs/source/user/error-codes.rst b/docs/source/user/error-codes.rst
new file mode 100644
index 0000000..9a2c26b
--- /dev/null
+++ b/docs/source/user/error-codes.rst
@@ -0,0 +1,49 @@
+=========================
+ Error / Violation Codes
+=========================
+
+Flake8 and its plugins assign a code to each message that we refer to as a
+:term:`error code` (or :term:`violation`). Most plugins will list their error
+codes in their documentation or README.
+
+Flake8 installs ``pycodestyle``, ``pyflakes``, and ``mccabe`` by default and
+generates its own :term:`error code`\ s for ``pyflakes``:
+
++------+---------------------------------------------------------------------+
+| Code | Example Message                                                     |
++======+=====================================================================+
+| F401 | ``module`` imported but unused                                      |
++------+---------------------------------------------------------------------+
+| F402 | import ``module`` from line ``N`` shadowed by loop variable         |
++------+---------------------------------------------------------------------+
+| F403 | 'from ``module`` import \*' used; unable to detect undefined names  |
++------+---------------------------------------------------------------------+
+| F404 | future import(s) ``name`` after other statements                    |
++------+---------------------------------------------------------------------+
+| F405 | ``name`` may be undefined, or defined from star imports: ``module`` |
++------+---------------------------------------------------------------------+
++------+---------------------------------------------------------------------+
+| F811 | redefinition of unused ``name`` from line ``N``                     |
++------+---------------------------------------------------------------------+
+| F812 | list comprehension redefines ``name`` from line ``N``               |
++------+---------------------------------------------------------------------+
+| F821 | undefined name ``name``                                             |
++------+---------------------------------------------------------------------+
+| F822 | undefined name ``name`` in __all__                                  |
++------+---------------------------------------------------------------------+
+| F823 | local variable ``name`` ... referenced before assignment            |
++------+---------------------------------------------------------------------+
+| F831 | duplicate argument ``name`` in function definition                  |
++------+---------------------------------------------------------------------+
+| F841 | local variable ``name`` is assigned to but never used               |
++------+---------------------------------------------------------------------+
+
+``mccabe`` only ever reports one :term:`violation` - ``C901`` based on the
+complexity value provided by the user.
+
+Users should also reference `pycodestyle's list of error codes`_.
+
+
+.. links
+.. _pycodestyle's list of error codes:
+    https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
diff --git a/docs/source/user/index.rst b/docs/source/user/index.rst
index 0df911e..e008eb2 100644
--- a/docs/source/user/index.rst
+++ b/docs/source/user/index.rst
@@ -23,6 +23,7 @@ This guide will cover all of these and the nuances for using |Flake8|.
     invocation
     configuration
     options
+    error-codes
     ignoring-errors
     using-plugins
     python-api
diff --git a/src/flake8.egg-info/PKG-INFO b/src/flake8.egg-info/PKG-INFO
index b9f8212..578a535 100644
--- a/src/flake8.egg-info/PKG-INFO
+++ b/src/flake8.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: flake8
-Version: 3.0.3
+Version: 3.0.4
 Summary: the modular source code checker: pep8, pyflakes and co
 Home-page: https://gitlab.com/pycqa/flake8
 Author: Ian Cordasco
diff --git a/src/flake8.egg-info/SOURCES.txt b/src/flake8.egg-info/SOURCES.txt
index f6fed34..89d02ef 100644
--- a/src/flake8.egg-info/SOURCES.txt
+++ b/src/flake8.egg-info/SOURCES.txt
@@ -313,9 +313,11 @@ docs/source/release-notes/3.0.0.rst
 docs/source/release-notes/3.0.1.rst
 docs/source/release-notes/3.0.2.rst
 docs/source/release-notes/3.0.3.rst
+docs/source/release-notes/3.0.4.rst
 docs/source/release-notes/index.rst
 docs/source/user/.keep
 docs/source/user/configuration.rst
+docs/source/user/error-codes.rst
 docs/source/user/ignoring-errors.rst
 docs/source/user/index.rst
 docs/source/user/invocation.rst
diff --git a/src/flake8/__init__.py b/src/flake8/__init__.py
index 4f8df9d..b6dcae8 100644
--- a/src/flake8/__init__.py
+++ b/src/flake8/__init__.py
@@ -27,7 +27,7 @@ LOG.addHandler(NullHandler())
 # Clean up after LOG config
 del NullHandler
 
-__version__ = '3.0.3'
+__version__ = '3.0.4'
 __version_info__ = tuple(int(i) for i in __version__.split('.') if i.isdigit())
 
 
diff --git a/src/flake8/checker.py b/src/flake8/checker.py
index 57fd896..2dc3481 100644
--- a/src/flake8/checker.py
+++ b/src/flake8/checker.py
@@ -38,21 +38,6 @@ SERIAL_RETRY_ERRNOS = set([
 ])
 
 
-def _run_checks_from_queue(process_queue, results_queue, statistics_queue):
-    LOG.info('Running checks in parallel')
-    try:
-        for checker in iter(process_queue.get, 'DONE'):
-            LOG.info('Checking "%s"', checker.filename)
-            checker.run_checks(results_queue, statistics_queue)
-    except exceptions.PluginRequestedUnknownParameters as exc:
-        print(str(exc))
-    except Exception as exc:
-        LOG.error('Unhandled exception occurred')
-        raise
-    finally:
-        results_queue.put('DONE')
-
-
 class Manager(object):
     """Manage the parallelism and checker instances for each plugin and file.
 
@@ -284,8 +269,9 @@ class Manager(object):
             file_exists = os.path.exists(filename)
             return (file_exists and matches_filename_patterns) or is_stdin
 
+        checks = self.checks.to_dictionary()
         self.checkers = [
-            FileChecker(filename, self.checks, self.options)
+            FileChecker(filename, checks, self.options)
             for argument in paths
             for filename in utils.filenames_from(argument,
                                                  self.is_path_excluded)
@@ -405,7 +391,7 @@ class FileChecker(object):
         :param checks:
             The plugins registered to check the file.
         :type checks:
-            flake8.plugins.manager.Checkers
+            dict
         :param options:
             Parsed option values from config and command-line.
         :type options:
@@ -458,14 +444,17 @@ class FileChecker(object):
         """Run the check in a single plugin."""
         LOG.debug('Running %r with %r', plugin, arguments)
         try:
-            self.processor.keyword_arguments_for(plugin.parameters, arguments)
+            self.processor.keyword_arguments_for(
+                plugin['parameters'],
+                arguments,
+            )
         except AttributeError as ae:
             LOG.error('Plugin requested unknown parameters.')
             raise exceptions.PluginRequestedUnknownParameters(
                 plugin=plugin,
                 exception=ae,
             )
-        return plugin.execute(**arguments)
+        return plugin['plugin'](**arguments)
 
     def run_ast_checks(self):
         """Run all checks expecting an abstract syntax tree."""
@@ -484,7 +473,7 @@ class FileChecker(object):
                         (exc_type.__name__, exception.args[0]))
             return
 
-        for plugin in self.checks.ast_plugins:
+        for plugin in self.checks['ast_plugins']:
             checker = self.run_check(plugin, tree=ast)
             # If the plugin uses a class, call the run method of it, otherwise
             # the call should return something iterable itself
@@ -509,7 +498,7 @@ class FileChecker(object):
 
         LOG.debug('Logical line: "%s"', logical_line.rstrip())
 
-        for plugin in self.checks.logical_line_plugins:
+        for plugin in self.checks['logical_line_plugins']:
             self.processor.update_checker_state_for(plugin)
             results = self.run_check(plugin, logical_line=logical_line) or ()
             for offset, text in results:
@@ -526,7 +515,7 @@ class FileChecker(object):
 
     def run_physical_checks(self, physical_line, override_error_line=None):
         """Run all checks for a given physical line."""
-        for plugin in self.checks.physical_line_plugins:
+        for plugin in self.checks['physical_line_plugins']:
             self.processor.update_checker_state_for(plugin)
             result = self.run_check(plugin, physical_line=physical_line)
             if result is not None:
@@ -636,6 +625,21 @@ class FileChecker(object):
                                              override_error_line=token[4])
 
 
+def _run_checks_from_queue(process_queue, results_queue, statistics_queue):
+    LOG.info('Running checks in parallel')
+    try:
+        for checker in iter(process_queue.get, 'DONE'):
+            LOG.info('Checking "%s"', checker.filename)
+            checker.run_checks(results_queue, statistics_queue)
+    except exceptions.PluginRequestedUnknownParameters as exc:
+        print(str(exc))
+    except Exception as exc:
+        LOG.error('Unhandled exception occurred')
+        raise
+    finally:
+        results_queue.put('DONE')
+
+
 def find_offset(offset, mapping):
     """Find the offset tuple for a single offset."""
     if isinstance(offset, tuple):
diff --git a/src/flake8/exceptions.py b/src/flake8/exceptions.py
index 71738b2..cf8aae3 100644
--- a/src/flake8/exceptions.py
+++ b/src/flake8/exceptions.py
@@ -36,17 +36,20 @@ class InvalidSyntax(Flake8Exception):
 
     def __init__(self, *args, **kwargs):
         """Initialize our InvalidSyntax exception."""
-        self.original_exception = kwargs.pop('exception')
+        exception = kwargs.pop('exception', None)
+        self.original_exception = exception
+        self.error_message = '{0}: {1}'.format(
+            exception.__class__.__name__,
+            exception.args[0],
+        )
         self.error_code = 'E902'
         self.line_number = 1
         self.column_number = 0
-        try:
-            self.error_message = self.original_exception.message
-        except AttributeError:
-            # On Python 3, the IOError is an OSError which has a
-            # strerror attribute instead of a message attribute
-            self.error_message = self.original_exception.strerror
-        super(InvalidSyntax, self).__init__(*args, **kwargs)
+        super(InvalidSyntax, self).__init__(
+            self.error_message,
+            *args,
+            **kwargs
+        )
 
 
 class PluginRequestedUnknownParameters(Flake8Exception):
@@ -65,7 +68,7 @@ class PluginRequestedUnknownParameters(Flake8Exception):
 
     def __str__(self):
         """Format our exception message."""
-        return self.FORMAT % {'name': self.plugin.plugin_name,
+        return self.FORMAT % {'name': self.plugin['plugin_name'],
                               'exc': self.original_exception}
 
 
diff --git a/src/flake8/plugins/manager.py b/src/flake8/plugins/manager.py
index 28f38a6..a5f1c3b 100644
--- a/src/flake8/plugins/manager.py
+++ b/src/flake8/plugins/manager.py
@@ -49,6 +49,16 @@ class Plugin(object):
             self.name, self.entry_point
         )
 
+    def to_dictionary(self):
+        """Convert this plugin to a dictionary."""
+        return {
+            'name': self.name,
+            'parameters': self.parameters,
+            'parameter_names': self.parameter_names,
+            'plugin': self.plugin,
+            'plugin_name': self.plugin_name,
+        }
+
     def is_in_a_group(self):
         """Determine if this plugin is in a group.
 
@@ -433,6 +443,20 @@ class Checkers(PluginTypeManager):
             if argument_name == plugin.parameter_names[0]:
                 yield plugin
 
+    def to_dictionary(self):
+        """Return a dictionary of AST and line-based plugins."""
+        return {
+            'ast_plugins': [
+                plugin.to_dictionary() for plugin in self.ast_plugins
+            ],
+            'logical_line_plugins': [
+                plugin.to_dictionary() for plugin in self.logical_line_plugins
+            ],
+            'physical_line_plugins': [
+                plugin.to_dictionary() for plugin in self.physical_line_plugins
+            ],
+        }
+
     def register_options(self, optmanager):
         """Register all of the checkers' options to the OptionManager.
 
diff --git a/src/flake8/plugins/pyflakes.py b/src/flake8/plugins/pyflakes.py
index 158d5a2..542e5fa 100644
--- a/src/flake8/plugins/pyflakes.py
+++ b/src/flake8/plugins/pyflakes.py
@@ -46,6 +46,9 @@ class FlakesChecker(pyflakes.checker.Checker):
 
     name = 'pyflakes'
     version = pyflakes.__version__
+    with_doctest = False
+    include_in_doctest = []
+    exclude_from_doctest = []
 
     def __init__(self, tree, filename):
         """Initialize the PyFlakes plugin with an AST tree and filename."""
diff --git a/src/flake8/processor.py b/src/flake8/processor.py
index 1d0e3a4..44024e5 100644
--- a/src/flake8/processor.py
+++ b/src/flake8/processor.py
@@ -129,9 +129,9 @@ class FileProcessor(object):
 
     def update_checker_state_for(self, plugin):
         """Update the checker_state attribute for the plugin."""
-        if 'checker_state' in plugin.parameters:
+        if 'checker_state' in plugin['parameters']:
             self.checker_state = self._checker_states.setdefault(
-                plugin.name, {}
+                plugin['name'], {}
             )
 
     def next_logical_line(self):
@@ -240,14 +240,8 @@ class FileProcessor(object):
                     break
                 self.tokens.append(token)
                 yield token
-        # NOTE(sigmavirus24): pycodestyle was catching both a SyntaxError
-        # and a tokenize.TokenError. In looking a the source on Python 2 and
-        # Python 3, the SyntaxError should never arise from generate_tokens.
-        # If we were using tokenize.tokenize, we would have to catch that. Of
-        # course, I'm going to be unsurprised to be proven wrong at a later
-        # date.
-        except tokenize.TokenError as exc:
-            raise exceptions.InvalidSyntax(exc.message, exception=exc)
+        except (tokenize.TokenError, SyntaxError) as exc:
+            raise exceptions.InvalidSyntax(exception=exc)
 
     def line_for(self, line_number):
         """Retrieve the physical line at the specified line number."""
diff --git a/tests/integration/test_checker.py b/tests/integration/test_checker.py
index 5c013b6..1b8a3c5 100644
--- a/tests/integration/test_checker.py
+++ b/tests/integration/test_checker.py
@@ -63,7 +63,11 @@ def test_handle_file_plugins(plugin_target):
     # Prevent it from reading lines from stdin or somewhere else
     with mock.patch('flake8.processor.FileProcessor.read_lines',
                     return_value=['Line 1']):
-        file_checker = checker.FileChecker('-', checks, mock.MagicMock())
+        file_checker = checker.FileChecker(
+            '-',
+            checks.to_dictionary(),
+            mock.MagicMock()
+        )
 
     # Do not actually build an AST
     file_checker.processor.build_ast = lambda: True
diff --git a/tests/unit/test_checker_manager.py b/tests/unit/test_checker_manager.py
index 7e9c5b1..e5562ef 100644
--- a/tests/unit/test_checker_manager.py
+++ b/tests/unit/test_checker_manager.py
@@ -47,8 +47,14 @@ def test_make_checkers():
     """Verify that we create a list of FileChecker instances."""
     style_guide = style_guide_mock()
     files = ['file1', 'file2']
+    checkplugins = mock.Mock()
+    checkplugins.to_dictionary.return_value = {
+        'ast_plugins': [],
+        'logical_line_plugins': [],
+        'physical_line_plugins': [],
+    }
     with mock.patch('flake8.checker.multiprocessing', None):
-        manager = checker.Manager(style_guide, files, [])
+        manager = checker.Manager(style_guide, files, checkplugins)
 
     with mock.patch('flake8.utils.filenames_from') as filenames_from:
         filenames_from.side_effect = [['file1'], ['file2']]

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-flake8.git



More information about the Python-modules-commits mailing list