[Python-modules-commits] [pep8-naming] 06/10: Import pep8-naming_0.4.1.orig.tar.xz

Daniel Stender stender at moszumanska.debian.org
Wed Jun 29 10:35:54 UTC 2016


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

stender pushed a commit to branch master
in repository pep8-naming.

commit a5b436a65c550491449f96178c2893598e9f9ce7
Author: Daniel Stender <stender at debian.org>
Date:   Wed Jun 29 12:06:04 2016 +0200

    Import pep8-naming_0.4.1.orig.tar.xz
---
 .travis.yml           |  29 ++++++++++
 LICENSE               |  23 ++++++++
 MANIFEST.in           |   2 +
 PKG-INFO              | 147 --------------------------------------------------
 README.rst            |  21 ++++----
 pep8ext_naming.py     |  33 +++++++++---
 run_tests.py          |  81 ++++++++++++++++++++++++++++
 setup.cfg             |   6 ---
 testsuite/N801.py     |  11 ++++
 testsuite/N802.py     |  72 +++++++++++++++++++++++++
 testsuite/N803.py     |  50 +++++++++++++++++
 testsuite/N803_py2.py |   7 +++
 testsuite/N803_py3.py |  13 +++++
 testsuite/N804.py     |  13 +++++
 testsuite/N805.py     |  16 ++++++
 testsuite/N806.py     |  48 +++++++++++++++++
 testsuite/N81x.py     |  12 +++++
 tox.ini               |  24 +++++++++
 18 files changed, 440 insertions(+), 168 deletions(-)

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..fedf3d6
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,29 @@
+language: python
+
+sudo: false
+
+install:
+    pip install tox
+
+script: tox
+
+matrix:
+  include:
+    - env: TOXENV=py26
+      python: 2.6
+    - env: TOXENV=py27
+      python: 2.7
+    - env: TOXENV=py33
+      python: 3.3
+    - env: TOXENV=py34
+      python: 3.4
+    - env: TOXENV=py35
+      python: 3.5
+    - env: TOXENV=pypy
+      python: pypy
+    - env: TOXENV=pypy3
+      python: pypy3
+    - env: TOXENV=py27-flake8
+      python: 2.7
+    - env: TOXENV=py34-flake8
+      python: 3.4
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..a7621d3
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,23 @@
+Copyright © 2013 Florent Xicluna <florent.xicluna at gmail.com>
+
+Licensed under the terms of the Expat License
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation files
+(the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of the Software,
+and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..cb0f808
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,2 @@
+include run_tests.py
+recursive-include testsuite *.py
diff --git a/PKG-INFO b/PKG-INFO
deleted file mode 100644
index 30fca9b..0000000
--- a/PKG-INFO
+++ /dev/null
@@ -1,147 +0,0 @@
-Metadata-Version: 1.1
-Name: pep8-naming
-Version: 0.3.3
-Summary: Check PEP-8 naming conventions, plugin for flake8
-Home-page: https://github.com/flintwork/pep8-naming
-Author: Florent Xicluna
-Author-email: florent.xicluna at gmail.com
-License: Expat license
-Description: PEP-8 Naming Conventions
-        ========================
-        
-        .. image:: https://badge.fury.io/py/pep8-naming.png
-            :target: http://badge.fury.io/py/pep8-naming
-            
-        .. image:: https://travis-ci.org/flintwork/pep8-naming.png?branch=master
-                :target: https://travis-ci.org/flintwork/pep8-naming
-        
-        .. image:: https://pypip.in/d/pep8-naming/badge.png
-                :target: https://crate.io/packages/pep8-naming?version=latest
-        
-        Check the PEP-8 naming conventions.
-        
-        This module provides a plugin for ``flake8``, the Python code checker.
-        
-        (It replaces the plugin ``flint-naming`` for the ``flint`` checker.)
-        
-        
-        Installation
-        ------------
-        
-        You can install, upgrade, uninstall ``pep8-naming`` with these commands::
-        
-          $ pip install pep8-naming
-          $ pip install --upgrade pep8-naming
-          $ pip uninstall pep8-naming
-        
-        
-        Plugin for Flake8
-        -----------------
-        
-        When both ``flake8`` and ``pep8-naming`` are installed, the plugin is
-        available in ``flake8``::
-        
-          $ flake8 --version
-          2.0 (pep8: 1.4.3, pyflakes: 0.6.1, naming: 0.2)
-        
-        By default the plugin is enabled.
-        
-        These error codes are emitted:
-        
-        +------+-------------------------------------------------------+
-        | code | sample message                                        |
-        +======+=======================================================+
-        | N801 | class names should use CapWords convention            |
-        +------+-------------------------------------------------------+
-        | N802 | function name should be lowercase                     |
-        +------+-------------------------------------------------------+
-        | N803 | argument name should be lowercase                     |
-        +------+-------------------------------------------------------+
-        | N804 | first argument of a classmethod should be named 'cls' |
-        +------+-------------------------------------------------------+
-        | N805 | first argument of a method should be named 'self'     |
-        +------+-------------------------------------------------------+
-        | N806 | variable in function should be lowercase              |
-        +------+-------------------------------------------------------+
-        +------+-------------------------------------------------------+
-        | N811 | constant imported as non constant                     |
-        +------+-------------------------------------------------------+
-        | N812 | lowercase imported as non lowercase                   |
-        +------+-------------------------------------------------------+
-        | N813 | camelcase imported as lowercase                       |
-        +------+-------------------------------------------------------+
-        | N814 | camelcase imported as constant                        |
-        +------+-------------------------------------------------------+
-        
-        
-        Changes
-        -------
-        
-        0.3.3 - 2015-06-30
-        ``````````````````
-        
-        * Fix bug where ignored names were not properly split into a list.
-        
-        0.3.2 - 2015-06-14
-        ``````````````````
-        
-        * Fix bug trying to call ``split`` on a list.
-        
-        0.3.1 - 2015-06-14
-        ``````````````````
-        
-        * Fix optparse exception resulting from trying to register an option twice.
-        
-        
-        0.3.0 - 2015-06-14
-        ``````````````````
-        
-        * Relaxed N806 checking for use with namedtuples
-        
-        * Add ``--ignore-names`` which allows the user to specify a list of names to
-          ignore. By default this includes ``setUp``, ``tearDown``, ``setUpClass``,
-          and ``tearDownClass``.
-        
-        
-        0.2.2 - 2014-04-19
-        ``````````````````
-        * Do not require ``setuptools`` in setup.py.  It works around an issue
-          with ``pip`` and Python 3.
-        
-        * ``__new__`` is now considered as ``classmethod`` implicitly
-        
-        * Run unit tests on travis-ci.org for python2.6, 2.7, 3.2, and 3.3
-        
-        * Add unit tests and support running them with setup.py
-        
-        * Support Python 3.4 
-        
-        
-        0.2.1 - 2013-02-22
-        ``````````````````
-        * Do not require ``flake8``
-        
-        
-        0.2 - 2013-02-22
-        ````````````````
-        * Rename project ``flint-naming`` to ``pep8-naming``
-        
-        * Fix a crash when function argument is a tuple of tuples
-        
-        
-        0.1 - 2013-02-11
-        ````````````````
-        * First release
-        
-Keywords: flake8 pep8 naming
-Platform: UNKNOWN
-Classifier: Development Status :: 3 - Alpha
-Classifier: Environment :: Console
-Classifier: Intended Audience :: Developers
-Classifier: License :: OSI Approved :: MIT License
-Classifier: Operating System :: OS Independent
-Classifier: Programming Language :: Python
-Classifier: Programming Language :: Python :: 2
-Classifier: Programming Language :: Python :: 3
-Classifier: Topic :: Software Development :: Libraries :: Python Modules
-Classifier: Topic :: Software Development :: Quality Assurance
diff --git a/README.rst b/README.rst
index 9e10be0..1dd6910 100644
--- a/README.rst
+++ b/README.rst
@@ -1,15 +1,6 @@
 PEP-8 Naming Conventions
 ========================
 
-.. image:: https://badge.fury.io/py/pep8-naming.png
-    :target: http://badge.fury.io/py/pep8-naming
-    
-.. image:: https://travis-ci.org/flintwork/pep8-naming.png?branch=master
-        :target: https://travis-ci.org/flintwork/pep8-naming
-
-.. image:: https://pypip.in/d/pep8-naming/badge.png
-        :target: https://crate.io/packages/pep8-naming?version=latest
-
 Check the PEP-8 naming conventions.
 
 This module provides a plugin for ``flake8``, the Python code checker.
@@ -69,6 +60,18 @@ These error codes are emitted:
 Changes
 -------
 
+0.4.1 - 2016-06-26
+``````````````````
+
+* Note to self: Never do releases before ~0600 or coffee on a Sunday.
+* Fix option parsing for Flake8 3.0 (store parsed value on class)
+
+0.4.0 - 2016-06-26
+``````````````````
+
+* Fix integration with Flake8 3.0.0b1
+* Start testing against Python 3.5
+
 0.3.3 - 2015-06-30
 ``````````````````
 
diff --git a/pep8ext_naming.py b/pep8ext_naming.py
index 77a0f50..6c896d8 100644
--- a/pep8ext_naming.py
+++ b/pep8ext_naming.py
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 """Checker of PEP-8 Naming Conventions."""
+import optparse
 import re
 import sys
 from collections import deque
@@ -10,7 +11,7 @@ try:
 except ImportError:
     from flake8.util import ast, iter_child_nodes
 
-__version__ = '0.3.3'
+__version__ = '0.4.1'
 
 LOWERCASE_REGEX = re.compile(r'[_a-z][_a-z0-9]*$')
 UPPERCASE_REGEX = re.compile(r'[_A-Z][_A-Z0-9]*$')
@@ -58,6 +59,20 @@ BaseASTCheck = _ASTCheckMeta('BaseASTCheck', (object,),
                              {'__doc__': "Base for AST Checks.", 'err': _err})
 
 
+def register_opt(parser, *args, **kwargs):
+    try:
+        # Flake8 3.x registration
+        parser.add_option(*args, **kwargs)
+    except (optparse.OptionError, TypeError):
+        # Flake8 2.x registration
+        parse_from_config = kwargs.pop('parse_from_config', False)
+        kwargs.pop('comma_separated_list', False)
+        kwargs.pop('normalize_paths', False)
+        parser.add_option(*args, **kwargs)
+        if parse_from_config:
+            parser.config_options.append(args[-1].lstrip('-'))
+
+
 class NamingChecker(object):
     """Checker of PEP-8 Naming Conventions."""
     name = 'naming'
@@ -72,14 +87,20 @@ class NamingChecker(object):
     @classmethod
     def add_options(cls, parser):
         ignored = ','.join(cls.ignore_names)
-        parser.add_option('--ignore-names', default=ignored,
-                          action='store', type='string',
-                          help="Names that should be ignored.")
-        parser.config_options.append('ignore-names')
+        register_opt(parser, '--ignore-names',
+                     default=ignored,
+                     action='store',
+                     type='string',
+                     parse_from_config=True,
+                     comma_separated_list=True,
+                     help='List of names the pep8-naming plugin should '
+                          'ignore. (Defaults to %default)')
 
     @classmethod
     def parse_options(cls, options):
-        cls.ignore_names = SPLIT_IGNORED_RE.split(options.ignore_names)
+        cls.ignore_names = options.ignore_names
+        if not isinstance(cls.ignore_names, list):
+            cls.ignore_names = SPLIT_IGNORED_RE.split(options.ignore_names)
 
     def run(self):
         return self.visit_tree(self._node) if self._node else ()
diff --git a/run_tests.py b/run_tests.py
new file mode 100644
index 0000000..b3d1b93
--- /dev/null
+++ b/run_tests.py
@@ -0,0 +1,81 @@
+import sys
+import os
+import pep8ext_naming
+import re
+
+PyCF_ONLY_AST = 1024
+
+IS_PY3 = sys.version_info[0] == 3
+IS_PY3_TEST = re.compile("^#\s*python3\s*only")
+IS_PY2_TEST = re.compile("^#\s*python2\s*only")
+
+
+def main():
+    print('Running pep8-naming tests')
+    test_count = 0
+    errors = 0
+    for filename in os.listdir('testsuite'):
+        with open(os.path.join('testsuite', filename)) as fd:
+            lines = list(fd)
+            if not is_test_allowed(lines):
+                continue
+
+            for testcase, codes in load_tests(lines):
+                test_count += 1
+                errors += test_file(filename, testcase, codes)
+
+    if errors == 0:
+        print("%s tests run successful" % test_count)
+        sys.exit(0)
+    else:
+        print("%i of %i tests failed" % (errors, test_count))
+        sys.exit(1)
+
+
+def is_test_allowed(lines):
+    if IS_PY3 and any(IS_PY2_TEST.search(line) for line in lines[:3]):
+        return False
+
+    if not IS_PY3 and any(IS_PY3_TEST.search(line) for line in lines[:3]):
+        return False
+
+    return True
+
+
+def load_tests(lines):
+    testcase = []
+    codes = []
+    for line in lines:
+        if line.startswith("#:"):
+            if testcase:
+                yield testcase, codes
+                del testcase[:]
+            codes = line.split()[1:]
+        else:
+            testcase.append(line)
+
+    if testcase and codes:
+        yield testcase, codes
+
+
+def test_file(filename, lines, codes):
+    tree = compile(''.join(lines), '', 'exec', PyCF_ONLY_AST)
+    checker = pep8ext_naming.NamingChecker(tree, filename)
+    found_errors = []
+    for lineno, col_offset, msg, instance in checker.run():
+        found_errors.append(msg.split()[0])
+
+    if not found_errors and codes == ['Okay']:
+        return 0
+
+    errors = 0
+    for code in codes:
+        if code not in found_errors:
+            errors += 1
+            print("ERROR: %s not in %s" % (code, filename))
+
+    return errors
+
+
+if __name__ == '__main__':
+    main()
diff --git a/setup.cfg b/setup.cfg
index 9a777d0..5e40900 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,8 +1,2 @@
 [wheel]
 universal = 1
-
-[egg_info]
-tag_date = 0
-tag_build = 
-tag_svn_revision = 0
-
diff --git a/testsuite/N801.py b/testsuite/N801.py
new file mode 100644
index 0000000..68b50d0
--- /dev/null
+++ b/testsuite/N801.py
@@ -0,0 +1,11 @@
+#: N801
+class notok(object):
+    pass
+#: N801
+class Good(object):
+    class notok(object):
+        pass
+    pass
+#: Okay
+class VeryGood(object):
+    pass
diff --git a/testsuite/N802.py b/testsuite/N802.py
new file mode 100644
index 0000000..9061def
--- /dev/null
+++ b/testsuite/N802.py
@@ -0,0 +1,72 @@
+#: Okay
+def ok():
+    pass
+#: N802
+def __bad():
+    pass
+#: N802
+def bad__():
+    pass
+#: N802
+def __bad__():
+    pass
+#: Okay
+def _ok():
+    pass
+#: Okay
+def ok_ok_ok_ok():
+    pass
+#: Okay
+def _somehow_good():
+    pass
+#: Okay
+def go_od_():
+    pass
+#: Okay
+def _go_od_():
+    pass
+#: N802
+def NotOK():
+    pass
+#: Okay
+def _():
+    pass
+#: Okay
+class Foo(object):
+    def __method(self):
+        pass
+#: Okay
+class Foo(object):
+    def __method__(self):
+        pass
+#: Okay
+class ClassName(object):
+    def __method__(self):
+        pass
+#: N802
+class ClassName(object):
+    def notOk(self):
+        pass
+#: N802
+class ClassName(object):
+    def method(self):
+        def __bad():
+            pass
+#: Okay
+def setUp():
+    pass
+
+#: Okay
+def tearDown():
+    pass
+
+#: Okay
+class TestCase:
+    def setUp(self):
+        pass
+    def tearDown(self):
+        pass
+    def setUpClass(self):
+        pass
+    def tearDownClass(self):
+        pass
diff --git a/testsuite/N803.py b/testsuite/N803.py
new file mode 100644
index 0000000..f619bd6
--- /dev/null
+++ b/testsuite/N803.py
@@ -0,0 +1,50 @@
+#: Okay
+def b1():
+    pass
+#: Okay
+def b2(a):
+    pass
+#: Okay
+def b3(a, b, c, d):
+    pass
+#: Okay
+def b4(a, b, c, *fuck):
+    pass
+#: Okay
+def b5(*fuck):
+    pass
+#: Okay
+def b6(a, b, c, **kwargs):
+    pass
+#: Okay
+def b7(**kwargs):
+    pass
+#: Okay
+def b8(*args, **kwargs):
+    pass
+#: Okay
+def b9(a, b, c, *args, **kwargs):
+    pass
+#: Okay
+def b10(a, b, c=3, d=4, *args, **kwargs):
+    pass
+#: N803
+def b11(**BAD):
+    pass
+#: N803
+def b12(*BAD):
+    pass
+#: N803
+def b13(BAD, *VERYBAD, **EXTRABAD):
+    pass
+#: N803
+def b14(BAD):
+    pass
+#: N803
+class Test(object):
+    def __init__(self, BAD):
+        pass
+
+    @classmethod
+    def test(cls, BAD):
+        pass
diff --git a/testsuite/N803_py2.py b/testsuite/N803_py2.py
new file mode 100644
index 0000000..58a6896
--- /dev/null
+++ b/testsuite/N803_py2.py
@@ -0,0 +1,7 @@
+# python2 only
+#: Okay
+def test(a, b, (good, verygood)):
+    pass
+#: N803
+def bad(a, b, (OHH, NOO)):
+    pass
diff --git a/testsuite/N803_py3.py b/testsuite/N803_py3.py
new file mode 100644
index 0000000..7fdaeec
--- /dev/null
+++ b/testsuite/N803_py3.py
@@ -0,0 +1,13 @@
+# python3 only
+#: Okay
+def compare(a, b, *, key=None):
+    pass
+#: N803
+def compare(a, b, *, BAD=None):
+    pass
+#: N803
+def compare(a, b, *VERY, bad=None):
+    pass
+#: N803
+def compare(a, b, *ok, fine=None, **BAD):
+    pass
diff --git a/testsuite/N804.py b/testsuite/N804.py
new file mode 100644
index 0000000..0fe6c06
--- /dev/null
+++ b/testsuite/N804.py
@@ -0,0 +1,13 @@
+#: N804
+class Foo(object):
+    @classmethod
+    def mmm(cls, ads):
+        pass
+
+    @classmethod
+    def bad(self, ads):
+        pass
+
+    @calling()
+    def test(self, ads):
+        pass
diff --git a/testsuite/N805.py b/testsuite/N805.py
new file mode 100644
index 0000000..2a19e1a
--- /dev/null
+++ b/testsuite/N805.py
@@ -0,0 +1,16 @@
+#: N805
+class Foo(object):
+    def good(self, ads):
+        pass
+
+    def bad(ads, self):
+        pass
+#: Okay
+class Foo(object):
+    def __new__(cls):
+        return object.__new__(Foo)
+#: Okay
+class Foo(object):
+    @classmethod
+    def __prepare__(cls):
+        pass
diff --git a/testsuite/N806.py b/testsuite/N806.py
new file mode 100644
index 0000000..53cb2d0
--- /dev/null
+++ b/testsuite/N806.py
@@ -0,0 +1,48 @@
+#: Okay
+def test():
+    good = 1
+#: Okay
+def test():
+    def test2():
+        good = 1
+#: Okay
+GOOD = 1
+#: Okay
+class Test(object):
+    GOOD = 1
+#: N806
+def test():
+    Bad = 1
+#: N806
+def test():
+    VERY = 2
+#: N806
+def test():
+    def test2():
+        class Foo(object):
+            def test3(self):
+                Bad = 3
+#: Okay
+def good():
+    global Bad
+    Bad = 1
+#: N806
+def bad():
+    global Bad
+
+    def foo():
+        Bad = 1
+
+#: Okay
+def test():
+    # namedtuples are often CamelCased since we treat them a bit like classes
+    import collections
+    Thing = collections.namedtuple('Thing', 'a b c')
+    from collections import namedtuple
+    ThingTwo = namedtuple('ThingTwo', 'a b c')
+
+#: N806
+def bad():
+    # Currently don't support aliased imports of namedtuple
+    from collections import namedtuple as nt
+    Thing = nt('Thing', 'a b c')
diff --git a/testsuite/N81x.py b/testsuite/N81x.py
new file mode 100644
index 0000000..826f331
--- /dev/null
+++ b/testsuite/N81x.py
@@ -0,0 +1,12 @@
+#: Okay
+import good as good
+#: Okay
+from mod import good as nice, NICE as GOOD, Camel as Memel
+#: N811
+from mod import GOOD as bad
+#: N812
+from mod import good as Bad
+#: N813
+from mod import CamelCase as noncamle
+#: N814
+from mod import CamelCase as CONSTANT
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..c7dd178
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,24 @@
+[tox]
+envlist = py26,py27,py33,py34,py35,pypy,pypy3
+
+[testenv]
+commands = python run_tests.py
+
+[testenv:py27-flake8]
+deps =
+    flake8
+commands = flake8 {posargs} pep8ext_naming.py
+
+[testenv:py34-flake8]
+basepython = python3.4
+deps =
+    flake8
+commands = flake8 {posargs} pep8ext_naming.py
+
+[testenv:release]
+deps =
+    twine >= 1.4.0
+    wheel
+commands =
+    python setup.py sdist bdist_wheel
+    twine upload {posargs} dist/*

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



More information about the Python-modules-commits mailing list