Disable multiprocessing when using stdin

Fixes #165
This commit is contained in:
Ian Cordasco 2014-09-12 22:36:37 -05:00
parent 79c80c3181
commit e6cb9528d3
3 changed files with 23 additions and 4 deletions

View file

@ -6,7 +6,7 @@ import pep8
from flake8 import __version__
from flake8.reporter import multiprocessing, BaseQReport, QueueReport
from flake8.util import OrderedSet, is_windows
from flake8.util import OrderedSet, is_windows, is_using_stdin
_flake8_noqa = re.compile(r'flake8[:=]\s*noqa', re.I).search
@ -57,7 +57,7 @@ def get_parser():
parser.config_options.append('jobs')
parser.add_option('-j', '--jobs', type='string', default='auto',
help="number of jobs to run simultaneously, "
"or 'auto'")
"or 'auto'. This is ignored on Windows.")
parser.add_option('--exit-zero', action='store_true',
help="exit with code 0 even if there are errors")
@ -95,7 +95,9 @@ def get_style_guide(**kwargs):
if options.diff:
options.jobs = None
if multiprocessing and options.jobs and not is_windows():
force_disable_jobs = is_windows() or is_using_stdin(styleguide.paths)
if multiprocessing and options.jobs and not force_disable_jobs:
if options.jobs.isdigit():
n_jobs = int(options.jobs)
else:

View file

@ -6,7 +6,7 @@ try:
except ImportError:
import mock # < PY33
from flake8 import engine, util, __version__
from flake8 import engine, util, __version__, reporter
class TestEngine(unittest.TestCase):
@ -82,5 +82,17 @@ class TestEngine(unittest.TestCase):
# Also we can never be sure (without reconstructing the string
# ourselves) what system we may be testing on.
def test_windows_disables_jobs(self):
with mock.patch('flake8.engine.is_windows') as is_windows:
is_windows.return_value = True
guide = engine.get_style_guide()
assert isinstance(guide, reporter.BaseQReport) is False
def test_stdin_disables_jobs(self):
with mock.patch('flake8.engine.is_using_stdin') as is_using_stdin:
is_using_stdin.return_value = True
guide = engine.get_style_guide()
assert isinstance(guide, reporter.BaseQReport) is False
if __name__ == '__main__':
unittest.main()

View file

@ -49,6 +49,11 @@ def is_windows():
return os.name == 'nt'
def is_using_stdin(paths):
"""Determine if we're running checks on stdin."""
return '-' in paths
def flag_on(val):
"""Return true if flag is on"""
return str(val).upper() in ('1', 'T', 'TRUE', 'ON')