File: pycodestyle_conf.py

package info (click to toggle)
python-lsp-server 1.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 796 kB
  • sloc: python: 7,791; sh: 12; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 1,268 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Copyright 2017-2020 Palantir Technologies, Inc.
# Copyright 2021- Python Language Server Contributors.

import pycodestyle

from pylsp._utils import find_parents

from .source import ConfigSource

CONFIG_KEY = "pycodestyle"
USER_CONFIGS = [pycodestyle.USER_CONFIG] if pycodestyle.USER_CONFIG else []
PROJECT_CONFIGS = ["pycodestyle.cfg", "setup.cfg", "tox.ini"]

OPTIONS = [
    ("exclude", "plugins.pycodestyle.exclude", list),
    ("filename", "plugins.pycodestyle.filename", list),
    ("hang-closing", "plugins.pycodestyle.hangClosing", bool),
    ("ignore", "plugins.pycodestyle.ignore", list),
    ("max-line-length", "plugins.pycodestyle.maxLineLength", int),
    ("indent-size", "plugins.pycodestyle.indentSize", int),
    ("select", "plugins.pycodestyle.select", list),
    ("aggressive", "plugins.pycodestyle.aggressive", int),
]


class PyCodeStyleConfig(ConfigSource):
    def user_config(self):
        config = self.read_config_from_files(USER_CONFIGS)
        return self.parse_config(config, CONFIG_KEY, OPTIONS)

    def project_config(self, document_path):
        files = find_parents(self.root_path, document_path, PROJECT_CONFIGS)
        config = self.read_config_from_files(files)
        return self.parse_config(config, CONFIG_KEY, OPTIONS)