summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-06-26 15:08:58 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2016-06-26 15:08:58 -0500
commitb194717d1a35862961efed0f4411d774024ec75d (patch)
tree339573b4af0cb84219869756ca5e4bb22cb227ea /src
parent790549fd25eb50ceed852ce3436e3afc111bbf37 (diff)
downloadflake8-b194717d1a35862961efed0f4411d774024ec75d.tar.gz
Search current directory if no paths are specified
This fixes a regression in behaviour from 2.x to 3. Closes #150
Diffstat (limited to 'src')
-rw-r--r--src/flake8/checker.py8
-rw-r--r--src/flake8/exceptions.py6
-rw-r--r--src/flake8/utils.py18
3 files changed, 26 insertions, 6 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