Skip to content

Commit 02c638c

Browse files
author
Vladimir Rudnyh
committed
Update flake8 to 2.5.2
1 parent 82a1e71 commit 02c638c

18 files changed

+1321
-96
lines changed

contrib/flake8/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.2.3'
1+
__version__ = '2.5.2'

contrib/flake8/_pyflakes.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
pass
77
else:
88
demandimport.disable()
9+
import os
10+
11+
import pep8
912
import pyflakes
1013
import pyflakes.checker
1114

@@ -39,23 +42,78 @@ class FlakesChecker(pyflakes.checker.Checker):
3942
version = pyflakes.__version__
4043

4144
def __init__(self, tree, filename):
45+
filename = pep8.normalize_paths(filename)[0]
46+
withDoctest = self.withDoctest
47+
included_by = [include for include in self.include_in_doctest
48+
if include != '' and filename.startswith(include)]
49+
if included_by:
50+
withDoctest = True
51+
52+
for exclude in self.exclude_from_doctest:
53+
if exclude != '' and filename.startswith(exclude):
54+
withDoctest = False
55+
overlaped_by = [include for include in included_by
56+
if include.startswith(exclude)]
57+
58+
if overlaped_by:
59+
withDoctest = True
60+
4261
super(FlakesChecker, self).__init__(tree, filename,
43-
withDoctest=self.withDoctest)
62+
withDoctest=withDoctest)
4463

4564
@classmethod
4665
def add_options(cls, parser):
4766
parser.add_option('--builtins',
4867
help="define more built-ins, comma separated")
4968
parser.add_option('--doctests', default=False, action='store_true',
5069
help="check syntax of the doctests")
51-
parser.config_options.extend(['builtins', 'doctests'])
70+
parser.add_option('--include-in-doctest', default='',
71+
dest='include_in_doctest',
72+
help='Run doctests only on these files',
73+
type='string')
74+
parser.add_option('--exclude-from-doctest', default='',
75+
dest='exclude_from_doctest',
76+
help='Skip these files when running doctests',
77+
type='string')
78+
parser.config_options.extend(['builtins', 'doctests',
79+
'include-in-doctest',
80+
'exclude-from-doctest'])
5281

5382
@classmethod
5483
def parse_options(cls, options):
5584
if options.builtins:
5685
cls.builtIns = cls.builtIns.union(options.builtins.split(','))
5786
cls.withDoctest = options.doctests
5887

88+
included_files = []
89+
for included_file in options.include_in_doctest.split(','):
90+
if included_file == '':
91+
continue
92+
if not included_file.startswith((os.sep, './', '~/')):
93+
included_files.append('./' + included_file)
94+
else:
95+
included_files.append(included_file)
96+
cls.include_in_doctest = pep8.normalize_paths(','.join(included_files))
97+
98+
excluded_files = []
99+
for excluded_file in options.exclude_from_doctest.split(','):
100+
if excluded_file == '':
101+
continue
102+
if not excluded_file.startswith((os.sep, './', '~/')):
103+
excluded_files.append('./' + excluded_file)
104+
else:
105+
excluded_files.append(excluded_file)
106+
cls.exclude_from_doctest = pep8.normalize_paths(
107+
','.join(excluded_files))
108+
109+
inc_exc = set(cls.include_in_doctest).intersection(
110+
set(cls.exclude_from_doctest))
111+
if inc_exc:
112+
raise ValueError('"%s" was specified in both the '
113+
'include-in-doctest and exclude-from-doctest '
114+
'options. You are not allowed to specify it in '
115+
'both for doctesting.' % inc_exc)
116+
59117
def run(self):
60118
for m in self.messages:
61119
col = getattr(m, 'col', 0)

contrib/flake8/callbacks.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import atexit
2+
import sys
3+
4+
5+
def install_vcs_hook(option, option_str, value, parser):
6+
# For now, there's no way to affect a change in how pep8 processes
7+
# options. If no args are provided and there's no config file present,
8+
# it will error out because no input was provided. To get around this,
9+
# when we're using --install-hook, we'll say that there were arguments so
10+
# we can actually attempt to install the hook.
11+
# See: https://gitlab.com/pycqa/flake8/issues/2 and
12+
# https://github.com/jcrocholl/pep8/blob/4c5bf00cb613be617c7f48d3b2b82a1c7b895ac1/pep8.py#L1912
13+
# for more context.
14+
parser.values.install_hook = True
15+
parser.rargs.append('.')
16+
17+
18+
def restore_stdout(old_stdout):
19+
sys.stdout.close()
20+
sys.stdout = old_stdout
21+
22+
23+
def redirect_stdout(option, option_str, value, parser):
24+
fd = open(value, 'w')
25+
old_stdout, sys.stdout = sys.stdout, fd
26+
27+
atexit.register(restore_stdout, old_stdout)

contrib/flake8/compat.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
"""Compatibility shims for Flake8."""
3+
import os.path
4+
import sys
5+
6+
7+
def relpath(path, start='.'):
8+
"""Wallpaper over the differences between 2.6 and newer versions."""
9+
if sys.version_info < (2, 7) and path.startswith(start):
10+
return path[len(start):]
11+
else:
12+
return os.path.relpath(path, start=start)

0 commit comments

Comments
 (0)