mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-10 23:04:18 +00:00
Fix performance regression with per-file-ignores
With a large number of errors, filenames, and per-file-ignores the style guide selection would take a significant portion of execution time (python3 70% / python2 99.9%). Caching the styleguide lookup by filename eliminates this bottleneck.
This commit is contained in:
parent
ee7081c8ce
commit
c85b282b05
3 changed files with 8 additions and 9 deletions
|
|
@ -11,6 +11,7 @@ requires-dist =
|
||||||
enum34; python_version<"3.4"
|
enum34; python_version<"3.4"
|
||||||
typing; python_version<"3.5"
|
typing; python_version<"3.5"
|
||||||
configparser; python_version<"3.2"
|
configparser; python_version<"3.2"
|
||||||
|
functools32; python_version<"3.2"
|
||||||
entrypoints >= 0.3.0, < 0.4.0
|
entrypoints >= 0.3.0, < 0.4.0
|
||||||
pyflakes >= 2.1.0, < 2.2.0
|
pyflakes >= 2.1.0, < 2.2.0
|
||||||
pycodestyle >= 2.5.0, < 2.6.0
|
pycodestyle >= 2.5.0, < 2.6.0
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -28,7 +28,7 @@ requires = [
|
||||||
extras_require = {
|
extras_require = {
|
||||||
":python_version<'3.4'": ['enum34'],
|
":python_version<'3.4'": ['enum34'],
|
||||||
":python_version<'3.5'": ['typing'],
|
":python_version<'3.5'": ['typing'],
|
||||||
":python_version<'3.2'": ['configparser'],
|
":python_version<'3.2'": ['configparser', 'functools32'],
|
||||||
}
|
}
|
||||||
|
|
||||||
if int(setuptools.__version__.split('.')[0]) < 18:
|
if int(setuptools.__version__.split('.')[0]) < 18:
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ import collections
|
||||||
import contextlib
|
import contextlib
|
||||||
import copy
|
import copy
|
||||||
import enum
|
import enum
|
||||||
import functools
|
|
||||||
import itertools
|
import itertools
|
||||||
import linecache
|
import linecache
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
from typing import Optional, Union # noqa: F401 (until flake8 3.7)
|
from typing import Optional, Union # noqa: F401 (until flake8 3.7)
|
||||||
|
|
||||||
from flake8 import defaults
|
from flake8 import defaults
|
||||||
|
|
@ -18,13 +18,10 @@ __all__ = ("StyleGuide",)
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
try:
|
if sys.version_info < (3, 2):
|
||||||
lru_cache = functools.lru_cache
|
from functools32 import lru_cache
|
||||||
except AttributeError:
|
else:
|
||||||
|
from functools import lru_cache
|
||||||
def lru_cache(maxsize=128, typed=False):
|
|
||||||
"""Stub for missing lru_cache."""
|
|
||||||
return lambda func: func
|
|
||||||
|
|
||||||
|
|
||||||
# TODO(sigmavirus24): Determine if we need to use enum/enum34
|
# TODO(sigmavirus24): Determine if we need to use enum/enum34
|
||||||
|
|
@ -366,6 +363,7 @@ class StyleGuideManager(object):
|
||||||
filename=filename, extend_ignore_with=violations
|
filename=filename, extend_ignore_with=violations
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@lru_cache(maxsize=None)
|
||||||
def style_guide_for(self, filename):
|
def style_guide_for(self, filename):
|
||||||
"""Find the StyleGuide for the filename in particular."""
|
"""Find the StyleGuide for the filename in particular."""
|
||||||
guides = sorted(
|
guides = sorted(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue