Browse Source

Implement pep8 check

Excludes E203 whitespace before ':' for now.

TODO: look into pep8 for why `# nopep8` does not work here
Matthew Wang 8 years ago
parent
commit
1a433ff5d7
4 changed files with 47 additions and 46 deletions
  1. 6
    3
      Makefile
  2. 24
    24
      cdiff.py
  3. 13
    13
      setup.py
  4. 4
    6
      tests/test_cdiff.py

+ 6
- 3
Makefile View File

@@ -3,13 +3,16 @@
3 3
 TESTPYPI = pypitest
4 4
 PYPI = pypi
5 5
 
6
-.PHONY: dogfood doc-check doc-preview clean build dist-test dist \
6
+.PHONY: dogfood lint doc-check doc-preview clean build dist-test dist \
7 7
 	test test3 cov cov3 html reg reg3 profile profile3
8 8
 
9 9
 dogfood:
10 10
 	./cdiff.py
11 11
 	git diff | ./cdiff.py -s
12 12
 
13
+lint:
14
+	pep8 --ignore=E203 *.py tests/*.py
15
+
13 16
 doc-check:
14 17
 	./setup.py --long-description | rst2html.py --strict > /dev/null
15 18
 
@@ -19,9 +22,9 @@ doc-preview:
19 22
 	sleep 1
20 23
 	rm -f output.html
21 24
 
22
-test: doc-check cov reg
25
+test: lint doc-check cov reg
23 26
 
24
-test3: doc-check cov3 reg3
27
+test3: lint doc-check cov3 reg3
25 28
 
26 29
 cov:
27 30
 	coverage run tests/test_cdiff.py

+ 24
- 24
cdiff.py View File

@@ -7,6 +7,14 @@ workspace or from stdin, with *side by side* and *auto pager* support. Requires
7 7
 python (>= 2.5.0) and ``less``.
8 8
 """
9 9
 
10
+import sys
11
+import os
12
+import re
13
+import signal
14
+import subprocess
15
+import select
16
+import difflib
17
+
10 18
 META_INFO = {
11 19
     'version'     : '0.9.8',
12 20
     'license'     : 'BSD-3',
@@ -18,8 +26,6 @@ META_INFO = {
18 26
                      'stdin, with side by side and auto pager support')
19 27
 }
20 28
 
21
-import sys
22
-
23 29
 if sys.hexversion < 0x02050000:
24 30
     raise SystemExit("*** Requires python >= 2.5.0")    # pragma: no cover
25 31
 
@@ -27,22 +33,14 @@ if sys.hexversion < 0x02050000:
27 33
 try:
28 34
     next
29 35
 except NameError:
30
-    def next(obj): return obj.next()
31
-
32
-import os
33
-import re
34
-import signal
35
-import subprocess
36
-import select
37
-import difflib
38
-
36
+    def next(obj):
37
+        return obj.next()
39 38
 
40 39
 try:
41 40
     unicode
42 41
 except NameError:
43 42
     unicode = str
44 43
 
45
-
46 44
 COLORS = {
47 45
     'reset'         : '\x1b[0m',
48 46
     'underline'     : '\x1b[4m',
@@ -65,19 +63,19 @@ COLORS = {
65 63
 # Keys for revision control probe, diff and log with diff
66 64
 VCS_INFO = {
67 65
     'Git': {
68
-        'probe' : ['git', 'rev-parse'],
69
-        'diff'  : ['git', 'diff', '--no-ext-diff'],
70
-        'log'   : ['git', 'log', '--patch'],
66
+        'probe': ['git', 'rev-parse'],
67
+        'diff': ['git', 'diff', '--no-ext-diff'],
68
+        'log': ['git', 'log', '--patch'],
71 69
     },
72 70
     'Mercurial': {
73
-        'probe' : ['hg', 'summary'],
74
-        'diff'  : ['hg', 'diff'],
75
-        'log'   : ['hg', 'log', '--patch'],
71
+        'probe': ['hg', 'summary'],
72
+        'diff': ['hg', 'diff'],
73
+        'log': ['hg', 'log', '--patch'],
76 74
     },
77 75
     'Svn': {
78
-        'probe' : ['svn', 'info'],
79
-        'diff'  : ['svn', 'diff'],
80
-        'log'   : ['svn', 'log', '--diff', '--use-merge-history'],
76
+        'probe': ['svn', 'info'],
77
+        'diff': ['svn', 'diff'],
78
+        'log': ['svn', 'log', '--diff', '--use-merge-history'],
81 79
     },
82 80
 }
83 81
 
@@ -304,8 +302,8 @@ class DiffParser(object):
304 302
             return
305 303
 
306 304
         for n in range(size):
307
-            if header[n].startswith('--- ') and (n < size - 1) and \
308
-                    header[n+1].startswith('+++ '):
305
+            if (header[n].startswith('--- ') and (n < size - 1) and
306
+                    header[n + 1].startswith('+++ ')):
309 307
                 self._type = 'unified'
310 308
                 self._stream = stream
311 309
                 break
@@ -698,7 +696,9 @@ def terminal_size():
698 696
     """
699 697
     width, height = None, None
700 698
     try:
701
-        import struct, fcntl, termios
699
+        import struct
700
+        import fcntl
701
+        import termios
702 702
         s = struct.pack('HHHH', 0, 0, 0, 0)
703 703
         x = fcntl.ioctl(1, termios.TIOCGWINSZ, s)
704 704
         height, width = struct.unpack('HHHH', x)[0:2]

+ 13
- 13
setup.py View File

@@ -2,10 +2,10 @@
2 2
 # -*- coding: utf-8 -*-
3 3
 
4 4
 from __future__ import with_statement
5
+import sys
5 6
 from distutils.core import setup
6 7
 from cdiff import META_INFO as _meta
7 8
 
8
-import sys
9 9
 if sys.hexversion < 0x02050000:
10 10
     raise SystemExit("*** Requires python >= 2.5.0")
11 11
 
@@ -15,17 +15,17 @@ with open('CHANGES.rst') as changes:
15 15
     long_description += changes.read()
16 16
 
17 17
 setup(
18
-    name = 'cdiff',
19
-    version = _meta['version'],
20
-    author = _meta['author'],
21
-    author_email = _meta['email'],
22
-    license = _meta['license'],
23
-    description = _meta['description'],
24
-    long_description = long_description,
25
-    keywords = _meta['keywords'],
26
-    url = _meta['url'],
18
+    name='cdiff',
19
+    version=_meta['version'],
20
+    author=_meta['author'],
21
+    author_email=_meta['email'],
22
+    license=_meta['license'],
23
+    description=_meta['description'],
24
+    long_description=long_description,
25
+    keywords=_meta['keywords'],
26
+    url=_meta['url'],
27 27
     # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
28
-    classifiers = [
28
+    classifiers=[
29 29
         'Development Status :: 5 - Production/Stable',
30 30
         'Topic :: Utilities',
31 31
         'License :: OSI Approved :: BSD License',
@@ -38,8 +38,8 @@ setup(
38 38
         'Programming Language :: Python :: 2',
39 39
         'Programming Language :: Python :: 3',
40 40
     ],
41
-    py_modules = ['cdiff'],
42
-    scripts = ['cdiff'],
41
+    py_modules=['cdiff'],
42
+    scripts=['cdiff'],
43 43
 )
44 44
 
45 45
 # vim:set et sts=4 sw=4 tw=79:

+ 4
- 6
tests/test_cdiff.py View File

@@ -4,16 +4,13 @@
4 4
 """Unit test for cdiff"""
5 5
 
6 6
 import sys
7
-if sys.hexversion < 0x02050000:
8
-    raise SystemExit("*** Requires python >= 2.5.0")    # pragma: no cover
9
-
10 7
 import unittest
11 8
 import tempfile
12 9
 import subprocess
13 10
 import os
14 11
 
15 12
 sys.path.insert(0, '')
16
-import cdiff
13
+import cdiff  # nopep8
17 14
 
18 15
 
19 16
 class Sequential(object):
@@ -130,7 +127,8 @@ class DiffMarkupTest(unittest.TestCase):
130 127
         hunk.append(('-', 'garb\n'))
131 128
         hunk.append(('-', 'Again\n'))
132 129
         hunk.append(('+', 'again\n'))
133
-        diff = cdiff.UnifiedDiff(['header\n'], '--- old\n', '+++ new\n', [hunk])
130
+        diff = cdiff.UnifiedDiff(
131
+            ['header\n'], '--- old\n', '+++ new\n', [hunk])
134 132
         return diff
135 133
 
136 134
     def test_markup_mix(self):
@@ -363,7 +361,7 @@ class DiffMarkupTest(unittest.TestCase):
363 361
         self.assertEqual(
364 362
             out[5],
365 363
             '\x1b[33m1\x1b[0m '
366
-            '\x1b[31m\x1b[7m\x1b[31mh\x1b[0m\x1b[31mhel\x1b[0m\x1b[1;35m>\x1b[0m '
364
+            '\x1b[31m\x1b[7m\x1b[31mh\x1b[0m\x1b[31mhel\x1b[0m\x1b[1;35m>\x1b[0m '  # nopep8
367 365
             '\x1b[0m\x1b[33m1\x1b[0m '
368 366
             '\x1b[32mhell\x1b[0m\x1b[1;35m>\x1b[0m\n')
369 367
         self.assertEqual(