Search current directory if no paths are specified

This fixes a regression in behaviour from 2.x to 3.

Closes #150
This commit is contained in:
Ian Cordasco 2016-06-26 15:08:58 -05:00
parent 790549fd25
commit b194717d1a
No known key found for this signature in database
GPG key ID: 656D3395E4A9791A
4 changed files with 27 additions and 7 deletions

View file

@ -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.

View file

@ -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."""

View file

@ -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

View file

@ -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