diff --git a/flake8/engine.py b/flake8/engine.py index bba2cea..8676cb2 100644 --- a/flake8/engine.py +++ b/flake8/engine.py @@ -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: diff --git a/flake8/tests/test_engine.py b/flake8/tests/test_engine.py index c8dce7f..27eefc2 100644 --- a/flake8/tests/test_engine.py +++ b/flake8/tests/test_engine.py @@ -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() diff --git a/flake8/util.py b/flake8/util.py index 5ace309..5a954f8 100644 --- a/flake8/util.py +++ b/flake8/util.py @@ -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')