mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-09 14:24:17 +00:00
Merge branch 'bug/122' into 'master'
Correct usage config_file StyleGuide parameter Previously, we passed the location for our user config file to the StyleGuide. This was intended to be a way to tell pep8's StyleGuide to use that as a user config file, but instead that became the default for the --config command-line option. This caused that to have higher priority than the project configuration file. Closes #122 See merge request !53
This commit is contained in:
commit
40f1a1e337
2 changed files with 11 additions and 14 deletions
|
|
@ -14,7 +14,6 @@ except ImportError: # Python 2
|
||||||
|
|
||||||
from flake8 import compat
|
from flake8 import compat
|
||||||
from flake8.engine import get_parser, get_style_guide
|
from flake8.engine import get_parser, get_style_guide
|
||||||
from flake8.main import DEFAULT_CONFIG
|
|
||||||
|
|
||||||
|
|
||||||
def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
|
def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
|
||||||
|
|
@ -51,8 +50,7 @@ def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
|
||||||
|
|
||||||
tmpdir = tempfile.mkdtemp()
|
tmpdir = tempfile.mkdtemp()
|
||||||
|
|
||||||
flake8_style = get_style_guide(config_file=DEFAULT_CONFIG, paths=['.'],
|
flake8_style = get_style_guide(paths=['.'], **options)
|
||||||
**options)
|
|
||||||
filepatterns = flake8_style.options.filename
|
filepatterns = flake8_style.options.filename
|
||||||
|
|
||||||
# Copy staged versions to temporary directory
|
# Copy staged versions to temporary directory
|
||||||
|
|
@ -102,7 +100,7 @@ def hg_hook(ui, repo, **kwargs):
|
||||||
complexity = ui.config('flake8', 'complexity', default=-1)
|
complexity = ui.config('flake8', 'complexity', default=-1)
|
||||||
strict = ui.configbool('flake8', 'strict', default=True)
|
strict = ui.configbool('flake8', 'strict', default=True)
|
||||||
ignore = ui.config('flake8', 'ignore', default=None)
|
ignore = ui.config('flake8', 'ignore', default=None)
|
||||||
config = ui.config('flake8', 'config', default=DEFAULT_CONFIG)
|
config = ui.config('flake8', 'config', default=None)
|
||||||
|
|
||||||
paths = _get_files(repo, **kwargs)
|
paths = _get_files(repo, **kwargs)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,26 +3,29 @@ import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import pep8
|
||||||
import setuptools
|
import setuptools
|
||||||
|
|
||||||
from flake8.engine import get_parser, get_style_guide
|
from flake8.engine import get_parser, get_style_guide
|
||||||
from flake8.util import option_normalizer
|
from flake8.util import option_normalizer
|
||||||
|
|
||||||
if sys.platform.startswith('win'):
|
if sys.platform.startswith('win'):
|
||||||
DEFAULT_CONFIG = os.path.expanduser(r'~\.flake8')
|
USER_CONFIG = os.path.expanduser(r'~\.flake8')
|
||||||
else:
|
else:
|
||||||
DEFAULT_CONFIG = os.path.join(
|
USER_CONFIG = os.path.join(
|
||||||
os.getenv('XDG_CONFIG_HOME') or os.path.expanduser('~/.config'),
|
os.getenv('XDG_CONFIG_HOME') or os.path.expanduser('~/.config'),
|
||||||
'flake8'
|
'flake8'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
pep8.USER_CONFIG = USER_CONFIG
|
||||||
|
|
||||||
EXTRA_IGNORE = []
|
EXTRA_IGNORE = []
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Parse options and run checks on Python source."""
|
"""Parse options and run checks on Python source."""
|
||||||
# Prepare
|
# Prepare
|
||||||
flake8_style = get_style_guide(parse_argv=True, config_file=DEFAULT_CONFIG)
|
flake8_style = get_style_guide(parse_argv=True)
|
||||||
options = flake8_style.options
|
options = flake8_style.options
|
||||||
|
|
||||||
if options.install_hook:
|
if options.install_hook:
|
||||||
|
|
@ -61,8 +64,7 @@ def check_file(path, ignore=(), complexity=-1):
|
||||||
:param int complexity: (optional), enables the mccabe check for values > 0
|
:param int complexity: (optional), enables the mccabe check for values > 0
|
||||||
"""
|
"""
|
||||||
ignore = set(ignore).union(EXTRA_IGNORE)
|
ignore = set(ignore).union(EXTRA_IGNORE)
|
||||||
flake8_style = get_style_guide(
|
flake8_style = get_style_guide(ignore=ignore, max_complexity=complexity)
|
||||||
config_file=DEFAULT_CONFIG, ignore=ignore, max_complexity=complexity)
|
|
||||||
return flake8_style.input_file(path)
|
return flake8_style.input_file(path)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -74,8 +76,7 @@ def check_code(code, ignore=(), complexity=-1):
|
||||||
:param int complexity: (optional), enables the mccabe check for values > 0
|
:param int complexity: (optional), enables the mccabe check for values > 0
|
||||||
"""
|
"""
|
||||||
ignore = set(ignore).union(EXTRA_IGNORE)
|
ignore = set(ignore).union(EXTRA_IGNORE)
|
||||||
flake8_style = get_style_guide(
|
flake8_style = get_style_guide(ignore=ignore, max_complexity=complexity)
|
||||||
config_file=DEFAULT_CONFIG, ignore=ignore, max_complexity=complexity)
|
|
||||||
return flake8_style.input_file(None, lines=code.splitlines(True))
|
return flake8_style.input_file(None, lines=code.splitlines(True))
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -131,9 +132,7 @@ class Flake8Command(setuptools.Command):
|
||||||
def run(self):
|
def run(self):
|
||||||
# Prepare
|
# Prepare
|
||||||
paths = list(self.distribution_files())
|
paths = list(self.distribution_files())
|
||||||
flake8_style = get_style_guide(config_file=DEFAULT_CONFIG,
|
flake8_style = get_style_guide(paths=paths, **self.options_dict)
|
||||||
paths=paths,
|
|
||||||
**self.options_dict)
|
|
||||||
|
|
||||||
# Run the checkers
|
# Run the checkers
|
||||||
report = flake8_style.check_files()
|
report = flake8_style.check_files()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue