summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/flake8/checker.py8
-rw-r--r--src/flake8/exceptions.py6
-rw-r--r--src/flake8/utils.py18
-rw-r--r--tox.ini2
4 files changed, 27 insertions, 7 deletions
diff --git a/src/flake8/checker.py b/src/flake8/checker.py
index b875f44..06c4676 100644
--- a/src/flake8/checker.py
+++ b/src/flake8/checker.py
@@ -253,6 +253,10 @@ class Manager(object):
"""Create checkers for each file."""
if paths is None:
paths = self.arguments
+
+ if not paths:
+ paths = ['.']
+
filename_patterns = self.options.filename
# NOTE(sigmavirus24): Yes this is a little unsightly, but it's our
@@ -273,6 +277,7 @@ class Manager(object):
self.is_path_excluded)
if should_create_file_checker(filename)
]
+ LOG.info('Checking %d files', len(self.checkers))
def report(self):
# type: () -> (int, int)
@@ -340,6 +345,9 @@ class Manager(object):
raise
LOG.warning('Running in serial after OS exception, %r', oserr)
self.run_serial()
+ except KeyboardInterrupt:
+ LOG.warning('Flake8 was interrupted by the user')
+ raise exceptions.EarlyQuit('Early quit while running checks')
def start(self, paths=None):
"""Start checking files.
diff --git a/src/flake8/exceptions.py b/src/flake8/exceptions.py
index 5ff55a2..2b03795 100644
--- a/src/flake8/exceptions.py
+++ b/src/flake8/exceptions.py
@@ -7,6 +7,12 @@ class Flake8Exception(Exception):
pass
+class EarlyQuit(Flake8Exception):
+ """Except raised when encountering a KeyboardInterrupt."""
+
+ pass
+
+
class FailedToLoadPlugin(Flake8Exception):
"""Exception raised when a plugin fails to load."""
diff --git a/src/flake8/utils.py b/src/flake8/utils.py
index 597dea6..9f1189c 100644
--- a/src/flake8/utils.py
+++ b/src/flake8/utils.py
@@ -209,16 +209,22 @@ def filenames_from(arg, predicate=None):
predicate = _default_predicate
if os.path.isdir(arg):
for root, sub_directories, files in os.walk(arg):
- for filename in files:
- joined = os.path.join(root, filename)
- if predicate(joined):
- continue
- yield joined
+ if predicate(root):
+ sub_directories[:] = []
+ continue
+
# NOTE(sigmavirus24): os.walk() will skip a directory if you
# remove it from the list of sub-directories.
for directory in sub_directories:
- if predicate(directory):
+ joined = os.path.join(root, directory)
+ if predicate(directory) or predicate(joined):
sub_directories.remove(directory)
+
+ for filename in files:
+ joined = os.path.join(root, filename)
+ if predicate(joined) or predicate(filename):
+ continue
+ yield joined
else:
yield arg
diff --git a/tox.ini b/tox.ini
index aa3dc33..3e387b4 100644
--- a/tox.ini
+++ b/tox.ini
@@ -132,7 +132,7 @@ ignore = D203
# NOTE(sigmavirus24): Once we release 3.0.0 this exclude option can be specified
# across multiple lines. Presently it cannot be specified across multiple lines.
# :-(
-exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,tests/fixtures/
+exclude = .tox,.git,__pycache__,docs/source/conf.py,build,dist,tests/fixtures/*,*.pyc
max-complexity = 10
import-order-style = google
application-import-names = flake8