mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-12 23:54:17 +00:00
parent
79c80c3181
commit
e6cb9528d3
3 changed files with 23 additions and 4 deletions
|
|
@ -6,7 +6,7 @@ import pep8
|
||||||
|
|
||||||
from flake8 import __version__
|
from flake8 import __version__
|
||||||
from flake8.reporter import multiprocessing, BaseQReport, QueueReport
|
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
|
_flake8_noqa = re.compile(r'flake8[:=]\s*noqa', re.I).search
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ def get_parser():
|
||||||
parser.config_options.append('jobs')
|
parser.config_options.append('jobs')
|
||||||
parser.add_option('-j', '--jobs', type='string', default='auto',
|
parser.add_option('-j', '--jobs', type='string', default='auto',
|
||||||
help="number of jobs to run simultaneously, "
|
help="number of jobs to run simultaneously, "
|
||||||
"or 'auto'")
|
"or 'auto'. This is ignored on Windows.")
|
||||||
|
|
||||||
parser.add_option('--exit-zero', action='store_true',
|
parser.add_option('--exit-zero', action='store_true',
|
||||||
help="exit with code 0 even if there are errors")
|
help="exit with code 0 even if there are errors")
|
||||||
|
|
@ -95,7 +95,9 @@ def get_style_guide(**kwargs):
|
||||||
if options.diff:
|
if options.diff:
|
||||||
options.jobs = None
|
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():
|
if options.jobs.isdigit():
|
||||||
n_jobs = int(options.jobs)
|
n_jobs = int(options.jobs)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import mock # < PY33
|
import mock # < PY33
|
||||||
|
|
||||||
from flake8 import engine, util, __version__
|
from flake8 import engine, util, __version__, reporter
|
||||||
|
|
||||||
|
|
||||||
class TestEngine(unittest.TestCase):
|
class TestEngine(unittest.TestCase):
|
||||||
|
|
@ -82,5 +82,17 @@ class TestEngine(unittest.TestCase):
|
||||||
# Also we can never be sure (without reconstructing the string
|
# Also we can never be sure (without reconstructing the string
|
||||||
# ourselves) what system we may be testing on.
|
# 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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,11 @@ def is_windows():
|
||||||
return os.name == 'nt'
|
return os.name == 'nt'
|
||||||
|
|
||||||
|
|
||||||
|
def is_using_stdin(paths):
|
||||||
|
"""Determine if we're running checks on stdin."""
|
||||||
|
return '-' in paths
|
||||||
|
|
||||||
|
|
||||||
def flag_on(val):
|
def flag_on(val):
|
||||||
"""Return true if flag is on"""
|
"""Return true if flag is on"""
|
||||||
return str(val).upper() in ('1', 'T', 'TRUE', 'ON')
|
return str(val).upper() in ('1', 'T', 'TRUE', 'ON')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue