mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-10 23:04:18 +00:00
Use git config before os.environ
Get parameter's value using git config before trying os.environ.
This commit is contained in:
parent
4d9a88298b
commit
d03b526913
1 changed files with 40 additions and 7 deletions
|
|
@ -163,16 +163,49 @@ def find_vcs():
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
def get_git_config(option, type='', convert_type=True):
|
||||||
|
# type can be --bool, --int or an empty string
|
||||||
|
_, git_cfg_value, _ = run('git config --get %s %s' % (type, option),
|
||||||
|
raw_output=True)
|
||||||
|
git_cfg_value = git_cfg_value.strip()
|
||||||
|
if not convert_type:
|
||||||
|
return git_cfg_value
|
||||||
|
if type == '--bool':
|
||||||
|
git_cfg_value = git_cfg_value == 'true'
|
||||||
|
elif git_cfg_value and type == '--int':
|
||||||
|
git_cfg_value = int(git_cfg_value)
|
||||||
|
return git_cfg_value
|
||||||
|
|
||||||
|
|
||||||
|
_params = dict([
|
||||||
|
('FLAKE8_COMPLEXITY', '--int'),
|
||||||
|
('FLAKE8_STRICT', '--bool'),
|
||||||
|
('FLAKE8_IGNORE', ''),
|
||||||
|
('FLAKE8_LAZY', '--bool'),
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def get_git_param(option, default=''):
|
||||||
|
type = _params[option]
|
||||||
|
param_value = get_git_config(option.lower().replace('_', '.'),
|
||||||
|
type=type, convert_type=False)
|
||||||
|
if param_value == '':
|
||||||
|
param_value = os.getenv(option, default)
|
||||||
|
if (type == '--bool') and not isinstance(param_value, bool):
|
||||||
|
param_value = param_value.lower() == 'true'
|
||||||
|
elif param_value and type == '--int':
|
||||||
|
param_value = int(param_value)
|
||||||
|
return param_value
|
||||||
|
|
||||||
|
|
||||||
git_hook_file = """#!/usr/bin/env python
|
git_hook_file = """#!/usr/bin/env python
|
||||||
import sys
|
import sys
|
||||||
import os
|
from flake8.hooks import git_hook, get_git_param
|
||||||
from flake8.hooks import git_hook
|
|
||||||
|
|
||||||
COMPLEXITY = os.getenv('FLAKE8_COMPLEXITY', 10)
|
|
||||||
STRICT = os.getenv('FLAKE8_STRICT', False)
|
|
||||||
IGNORE = os.getenv('FLAKE8_IGNORE')
|
|
||||||
LAZY = os.getenv('FLAKE8_LAZY', False)
|
|
||||||
|
|
||||||
|
COMPLEXITY = get_git_param('FLAKE8_COMPLEXITY', 10)
|
||||||
|
STRICT = get_git_param('FLAKE8_STRICT', False)
|
||||||
|
IGNORE = get_git_param('FLAKE8_IGNORE')
|
||||||
|
LAZY = get_git_param('FLAKE8_LAZY', False)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(git_hook(
|
sys.exit(git_hook(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue