Przeglądaj źródła

Merge branch 'pep8'

Implement pep8 check.  Excludes `E203 whitespace before ':'` for now.
Matthew Wang 8 lat temu
rodzic
commit
fc5341a10b
7 zmienionych plików z 54 dodań i 52 usunięć
  1. 1
    0
      .gitignore
  2. 2
    6
      .travis.yml
  3. 6
    3
      Makefile
  4. 24
    24
      cdiff.py
  5. 4
    0
      requirements.txt
  6. 13
    13
      setup.py
  7. 4
    6
      tests/test_cdiff.py

+ 1
- 0
.gitignore Wyświetl plik

2
 *.pyc
2
 *.pyc
3
 *~
3
 *~
4
 *.tmp
4
 *.tmp
5
+/envs/
5
 /.coverage
6
 /.coverage
6
 /.travis-solo/
7
 /.travis-solo/
7
 /htmlcov/
8
 /htmlcov/

+ 2
- 6
.travis.yml Wyświetl plik

8
   - "3.4"
8
   - "3.4"
9
   - "pypy"
9
   - "pypy"
10
 
10
 
11
-before_install:
12
-  - pip --quiet install docutils
13
-  - pip --quiet install Pygments==1.6
14
-  - pip --quiet install "coverage<4"
11
+install:
12
+  - pip install -r requirements.txt
15
   - coverage --version
13
   - coverage --version
16
   - sudo apt-get update
14
   - sudo apt-get update
17
   - sudo apt-get --quiet=2 install patchutils
15
   - sudo apt-get --quiet=2 install patchutils
18
-
19
-install:
20
   - python setup.py --quiet install
16
   - python setup.py --quiet install
21
 
17
 
22
 script:
18
 script:

+ 6
- 3
Makefile Wyświetl plik

3
 TESTPYPI = pypitest
3
 TESTPYPI = pypitest
4
 PYPI = pypi
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
 	test test3 cov cov3 html reg reg3 profile profile3
7
 	test test3 cov cov3 html reg reg3 profile profile3
8
 
8
 
9
 dogfood:
9
 dogfood:
10
 	./cdiff.py
10
 	./cdiff.py
11
 	git diff | ./cdiff.py -s
11
 	git diff | ./cdiff.py -s
12
 
12
 
13
+lint:
14
+	pep8 --ignore=E203 *.py tests/*.py
15
+
13
 doc-check:
16
 doc-check:
14
 	./setup.py --long-description | rst2html.py --strict > /dev/null
17
 	./setup.py --long-description | rst2html.py --strict > /dev/null
15
 
18
 
19
 	sleep 1
22
 	sleep 1
20
 	rm -f output.html
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
 cov:
29
 cov:
27
 	coverage run tests/test_cdiff.py
30
 	coverage run tests/test_cdiff.py

+ 24
- 24
cdiff.py Wyświetl plik

7
 python (>= 2.5.0) and ``less``.
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
 META_INFO = {
18
 META_INFO = {
11
     'version'     : '0.9.8',
19
     'version'     : '0.9.8',
12
     'license'     : 'BSD-3',
20
     'license'     : 'BSD-3',
18
                      'stdin, with side by side and auto pager support')
26
                      'stdin, with side by side and auto pager support')
19
 }
27
 }
20
 
28
 
21
-import sys
22
-
23
 if sys.hexversion < 0x02050000:
29
 if sys.hexversion < 0x02050000:
24
     raise SystemExit("*** Requires python >= 2.5.0")    # pragma: no cover
30
     raise SystemExit("*** Requires python >= 2.5.0")    # pragma: no cover
25
 
31
 
27
 try:
33
 try:
28
     next
34
     next
29
 except NameError:
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
 try:
39
 try:
41
     unicode
40
     unicode
42
 except NameError:
41
 except NameError:
43
     unicode = str
42
     unicode = str
44
 
43
 
45
-
46
 COLORS = {
44
 COLORS = {
47
     'reset'         : '\x1b[0m',
45
     'reset'         : '\x1b[0m',
48
     'underline'     : '\x1b[4m',
46
     'underline'     : '\x1b[4m',
65
 # Keys for revision control probe, diff and log with diff
63
 # Keys for revision control probe, diff and log with diff
66
 VCS_INFO = {
64
 VCS_INFO = {
67
     'Git': {
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
     'Mercurial': {
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
     'Svn': {
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
             return
302
             return
305
 
303
 
306
         for n in range(size):
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
                 self._type = 'unified'
307
                 self._type = 'unified'
310
                 self._stream = stream
308
                 self._stream = stream
311
                 break
309
                 break
698
     """
696
     """
699
     width, height = None, None
697
     width, height = None, None
700
     try:
698
     try:
701
-        import struct, fcntl, termios
699
+        import struct
700
+        import fcntl
701
+        import termios
702
         s = struct.pack('HHHH', 0, 0, 0, 0)
702
         s = struct.pack('HHHH', 0, 0, 0, 0)
703
         x = fcntl.ioctl(1, termios.TIOCGWINSZ, s)
703
         x = fcntl.ioctl(1, termios.TIOCGWINSZ, s)
704
         height, width = struct.unpack('HHHH', x)[0:2]
704
         height, width = struct.unpack('HHHH', x)[0:2]

+ 4
- 0
requirements.txt Wyświetl plik

1
+docutils
2
+pep8
3
+Pygments==1.6
4
+coverage<4

+ 13
- 13
setup.py Wyświetl plik

2
 # -*- coding: utf-8 -*-
2
 # -*- coding: utf-8 -*-
3
 
3
 
4
 from __future__ import with_statement
4
 from __future__ import with_statement
5
+import sys
5
 from distutils.core import setup
6
 from distutils.core import setup
6
 from cdiff import META_INFO as _meta
7
 from cdiff import META_INFO as _meta
7
 
8
 
8
-import sys
9
 if sys.hexversion < 0x02050000:
9
 if sys.hexversion < 0x02050000:
10
     raise SystemExit("*** Requires python >= 2.5.0")
10
     raise SystemExit("*** Requires python >= 2.5.0")
11
 
11
 
15
     long_description += changes.read()
15
     long_description += changes.read()
16
 
16
 
17
 setup(
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
     # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
27
     # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
28
-    classifiers = [
28
+    classifiers=[
29
         'Development Status :: 5 - Production/Stable',
29
         'Development Status :: 5 - Production/Stable',
30
         'Topic :: Utilities',
30
         'Topic :: Utilities',
31
         'License :: OSI Approved :: BSD License',
31
         'License :: OSI Approved :: BSD License',
38
         'Programming Language :: Python :: 2',
38
         'Programming Language :: Python :: 2',
39
         'Programming Language :: Python :: 3',
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
 # vim:set et sts=4 sw=4 tw=79:
45
 # vim:set et sts=4 sw=4 tw=79:

+ 4
- 6
tests/test_cdiff.py Wyświetl plik

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