mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-01 19:36:54 +00:00
Merge Florent's multiprocessing work over Joe's
This commit is contained in:
commit
a0e3f364b1
2 changed files with 18 additions and 8 deletions
|
|
@ -55,8 +55,9 @@ def get_parser():
|
|||
except NotImplementedError:
|
||||
auto = 1
|
||||
parser.config_options.append('jobs')
|
||||
parser.add_option('-j', '--jobs', type='int', default=auto,
|
||||
help="number of jobs to run simultaneously")
|
||||
parser.add_option('-j', '--jobs', type='string', default='',
|
||||
help="number of jobs to run simultaneously, "
|
||||
"or 'auto'")
|
||||
|
||||
parser.add_option('--exit-zero', action='store_true',
|
||||
help="exit with code 0 even if there are errors")
|
||||
|
|
@ -91,11 +92,20 @@ def get_style_guide(**kwargs):
|
|||
for options_hook in options_hooks:
|
||||
options_hook(options)
|
||||
|
||||
if multiprocessing and options.jobs > 1:
|
||||
reporter = BaseQReport if options.quiet else QueueReport
|
||||
report = styleguide.init_report(reporter)
|
||||
report.input_file = styleguide.input_file
|
||||
styleguide.runner = report.task_queue.put
|
||||
if multiprocessing and options.jobs:
|
||||
if options.jobs.isdigit():
|
||||
n_jobs = int(options.jobs)
|
||||
else:
|
||||
try:
|
||||
n_jobs = multiprocessing.cpu_count()
|
||||
except NotImplementedError:
|
||||
n_jobs = 1
|
||||
if n_jobs > 1:
|
||||
options.jobs = n_jobs
|
||||
reporter = BaseQReport if options.quiet else QueueReport
|
||||
report = styleguide.init_report(reporter)
|
||||
report.input_file = styleguide.input_file
|
||||
styleguide.runner = report.task_queue.put
|
||||
|
||||
return styleguide
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class TestEngine(unittest.TestCase):
|
|||
m = mock.Mock()
|
||||
with mock.patch('flake8.engine.StyleGuide') as StyleGuide:
|
||||
with mock.patch('flake8.engine.get_parser') as get_parser:
|
||||
StyleGuide.return_value.options.jobs = 42
|
||||
StyleGuide.return_value.options.jobs = '42'
|
||||
get_parser.return_value = (m, [])
|
||||
engine.get_style_guide(foo='bar')
|
||||
get_parser.assert_called_once_with()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue