diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2012-04-06 07:35:21 -0700 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2012-04-06 07:35:21 -0700 |
commit | c8c2b738a3721b58a74554eb260619c9a7560b8e (patch) | |
tree | 30ef2238d4e74b3d0c3e8c44b4e9ad6d85c556c2 | |
parent | 29968a6fa42ea2802118df92bd829344d910b8ae (diff) | |
parent | 738715dd58d9566c44724b5d7353a7cf5a56f2f8 (diff) | |
download | pep8-c8c2b738a3721b58a74554eb260619c9a7560b8e.tar.gz |
Merge pull request #52 from florentx/master
Merge release 1.0 in trunk
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CHANGES.txt | 36 | ||||
-rw-r--r-- | MANIFEST.in | 1 | ||||
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | README.rst | 4 | ||||
-rw-r--r-- | TODO.txt | 8 | ||||
-rwxr-xr-x | pep8.py | 66 | ||||
-rw-r--r-- | setup.py | 64 | ||||
-rw-r--r-- | testsuite/W60.py | 2 |
9 files changed, 118 insertions, 67 deletions
@@ -1 +1,2 @@ pep8.egg-info +*.pyc diff --git a/CHANGES.txt b/CHANGES.txt index 4934a46..7e8f6ba 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,42 @@ Changelog ========= +1.0 (2012-04-04) +---------------- + +* Fix W602 ``raise`` to handle multi-char names. (Issue #53) + + +0.7.0 (2012-03-26) +------------------ + +* Now ``--first`` prints only the first occurence of each error. + The ``--repeat`` flag becomes obsolete because it is the default + behaviour. (Issue #6) + +* Allow to specify ``--max-line-length``. (Issue #36) + +* Make the shebang more flexible. (Issue #26) + +* Add testsuite to the bundle. (Issue #25) + +* Fixes for Jython. (Issue #49) + +* Add PyPI classifiers. (Issue #43) + +* Fix the ``--exclude`` option. (Issue #48) + +* Fix W602, accept ``raise`` with 3 arguments. (Issue #34) + +* Correctly select all tests if ``DEFAULT_IGNORE == ''``. + + +0.6.1 (2010-10-03) +------------------ + +* Fix inconsistent version numbers. (Issue #21) + + 0.6.0 (2010-09-19) ------------------ diff --git a/MANIFEST.in b/MANIFEST.in index d40acf7..bdce657 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ +recursive-include testsuite * include pep8.py include *.txt include *.rst @@ -17,6 +17,7 @@ multitest : python2.7 pep8.py --testsuite testsuite python3.0 pep8.py --testsuite testsuite python3.1 pep8.py --testsuite testsuite + python3.2 pep8.py --testsuite testsuite python2.3 pep8.py --doctest python2.4 pep8.py --doctest python2.5 pep8.py --doctest @@ -24,6 +25,7 @@ multitest : python2.7 pep8.py --doctest python3.0 pep8.py --doctest python3.1 pep8.py --doctest + python3.2 pep8.py --doctest python2.3 pep8.py --repeat --statistics pep8.py python2.4 pep8.py --repeat --statistics pep8.py python2.5 pep8.py --repeat --statistics pep8.py @@ -31,3 +33,4 @@ multitest : python2.7 pep8.py --repeat --statistics pep8.py python3.0 pep8.py --repeat --statistics pep8.py python3.1 pep8.py --repeat --statistics pep8.py + python3.2 pep8.py --repeat --statistics pep8.py @@ -95,7 +95,8 @@ Quick help is available on the command line:: -h, --help show this help message and exit -v, --verbose print status messages, or debug with -vv -q, --quiet report only file names, or nothing with -qq - -r, --repeat show all occurrences of the same error + -r, --repeat (obsolete) show all occurrences of the same error + --first show first occurrence of each error --exclude=patterns exclude files or directories which match these comma separated patterns (default: .svn,CVS,.bzr,.hg,.git) --filename=patterns when parsing directories, only check filenames matching @@ -109,6 +110,7 @@ Quick help is available on the command line:: error and set exit code to 1 if total is not null --benchmark measure processing speed --testsuite=dir run regression tests from dir + --max-line-length=n set maximum allowed line length (default 79) --doctest run doctest on myself Feedback @@ -1,8 +0,0 @@ -TODO -==== - -- Should command line option --repeat be enabled by default? - -- Does command line option --ignore properly prevent status code 1? - -- Release version 1.0 after a brief stabilization period. @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # pep8.py - Check Python source code formatting, according to PEP 8 # Copyright (C) 2006 Johann C. Rocholl <johann@rocholl.net> # @@ -92,7 +92,7 @@ for space. """ -__version__ = '0.5.1dev' +__version__ = '0.7.1dev' import os import sys @@ -115,6 +115,7 @@ MAX_LINE_LENGTH = 79 INDENT_REGEX = re.compile(r'([ \t]*)') RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*(,)') +RERAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,\s*\w+\s*,\s*\w+') SELFTEST_REGEX = re.compile(r'(Okay|[EW]\d{3}):\s(.*)') ERRORCODE_REGEX = re.compile(r'[EW]\d{3}') DOCSTRING_REGEX = re.compile(r'u?r?["\']') @@ -123,6 +124,7 @@ WHITESPACE_AROUND_OPERATOR_REGEX = \ EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]') WHITESPACE_AROUND_NAMED_PARAMETER_REGEX = \ re.compile(r'[()]|\s=[^=]|[^=!<>]=\s') +LAMBDA_REGEX = re.compile(r'\blambda\b') WHITESPACE = ' \t' @@ -242,16 +244,17 @@ def maximum_line_length(physical_line): """ line = physical_line.rstrip() length = len(line) - if length > MAX_LINE_LENGTH: + if length > options.max_line_length: try: # The line could contain multi-byte characters if not hasattr(line, 'decode'): # Python 3 line = line.encode('latin-1') length = len(line.decode('utf-8')) - except UnicodeDecodeError: + except UnicodeError: pass - if length > MAX_LINE_LENGTH: - return MAX_LINE_LENGTH, "E501 line too long (%d characters)" % length + if length > options.max_line_length: + return options.max_line_length, \ + "E501 line too long (%d characters)" % length ############################################################################## @@ -656,7 +659,7 @@ def compound_statements(logical_line): before = line[:found] if (before.count('{') <= before.count('}') and # {'a': 1} (dict) before.count('[') <= before.count(']') and # [1:2] (slice) - not re.search(r'\blambda\b', before)): # lambda x: x + not LAMBDA_REGEX.search(before)): # lambda x: x return found, "E701 multiple statements on one line (colon)" found = line.find(';') if -1 < found: @@ -687,7 +690,7 @@ def python_3000_raise_comma(logical_line): form will be removed in Python 3000. """ match = RAISE_COMMA_REGEX.match(logical_line) - if match: + if match and not RERAISE_COMMA_REGEX.match(logical_line): return match.start(1), "W602 deprecated form of raising exception" @@ -781,13 +784,6 @@ def mute_string(text): return text[:start] + 'x' * (end - start) + text[end:] -def message(text): - """Print a message.""" - # print >> sys.stderr, options.prog + ': ' + text - # print >> sys.stderr, text - print(text) - - ############################################################################## # Framework to run all checks ############################################################################## @@ -996,7 +992,7 @@ class Checker(object): if ignore_code(code): return if options.quiet == 1 and not self.file_errors: - message(self.filename) + print(self.filename) if code in options.counters: options.counters[code] += 1 else: @@ -1007,15 +1003,15 @@ class Checker(object): return self.file_errors += 1 if options.counters[code] == 1 or options.repeat: - message("%s:%s:%d: %s" % - (self.filename, self.line_offset + line_number, - offset + 1, text)) + print("%s:%s:%d: %s" % + (self.filename, self.line_offset + line_number, + offset + 1, text)) if options.show_source: line = self.lines[line_number - 1] - message(line.rstrip()) - message(' ' * offset + '^') + print(line.rstrip()) + print(' ' * offset + '^') if options.show_pep8: - message(check.__doc__.lstrip('\n').rstrip()) + print(check.__doc__.lstrip('\n').rstrip()) def input_file(filename): @@ -1023,7 +1019,7 @@ def input_file(filename): Run all checks on a Python source file. """ if options.verbose: - message('checking ' + filename) + print('checking ' + filename) errors = Checker(filename).check_all() @@ -1038,10 +1034,10 @@ def input_dir(dirname, runner=None): runner = input_file for root, dirs, files in os.walk(dirname): if options.verbose: - message('directory ' + root) + print('directory ' + root) options.counters['directories'] += 1 dirs.sort() - for subdir in dirs: + for subdir in dirs[:]: if excluded(subdir): dirs.remove(subdir) files.sort() @@ -1146,8 +1142,8 @@ def print_benchmark(elapsed): print('%-7.2f %s' % (elapsed, 'seconds elapsed')) for key in BENCHMARK_KEYS: print('%-7d %s per second (%d total)' % ( - options.counters[key] / elapsed, key, - options.counters[key])) + options.counters[key] / elapsed, key, + options.counters[key])) def run_tests(filename): @@ -1187,9 +1183,9 @@ def run_tests(filename): for code in codes: if not options.counters.get(code): errors += 1 - message('%s: error %s not found' % (label, code)) + print('%s: error %s not found' % (label, code)) if options.verbose and not errors: - message('%s: passed (%s)' % (label, ' '.join(codes))) + print('%s: passed (%s)' % (label, ' '.join(codes))) # Keep showing errors for multiple tests reset_counters() # output the real line numbers @@ -1261,8 +1257,10 @@ def process_options(arglist=None): help="print status messages, or debug with -vv") parser.add_option('-q', '--quiet', default=0, action='count', help="report only file names, or nothing with -qq") - parser.add_option('-r', '--repeat', action='store_true', - help="show all occurrences of the same error") + parser.add_option('-r', '--repeat', default=True, action='store_true', + help="(obsolete) show all occurrences of the same error") + parser.add_option('--first', action='store_false', dest='repeat', + help="show first occurrence of each error") parser.add_option('--exclude', metavar='patterns', default=DEFAULT_EXCLUDE, help="exclude files or directories which match these " "comma separated patterns (default: %s)" % @@ -1289,6 +1287,10 @@ def process_options(arglist=None): help="measure processing speed") parser.add_option('--testsuite', metavar='dir', help="run regression tests from dir") + parser.add_option('--max-line-length', type='int', metavar='n', + default=MAX_LINE_LENGTH, + help="set maximum allowed line length (default: %d)" % + MAX_LINE_LENGTH) parser.add_option('--doctest', action='store_true', help="run doctest on myself") options, args = parser.parse_args(arglist) @@ -1311,7 +1313,7 @@ def process_options(arglist=None): elif options.select: # Ignore all checks which are not explicitly selected options.ignore = [''] - elif options.testsuite or options.doctest: + elif options.testsuite or options.doctest or not DEFAULT_IGNORE: # For doctest and testsuite, all checks are required options.ignore = [] else: @@ -1,31 +1,43 @@ from setuptools import setup, find_packages -version = '0.6.0' +version = '1.0' long_description = '\n\n'.join([open('README.rst').read(), open('CHANGES.txt').read(), - open('TODO.txt').read()]) +# open('TODO.txt').read(), + ]) -setup(name='pep8', - version=version, - description="Python style guide checker", - long_description=long_description, - classifiers=[], - keywords='pep8', - author='Johann C. Rocholl', - author_email='johann@rocholl.net', - url='http://github.com/jcrocholl/pep8', - license='Expat license', - py_modules=['pep8'], - namespace_packages=[], - include_package_data=True, - zip_safe=False, - install_requires=[ - 'setuptools', - # -*- Extra requirements: -*- - ], - entry_points={ - 'console_scripts': [ - 'pep8 = pep8:_main', - ], - }, - ) +setup( + name='pep8', + version=version, + description="Python style guide checker", + long_description=long_description, + keywords='pep8', + author='Johann C. Rocholl', + author_email='johann@rocholl.net', + url='http://github.com/jcrocholl/pep8', + license='Expat license', + py_modules=['pep8'], + namespace_packages=[], + include_package_data=True, + zip_safe=False, + install_requires=[ + 'setuptools', + # -*- Extra requirements: -*- + ], + entry_points={ + 'console_scripts': [ + 'pep8 = pep8:_main', + ], + }, + classifiers=[ + 'Development Status :: 5 - Production/Stable', + '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', + ], +) diff --git a/testsuite/W60.py b/testsuite/W60.py index 19b6549..ee23d61 100644 --- a/testsuite/W60.py +++ b/testsuite/W60.py @@ -3,6 +3,8 @@ if a.has_key("b"): print a #: W602 raise DummyError, "Message" +#: Okay +raise type_, val, tb #: W603 if x <> 0: x = 0 |