1# Copyright 2017-2020 Palantir Technologies, Inc. 2# Copyright 2021- Python Language Server Contributors. 3 4import pycodestyle 5from pylsp._utils import find_parents 6from .source import ConfigSource 7 8 9CONFIG_KEY = 'pycodestyle' 10USER_CONFIGS = [pycodestyle.USER_CONFIG] if pycodestyle.USER_CONFIG else [] 11PROJECT_CONFIGS = ['pycodestyle.cfg', 'setup.cfg', 'tox.ini'] 12 13OPTIONS = [ 14 ('exclude', 'plugins.pycodestyle.exclude', list), 15 ('filename', 'plugins.pycodestyle.filename', list), 16 ('hang-closing', 'plugins.pycodestyle.hangClosing', bool), 17 ('ignore', 'plugins.pycodestyle.ignore', list), 18 ('max-line-length', 'plugins.pycodestyle.maxLineLength', int), 19 ('select', 'plugins.pycodestyle.select', list), 20 ('aggressive', 'plugins.pycodestyle.aggressive', int), 21] 22 23 24class PyCodeStyleConfig(ConfigSource): 25 26 def user_config(self): 27 config = self.read_config_from_files(USER_CONFIGS) 28 return self.parse_config(config, CONFIG_KEY, OPTIONS) 29 30 def project_config(self, document_path): 31 files = find_parents(self.root_path, document_path, PROJECT_CONFIGS) 32 config = self.read_config_from_files(files) 33 return self.parse_config(config, CONFIG_KEY, OPTIONS) 34