diff options
-rw-r--r-- | .travis.yml | 4 | ||||
-rw-r--r-- | CHANGES.txt | 12 | ||||
-rw-r--r-- | docs/conf.py | 9 | ||||
-rw-r--r-- | docs/index.rst | 2 | ||||
-rw-r--r-- | docs/intro.rst | 29 | ||||
-rwxr-xr-x | pep8.py | 10 | ||||
-rw-r--r-- | testsuite/test_all.py | 3 | ||||
-rw-r--r-- | testsuite/test_api.py | 38 | ||||
-rw-r--r-- | testsuite/test_util.py | 23 |
9 files changed, 122 insertions, 8 deletions
diff --git a/.travis.yml b/.travis.yml index c50362b..a37c115 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,3 +17,7 @@ script: matrix: allow_failures: - python: pypy + +notifications: + email: + - IanLee1521@gmail.com diff --git a/CHANGES.txt b/CHANGES.txt index 4bcfcf7..72072ca 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,12 @@ Changelog 1.x (unreleased) ---------------- +News: + +* Ian Lee <ianlee1521@gmail.com> joined the project as a maintainer. + +Bug fixes: + * Report E731 for lambda assignment. (Issue #277) * Report E704 for one-liner def instead of E701. @@ -16,6 +22,12 @@ Changelog * Report E266 instead of E265 when the block comment starts with multiple ``#``. (Issue #270) +* Strip whitespace from around paths during normalization. (Issue #339 / #343) + +* Update ``--format`` documentation. (Issue #198 / Pull Request #310) + +* Don't crash if Checker.build_tokens_line() returns None. (Issue #306) + 1.5.7 (2014-05-29) ------------------ diff --git a/docs/conf.py b/docs/conf.py index cd288cc..d1dca3c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -45,7 +45,8 @@ master_doc = 'index' # General information about the project. project = u'pep8' -copyright = u'2012-2013, Florent Xicluna' +authors = u'Johann C. Rocholl, Florent Xicluna, Ian Lee' +copyright = u'2006-2014, %s' % (authors) # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -192,7 +193,7 @@ latex_elements = { # author, documentclass [howto/manual]). latex_documents = [ ('index', 'pep8.tex', u'pep8 documentation', - u'Florent Xicluna', 'manual'), + authors, 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -222,7 +223,7 @@ latex_documents = [ # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'pep8', u'pep8 documentation', - [u'Florent Xicluna'], 1) + [authors], 1) ] # If true, show URL addresses after external links. @@ -235,7 +236,7 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'pep8', u'pep8 documentation', u'Florent Xicluna', + ('index', 'pep8', u'pep8 documentation', authors, 'pep8', 'One line description of project.', 'Miscellaneous'), ] diff --git a/docs/index.rst b/docs/index.rst index eb3f21a..5500e0d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -37,7 +37,7 @@ Credits Created by Johann C. Rocholl. -Maintained by Florent Xicluna. +Maintained by Florent Xicluna and Ian Lee. .. _license: diff --git a/docs/intro.rst b/docs/intro.rst index 5e3af1f..7d05cd8 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -111,6 +111,33 @@ Or you can display how often each error was found:: 612 W601 .has_key() is deprecated, use 'in' 1188 W602 deprecated form of raising exception +You can also make pep8.py show the error text in different formats by using --format having options default/pylint/custom:: + + $ pep8 testsuite/E40.py --format=default + testsuite/E40.py:2:10: E401 multiple imports on one line + + $ pep8 testsuite/E40.py --format=pylint + testsuite/E40.py:2: [E401] multiple imports on one line + + $ pep8 testsuite/E40.py --format='%(path)s|%(row)d|%(col)d| %(code)s %(text)s' + testsuite/E40.py|2|10| E401 multiple imports on one line + +Variables in the ``custom`` format option + ++----------------+------------------+ +| Variable | Significance | ++================+==================+ +| ``path`` | File name | ++----------------+------------------+ +| ``row`` | Row number | ++----------------+------------------+ +| ``col`` | Column number | ++----------------+------------------+ +| ``code`` | Error code | ++----------------+------------------+ +| ``text`` | Error text | ++----------------+------------------+ + Quick help is available on the command line:: $ pep8 -h @@ -158,7 +185,7 @@ Configuration The behaviour may be configured at two levels. -The user settings are read from the ``~/.config/pep8`` file and +The user settings are read from the ``~/.config/pep8`` file and for Windows from the ``~\.pep8`` file. Example:: @@ -2,6 +2,7 @@ # pep8.py - Check Python source code formatting, according to PEP 8 # Copyright (C) 2006-2009 Johann C. Rocholl <johann@rocholl.net> # Copyright (C) 2009-2014 Florent Xicluna <florent.xicluna@gmail.com> +# Copyright (C) 2014 Ian Lee <ianlee1521@gmail.com> # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation files @@ -1163,10 +1164,13 @@ def normalize_paths(value, parent=os.curdir): Return a list of absolute paths. """ - if not value or isinstance(value, list): + if not value: + return [] + if isinstance(value, list): return value paths = [] for path in value.split(','): + path = path.strip() if '/' in path: path = os.path.abspath(os.path.join(parent, path)) paths.append(path.rstrip('/')) @@ -1350,6 +1354,10 @@ class Checker(object): """Build a line from tokens and run all logical checks on it.""" self.report.increment_logical_line() mapping = self.build_tokens_line() + + if not mapping: + return + (start_row, start_col) = mapping[0][1] start_line = self.lines[start_row - 1] self.indent_level = expand_indent(start_line[:start_col]) diff --git a/testsuite/test_all.py b/testsuite/test_all.py index 5160900..50e2cb9 100644 --- a/testsuite/test_all.py +++ b/testsuite/test_all.py @@ -46,12 +46,13 @@ class Pep8TestCase(unittest.TestCase): def suite(): - from testsuite import test_api, test_shell + from testsuite import test_api, test_shell, test_util suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(Pep8TestCase)) suite.addTest(unittest.makeSuite(test_api.APITestCase)) suite.addTest(unittest.makeSuite(test_shell.ShellTestCase)) + suite.addTest(unittest.makeSuite(test_util.UtilTestCase)) return suite diff --git a/testsuite/test_api.py b/testsuite/test_api.py index 672f202..f38b101 100644 --- a/testsuite/test_api.py +++ b/testsuite/test_api.py @@ -342,5 +342,43 @@ class APITestCase(unittest.TestCase): self.assertFalse(sys.stderr) self.assertEqual(count_errors, 1) + def test_styleguide_unmatched_triple_quotes(self): + pep8.register_check(DummyChecker, ['Z701']) + lines = [ + 'def foo():\n', + ' """test docstring""\'\n', + ] + + pep8style = pep8.StyleGuide() + pep8style.input_file('stdin', lines=lines) + stdout = sys.stdout.getvalue() + + expected = 'stdin:2:5: E901 TokenError: EOF in multi-line string' + self.assertTrue(expected in stdout) + + def test_styleguide_continuation_line_outdented(self): + pep8.register_check(DummyChecker, ['Z701']) + lines = [ + 'def foo():\n', + ' pass\n', + '\n', + '\\\n', + '\n', + 'def bar():\n', + ' pass\n', + ] + + pep8style = pep8.StyleGuide() + count_errors = pep8style.input_file('stdin', lines=lines) + self.assertEqual(count_errors, 2) + stdout = sys.stdout.getvalue() + expected = ( + 'stdin:6:1: ' + 'E122 continuation line missing indentation or outdented' + ) + self.assertTrue(expected in stdout) + expected = 'stdin:6:1: E302 expected 2 blank lines, found 1' + self.assertTrue(expected in stdout) + # TODO: runner # TODO: input_file diff --git a/testsuite/test_util.py b/testsuite/test_util.py new file mode 100644 index 0000000..658d057 --- /dev/null +++ b/testsuite/test_util.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import os +import unittest + +import pep8 + + +class UtilTestCase(unittest.TestCase): + def test_normalize_paths(self): + cwd = os.getcwd() + + self.assertEquals(pep8.normalize_paths(''), []) + self.assertEquals(pep8.normalize_paths([]), []) + self.assertEquals(pep8.normalize_paths(None), []) + self.assertEquals(pep8.normalize_paths(['foo']), ['foo']) + self.assertEquals(pep8.normalize_paths('foo'), ['foo']) + self.assertEquals(pep8.normalize_paths('foo,bar'), ['foo', 'bar']) + self.assertEquals(pep8.normalize_paths('foo, bar '), ['foo', 'bar']) + self.assertEquals(pep8.normalize_paths('/foo/bar,baz/../bat'), + ['/foo/bar', cwd + '/bat']) + self.assertEquals(pep8.normalize_paths(".pyc,\n build/*"), + ['.pyc', cwd + '/build/*']) |