summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-07-20 19:29:32 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2016-07-20 19:29:32 -0500
commit1dad1e3a959df918a0cfbad66d9c11e9df5f06b9 (patch)
treef95ce2e638dc3bf722cd4c6a615dda8d29e66c58 /src
parent9f2eac7df13b3a37123fa80d93a8ab38e1c24e20 (diff)
parenta1fdb5a2b5934ef5629df2335b2d495ba5252812 (diff)
downloadflake8-1dad1e3a959df918a0cfbad66d9c11e9df5f06b9.tar.gz
Merge branch 'pr/78'
Closes #78
Diffstat (limited to 'src')
-rw-r--r--src/flake8/checker.py29
-rw-r--r--src/flake8/processor.py10
-rw-r--r--src/flake8/style_guide.py2
-rw-r--r--src/flake8/utils.py4
4 files changed, 27 insertions, 18 deletions
diff --git a/src/flake8/checker.py b/src/flake8/checker.py
index f7bd540..ba412e3 100644
--- a/src/flake8/checker.py
+++ b/src/flake8/checker.py
@@ -234,6 +234,11 @@ class Manager(object):
:rtype:
bool
"""
+ if path == '-':
+ if self.options.stdin_display_name == 'stdin':
+ return False
+ path = self.options.stdin_display_name
+
exclude = self.options.exclude
if not exclude:
return False
@@ -271,7 +276,7 @@ class Manager(object):
return (file_exists and matches_filename_patterns) or is_stdin
self.checkers = [
- FileChecker(filename, self.checks, self.style_guide)
+ FileChecker(filename, self.checks, self.options)
for argument in paths
for filename in utils.filenames_from(argument,
self.is_path_excluded)
@@ -294,7 +299,7 @@ class Manager(object):
results_reported = results_found = 0
for checker in self.checkers:
results = sorted(checker.results, key=lambda tup: (tup[2], tup[3]))
- results_reported += self._handle_results(checker.filename,
+ results_reported += self._handle_results(checker.display_name,
results)
results_found += len(results)
return (results_found, results_reported)
@@ -315,9 +320,9 @@ class Manager(object):
final_results[filename] = results
for checker in self.checkers:
- filename = checker.filename
+ filename = checker.display_name
checker.results = sorted(final_results.get(filename, []),
- key=lambda tup: (tup[1], tup[2]))
+ key=lambda tup: (tup[2], tup[2]))
def run_serial(self):
"""Run the checkers in serial."""
@@ -379,7 +384,7 @@ class Manager(object):
class FileChecker(object):
"""Manage running checks for a file and aggregate the results."""
- def __init__(self, filename, checks, style_guide):
+ def __init__(self, filename, checks, options):
"""Initialize our file checker.
:param str filename:
@@ -388,16 +393,17 @@ class FileChecker(object):
The plugins registered to check the file.
:type checks:
flake8.plugins.manager.Checkers
- :param style_guide:
- The initialized StyleGuide for this particular run.
- :type style_guide:
- flake8.style_guide.StyleGuide
+ :param options:
+ Parsed option values from config and command-line.
+ :type options:
+ optparse.Values
"""
+ self.options = options
self.filename = filename
self.checks = checks
- self.style_guide = style_guide
self.results = []
self.processor = self._make_processor()
+ self.display_name = self.processor.filename
self.statistics = {
'tokens': 0,
'logical lines': 0,
@@ -406,8 +412,7 @@ class FileChecker(object):
def _make_processor(self):
try:
- return processor.FileProcessor(self.filename,
- self.style_guide.options)
+ return processor.FileProcessor(self.filename, self.options)
except IOError:
# If we can not read the file due to an IOError (e.g., the file
# does not exist or we do not have the permissions to open it)
diff --git a/src/flake8/processor.py b/src/flake8/processor.py
index 76c5512..3e7dba5 100644
--- a/src/flake8/processor.py
+++ b/src/flake8/processor.py
@@ -55,12 +55,12 @@ class FileProcessor(object):
:param str filename:
Name of the file to process
"""
+ self.options = options
self.filename = filename
self.lines = lines
if lines is None:
self.lines = self.read_lines()
self.strip_utf_bom()
- self.options = options
# Defaults for public attributes
#: Number of preceding blank lines
@@ -272,9 +272,11 @@ class FileProcessor(object):
# type: () -> List[str]
"""Read the lines for this file checker."""
if self.filename is None or self.filename == '-':
- self.filename = 'stdin'
- return self.read_lines_from_stdin()
- return self.read_lines_from_filename()
+ self.filename = self.options.stdin_display_name
+ lines = self.read_lines_from_stdin()
+ else:
+ lines = self.read_lines_from_filename()
+ return lines
def _readlines_py2(self):
# type: () -> List[str]
diff --git a/src/flake8/style_guide.py b/src/flake8/style_guide.py
index ed1b844..284444d 100644
--- a/src/flake8/style_guide.py
+++ b/src/flake8/style_guide.py
@@ -260,8 +260,6 @@ class StyleGuide(object):
"""
error = Error(code, filename, line_number, column_number, text,
physical_line)
- if error.filename is None or error.filename == '-':
- error = error._replace(filename=self.options.stdin_display_name)
error_is_selected = (self.should_report_error(error.code) is
Decision.Selected)
is_not_inline_ignored = self.is_inline_ignored(error) is False
diff --git a/src/flake8/utils.py b/src/flake8/utils.py
index 68ed530..7f31f8f 100644
--- a/src/flake8/utils.py
+++ b/src/flake8/utils.py
@@ -208,6 +208,10 @@ def filenames_from(arg, predicate=None):
"""
if predicate is None:
predicate = _default_predicate
+
+ if predicate(arg):
+ return
+
if os.path.isdir(arg):
for root, sub_directories, files in os.walk(arg):
if predicate(root):