Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
Conflicts:
	pep8.py
	setup.py
  • Loading branch information
Chris Angove committed Apr 16, 2012
2 parents 63aa278 + 3df8635 commit f214446
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 72 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
pep8.egg-info
*.pyc
42 changes: 42 additions & 0 deletions CHANGES.txt
Expand Up @@ -17,6 +17,48 @@ Changelog
method. ~ Aditya Bhargava


1.0.1 (2012-04-06)
------------------

* Fix inconsistent version numbers.


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)
------------------

Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -1,3 +1,4 @@
recursive-include testsuite *
include pep8.py
include *.txt
include *.rst
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -17,17 +17,20 @@ 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
python2.6 pep8.py --doctest
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
python2.6 pep8.py --repeat --statistics pep8.py
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
4 changes: 3 additions & 1 deletion README.rst
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 0 additions & 8 deletions TODO.txt
@@ -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.
72 changes: 37 additions & 35 deletions pep8.py
@@ -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>
#
Expand Down Expand Up @@ -92,7 +92,7 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number)
"""

__version__ = '0.6.2'
__version__ = '1.0.1'

import os
import sys
Expand All @@ -116,6 +116,7 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number)

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?["\']')
Expand All @@ -126,6 +127,7 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number)
re.compile(r'[()]|\s=[^=]|[^=!<>]=\s')
WHITESPACE_AROUND_COMMA_REGEX = \
re.compile(r'[,;:](\t|\s\s+)\S')
LAMBDA_REGEX = re.compile(r'\blambda\b')


WHITESPACE = ' \t'
Expand Down Expand Up @@ -287,16 +289,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


##############################################################################
Expand Down Expand Up @@ -937,8 +940,8 @@ 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
yield found, "E701 multiple statements on one line (colon)"
not LAMBDA_REGEX.search(before)): # lambda x: x
return found, "E701 multiple statements on one line (colon)"
found = line.find(';')
if -1 < found:
yield found, "E702 multiple statements on one line (semicolon)"
Expand Down Expand Up @@ -968,8 +971,8 @@ def python_3000_raise_comma(logical_line):
form will be removed in Python 3000.
"""
match = RAISE_COMMA_REGEX.match(logical_line)
if match:
yield match.start(1), "W602 deprecated form of raising exception"
if match and not RERAISE_COMMA_REGEX.match(logical_line):
return match.start(1), "W602 deprecated form of raising exception"


def python_3000_not_equal(logical_line):
Expand Down Expand Up @@ -1062,13 +1065,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
##############################################################################
Expand Down Expand Up @@ -1311,7 +1307,7 @@ def report_error(self, line_number, offset, text, check):
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:
Expand All @@ -1322,24 +1318,24 @@ def report_error(self, line_number, offset, text, check):
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):
"""
Run all checks on a Python source file.
"""
if options.verbose:
message('checking ' + filename)
return Checker(filename).check_all()
print('checking ' + filename)
errors = Checker(filename).check_all()


def input_dir(dirname, runner=None):
Expand All @@ -1353,10 +1349,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()
Expand Down Expand Up @@ -1461,8 +1457,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):
Expand Down Expand Up @@ -1502,9 +1498,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
Expand Down Expand Up @@ -1609,8 +1605,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)" %
Expand All @@ -1637,6 +1635,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")
parser.add_option('-f', '--fix', action='count',
Expand Down Expand Up @@ -1665,7 +1667,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:
Expand Down
84 changes: 56 additions & 28 deletions setup.py
@@ -1,31 +1,59 @@
from setuptools import setup, find_packages

version = '0.6.2'
long_description = '\n\n'.join([open('README.rst').read(),
open('CHANGES.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',
],
},
)
def get_version():
f = open('pep8.py')
try:
for line in f:
if line.startswith('__version__'):
return eval(line.split('=')[-1])
finally:
f.close()


def get_long_description():
descr = []
for fname in 'README.rst', 'CHANGES.txt': # , 'TODO.txt'
f = open(fname)
try:
descr.append(f.read())
finally:
f.close()
return '\n\n'.join(descr)


setup(
name='pep8',
version=get_version(),
description="Python style guide checker",
long_description=get_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',
],
)

0 comments on commit f214446

Please sign in to comment.