Upgrading to GitLab 11.10.0. Expect errors and see debian-infrastructure-announce@lists.debian.org for further information.

Commit ebfbc62e authored by Daniel Stender's avatar Daniel Stender

Imported Upstream version 0.3.1

parents
*.egg
*.egg-info
*.py[cod]
.tox
dist
.project
.pydevproject
.settings/
build/
language: python
sudo: false
install:
pip install tox
script: tox
env:
matrix:
- TOXENV=py26
- TOXENV=py27
- TOXENV=py32
- TOXENV=py33
- TOXENV=py34
- TOXENV=pypy
- TOXENV=pypy3
Copyright © 2013 Florent Xicluna <florent.xicluna@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.
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.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
This diff is collapsed.
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()
[wheel]
universal = 1
# -*- coding: utf-8 -*-
from __future__ import with_statement
from setuptools import setup
from setuptools.command.test import test as TestCommand
def get_version(fname='pep8ext_naming.py'):
with open(fname) as f:
for line in f:
if line.startswith('__version__'):
return eval(line.split('=')[-1])
def get_long_description():
descr = []
for fname in ('README.rst',):
with open(fname) as f:
descr.append(f.read())
return '\n\n'.join(descr)
class RunTests(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
import run_tests
import sys
errno = run_tests.main()
sys.exit(errno)
setup(
name='pep8-naming',
version=get_version(),
description="Check PEP-8 naming conventions, plugin for flake8",
long_description=get_long_description(),
keywords='flake8 pep8 naming',
author='Florent Xicluna',
author_email='florent.xicluna@gmail.com',
url='https://github.com/flintwork/pep8-naming',
license='Expat license',
py_modules=['pep8ext_naming'],
zip_safe=False,
entry_points={
'flake8.extension': [
'N8 = pep8ext_naming:NamingChecker',
],
# Backward compatibility for Flint (now merged into Flake8)
'flint.extension': [
'N80 = pep8ext_naming:NamingChecker',
'N81 = pep8ext_naming:NamingChecker',
],
},
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Software Development :: Quality Assurance',
],
cmdclass={'test': RunTests},
)
#: N801
class notok(object):
pass
#: N801
class Good(object):
class notok(object):
pass
pass
#: Okay
class VeryGood(object):
pass
#: 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
#: 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
# python2 only
#: Okay
def test(a, b, (good, verygood)):
pass
#: N803
def bad(a, b, (OHH, NOO)):
pass
# 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
#: N804
class Foo(object):
@classmethod
def mmm(cls, ads):
pass
@classmethod
def bad(self, ads):
pass
@calling()
def test(self, ads):
pass
#: 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
#: 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')
#: 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
[tox]
envlist = py26,py27,py32,py33,py34,pypy,pypy3
[testenv]
commands = python run_tests.py
[testenv:release]
deps =
twine >= 1.4.0
wheel
commands =
python setup.py sdist bdist_wheel
twine upload {posargs} dist/*
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment