mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-09 14:24:17 +00:00
Add a helper method for retrying checks in serial
This allows us to reuse the same code simply for check_files and input_file. This should cover all uses of the StyleGuide methods. Related to bug #74
This commit is contained in:
parent
1c6c1f5116
commit
f1aa58889d
1 changed files with 16 additions and 6 deletions
|
|
@ -104,7 +104,7 @@ class StyleGuide(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Reasoning for error numbers is in-line below
|
# Reasoning for error numbers is in-line below
|
||||||
turn_off_multiprocessing_errors = set([
|
serial_retry_errors = set([
|
||||||
# ENOSPC: Added by sigmavirus24
|
# ENOSPC: Added by sigmavirus24
|
||||||
# > On some operating systems (OSX), multiprocessing may cause an
|
# > On some operating systems (OSX), multiprocessing may cause an
|
||||||
# > ENOSPC error while trying to trying to create a Semaphore.
|
# > ENOSPC error while trying to trying to create a Semaphore.
|
||||||
|
|
@ -130,15 +130,24 @@ class StyleGuide(object):
|
||||||
def paths(self):
|
def paths(self):
|
||||||
return self._styleguide.paths
|
return self._styleguide.paths
|
||||||
|
|
||||||
def check_files(self, paths=None):
|
def _retry_serial(self, func, *args, **kwargs):
|
||||||
|
"""This will retry the passed function in serial if necessary.
|
||||||
|
|
||||||
|
In the event that we encounter an OSError with an errno in
|
||||||
|
:attr:`serial_retry_errors`, this function will retry this function
|
||||||
|
using pep8's default Report class which operates in serial.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
return self._styleguide.check_files(paths)
|
return func(*args, **kwargs)
|
||||||
except IOError as ioerr:
|
except IOError as ioerr:
|
||||||
if ioerr.errno in self.turn_off_multiprocessing_errors:
|
if ioerr.errno in self.serial_retry_errors:
|
||||||
self.init_report(pep8.StandardReport)
|
self.init_report(pep8.StandardReport)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
return self._styleguide.check_files(paths)
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
|
def check_files(self, paths=None):
|
||||||
|
return self._retry_serial(self._styleguide.check_files, paths=paths)
|
||||||
|
|
||||||
def excluded(self, filename, parent=None):
|
def excluded(self, filename, parent=None):
|
||||||
return self._styleguide.excluded(filename, parent=parent)
|
return self._styleguide.excluded(filename, parent=parent)
|
||||||
|
|
@ -147,7 +156,8 @@ class StyleGuide(object):
|
||||||
return self._styleguide.init_report(reporter)
|
return self._styleguide.init_report(reporter)
|
||||||
|
|
||||||
def input_file(self, filename, lines=None, expected=None, line_offset=0):
|
def input_file(self, filename, lines=None, expected=None, line_offset=0):
|
||||||
return self._styleguide.input_file(
|
return self._retry_serial(
|
||||||
|
self._styleguide.input_file,
|
||||||
filename=filename,
|
filename=filename,
|
||||||
lines=lines,
|
lines=lines,
|
||||||
expected=expected,
|
expected=expected,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue