Skip to content

Commit c7d93a0

Browse files
committed
run reformat
1 parent 2286f5b commit c7d93a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2067
-2344
lines changed

pylsp/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# Copyright 2021- Python Language Server Contributors.
33

44
import os
5+
56
import pluggy
7+
68
from . import _version
79
from ._version import __version__
810

@@ -22,8 +24,8 @@ def convert_version_info(version: str) -> (int, ..., str):
2224

2325
_version.VERSION_INFO = convert_version_info(__version__)
2426

25-
PYLSP = 'pylsp'
26-
IS_WIN = os.name == 'nt'
27+
PYLSP = "pylsp"
28+
IS_WIN = os.name == "nt"
2729

2830
hookspec = pluggy.HookspecMarker(PYLSP)
2931
hookimpl = pluggy.HookimplMarker(PYLSP)

pylsp/__main__.py

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,59 +12,39 @@
1212
except Exception: # pylint: disable=broad-except
1313
import json
1414

15-
from .python_lsp import (PythonLSPServer, start_io_lang_server,
16-
start_tcp_lang_server, start_ws_lang_server)
1715
from ._version import __version__
16+
from .python_lsp import PythonLSPServer, start_io_lang_server, start_tcp_lang_server, start_ws_lang_server
1817

19-
LOG_FORMAT = "%(asctime)s {0} - %(levelname)s - %(name)s - %(message)s".format(
20-
time.localtime().tm_zone)
18+
LOG_FORMAT = "%(asctime)s {0} - %(levelname)s - %(name)s - %(message)s".format(time.localtime().tm_zone)
2119

2220

2321
def add_arguments(parser):
2422
parser.description = "Python Language Server"
2523

24+
parser.add_argument("--tcp", action="store_true", help="Use TCP server instead of stdio")
25+
parser.add_argument("--ws", action="store_true", help="Use Web Sockets server instead of stdio")
26+
parser.add_argument("--host", default="127.0.0.1", help="Bind to this address")
27+
parser.add_argument("--port", type=int, default=2087, help="Bind to this port")
2628
parser.add_argument(
27-
"--tcp", action="store_true",
28-
help="Use TCP server instead of stdio"
29-
)
30-
parser.add_argument(
31-
"--ws", action="store_true",
32-
help="Use Web Sockets server instead of stdio"
33-
)
34-
parser.add_argument(
35-
"--host", default="127.0.0.1",
36-
help="Bind to this address"
37-
)
38-
parser.add_argument(
39-
"--port", type=int, default=2087,
40-
help="Bind to this port"
41-
)
42-
parser.add_argument(
43-
'--check-parent-process', action="store_true",
29+
"--check-parent-process",
30+
action="store_true",
4431
help="Check whether parent process is still alive using os.kill(ppid, 0) "
4532
"and auto shut down language server process when parent process is not alive."
46-
"Note that this may not work on a Windows machine."
33+
"Note that this may not work on a Windows machine.",
4734
)
4835

4936
log_group = parser.add_mutually_exclusive_group()
50-
log_group.add_argument(
51-
"--log-config",
52-
help="Path to a JSON file containing Python logging config."
53-
)
37+
log_group.add_argument("--log-config", help="Path to a JSON file containing Python logging config.")
5438
log_group.add_argument(
5539
"--log-file",
56-
help="Redirect logs to the given file instead of writing to stderr."
57-
"Has no effect if used with --log-config."
40+
help="Redirect logs to the given file instead of writing to stderr." "Has no effect if used with --log-config.",
5841
)
5942

6043
parser.add_argument(
61-
'-v', '--verbose', action='count', default=0,
62-
help="Increase verbosity of log output, overrides log config file"
44+
"-v", "--verbose", action="count", default=0, help="Increase verbosity of log output, overrides log config file"
6345
)
6446

65-
parser.add_argument(
66-
'-V', '--version', action='version', version='%(prog)s v' + __version__
67-
)
47+
parser.add_argument("-V", "--version", action="version", version="%(prog)s v" + __version__)
6848

6949

7050
def main():
@@ -74,15 +54,12 @@ def main():
7454
_configure_logger(args.verbose, args.log_config, args.log_file)
7555

7656
if args.tcp:
77-
start_tcp_lang_server(args.host, args.port, args.check_parent_process,
78-
PythonLSPServer)
57+
start_tcp_lang_server(args.host, args.port, args.check_parent_process, PythonLSPServer)
7958
elif args.ws:
80-
start_ws_lang_server(args.port, args.check_parent_process,
81-
PythonLSPServer)
59+
start_ws_lang_server(args.port, args.check_parent_process, PythonLSPServer)
8260
else:
8361
stdin, stdout = _binary_stdio()
84-
start_io_lang_server(stdin, stdout, args.check_parent_process,
85-
PythonLSPServer)
62+
start_io_lang_server(stdin, stdout, args.check_parent_process, PythonLSPServer)
8663

8764

8865
def _binary_stdio():
@@ -99,14 +76,13 @@ def _configure_logger(verbose=0, log_config=None, log_file=None):
9976
root_logger = logging.root
10077

10178
if log_config:
102-
with open(log_config, 'r', encoding='utf-8') as f:
79+
with open(log_config, "r", encoding="utf-8") as f:
10380
logging.config.dictConfig(json.load(f))
10481
else:
10582
formatter = logging.Formatter(LOG_FORMAT)
10683
if log_file:
10784
log_handler = logging.handlers.RotatingFileHandler(
108-
log_file, mode='a', maxBytes=50*1024*1024,
109-
backupCount=10, encoding=None, delay=0
85+
log_file, mode="a", maxBytes=50 * 1024 * 1024, backupCount=10, encoding=None, delay=0
11086
)
11187
else:
11288
log_handler = logging.StreamHandler()
@@ -123,5 +99,5 @@ def _configure_logger(verbose=0, log_config=None, log_file=None):
12399
root_logger.setLevel(level)
124100

125101

126-
if __name__ == '__main__':
102+
if __name__ == "__main__":
127103
main()

pylsp/_utils.py

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717

1818
# Eol chars accepted by the LSP protocol
1919
# the ordering affects performance
20-
EOL_CHARS = ['\r\n', '\r', '\n']
20+
EOL_CHARS = ["\r\n", "\r", "\n"]
2121
EOL_REGEX = re.compile(f'({"|".join(EOL_CHARS)})')
2222

2323
log = logging.getLogger(__name__)
2424

2525

2626
def debounce(interval_s, keyed_by=None):
2727
"""Debounce calls to this function until interval_s seconds have passed."""
28+
2829
def wrapper(func):
2930
timers = {}
3031
lock = threading.Lock()
@@ -48,7 +49,9 @@ def run():
4849
timer = threading.Timer(interval_s, run)
4950
timers[key] = timer
5051
timer.start()
52+
5153
return debounced
54+
5255
return wrapper
5356

5457

@@ -92,11 +95,11 @@ def path_to_dot_name(path):
9295
directory = os.path.dirname(path)
9396
module_name, _ = os.path.splitext(os.path.basename(path))
9497
full_name = [module_name]
95-
while os.path.exists(os.path.join(directory, '__init__.py')):
98+
while os.path.exists(os.path.join(directory, "__init__.py")):
9699
this_directory = os.path.basename(directory)
97100
directory = os.path.dirname(directory)
98101
full_name = [this_directory] + full_name
99-
return '.'.join(full_name)
102+
return ".".join(full_name)
100103

101104

102105
def match_uri_to_workspace(uri, workspaces):
@@ -128,6 +131,7 @@ def merge_dicts(dict_a, dict_b):
128131
129132
If override_nones is True, then
130133
"""
134+
131135
def _merge_dicts_(a, b):
132136
for key in set(a.keys()).union(b.keys()):
133137
if key in a and key in b:
@@ -143,15 +147,16 @@ def _merge_dicts_(a, b):
143147
yield (key, a[key])
144148
elif b[key] is not None:
145149
yield (key, b[key])
150+
146151
return dict(_merge_dicts_(dict_a, dict_b))
147152

148153

149154
def escape_plain_text(contents: str) -> str:
150155
"""
151156
Format plain text to display nicely in environments which do not respect whitespaces.
152157
"""
153-
contents = contents.replace('\t', '\u00A0' * 4)
154-
contents = contents.replace(' ', '\u00A0' * 2)
158+
contents = contents.replace("\t", "\u00A0" * 4)
159+
contents = contents.replace(" ", "\u00A0" * 2)
155160
return contents
156161

157162

@@ -160,17 +165,17 @@ def escape_markdown(contents: str) -> str:
160165
Format plain text to display nicely in Markdown environment.
161166
"""
162167
# escape markdown syntax
163-
contents = re.sub(r'([\\*_#[\]])', r'\\\1', contents)
168+
contents = re.sub(r"([\\*_#[\]])", r"\\\1", contents)
164169
# preserve white space characters
165170
contents = escape_plain_text(contents)
166171
return contents
167172

168173

169174
def wrap_signature(signature):
170-
return '```python\n' + signature + '\n```\n'
175+
return "```python\n" + signature + "\n```\n"
171176

172177

173-
SERVER_SUPPORTED_MARKUP_KINDS = {'markdown', 'plaintext'}
178+
SERVER_SUPPORTED_MARKUP_KINDS = {"markdown", "plaintext"}
174179

175180

176181
def choose_markup_kind(client_supported_markup_kinds: List[str]):
@@ -181,7 +186,7 @@ def choose_markup_kind(client_supported_markup_kinds: List[str]):
181186
for kind in client_supported_markup_kinds:
182187
if kind in SERVER_SUPPORTED_MARKUP_KINDS:
183188
return kind
184-
return 'markdown'
189+
return "markdown"
185190

186191

187192
def format_docstring(contents: str, markup_kind: str, signatures: Optional[List[str]] = None):
@@ -195,33 +200,24 @@ def format_docstring(contents: str, markup_kind: str, signatures: Optional[List[
195200
to the provided contents of the docstring if given.
196201
"""
197202
if not isinstance(contents, str):
198-
contents = ''
203+
contents = ""
199204

200-
if markup_kind == 'markdown':
205+
if markup_kind == "markdown":
201206
try:
202207
value = docstring_to_markdown.convert(contents)
203-
return {
204-
'kind': 'markdown',
205-
'value': value
206-
}
208+
return {"kind": "markdown", "value": value}
207209
except docstring_to_markdown.UnknownFormatError:
208210
# try to escape the Markdown syntax instead:
209211
value = escape_markdown(contents)
210212

211213
if signatures:
212-
value = wrap_signature('\n'.join(signatures)) + '\n\n' + value
214+
value = wrap_signature("\n".join(signatures)) + "\n\n" + value
213215

214-
return {
215-
'kind': 'markdown',
216-
'value': value
217-
}
216+
return {"kind": "markdown", "value": value}
218217
value = contents
219218
if signatures:
220-
value = '\n'.join(signatures) + '\n\n' + value
221-
return {
222-
'kind': 'plaintext',
223-
'value': escape_plain_text(value)
224-
}
219+
value = "\n".join(signatures) + "\n\n" + value
220+
return {"kind": "plaintext", "value": escape_plain_text(value)}
225221

226222

227223
def clip_column(column, lines, line_number):
@@ -230,7 +226,7 @@ def clip_column(column, lines, line_number):
230226
231227
https://microsoft.github.io/language-server-protocol/specification#position
232228
"""
233-
max_column = len(lines[line_number].rstrip('\r\n')) if len(lines) > line_number else 0
229+
max_column = len(lines[line_number].rstrip("\r\n")) if len(lines) > line_number else 0
234230
return min(column, max_column)
235231

236232

@@ -242,14 +238,14 @@ def position_to_jedi_linecolumn(document, position):
242238
"""
243239
code_position = {}
244240
if position:
245-
code_position = {'line': position['line'] + 1,
246-
'column': clip_column(position['character'],
247-
document.lines,
248-
position['line'])}
241+
code_position = {
242+
"line": position["line"] + 1,
243+
"column": clip_column(position["character"], document.lines, position["line"]),
244+
}
249245
return code_position
250246

251247

252-
if os.name == 'nt':
248+
if os.name == "nt":
253249
import ctypes
254250

255251
kernel32 = ctypes.windll.kernel32

pylsp/config/config.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
import pluggy
1111
from pluggy._hooks import HookImpl
1212

13-
from pylsp import _utils, hookspecs, uris, PYLSP
13+
from pylsp import PYLSP, _utils, hookspecs, uris
1414

1515
log = logging.getLogger(__name__)
1616

1717
# Sources of config, first source overrides next source
18-
DEFAULT_CONFIG_SOURCES = ['pycodestyle']
18+
DEFAULT_CONFIG_SOURCES = ["pycodestyle"]
1919

2020

2121
class PluginManager(pluggy.PluginManager):
22-
2322
def _hookexec(
2423
self,
2524
hook_name: str,
@@ -50,12 +49,14 @@ def __init__(self, root_uri, init_opts, process_id, capabilities):
5049
self._config_sources = {}
5150
try:
5251
from .flake8_conf import Flake8Config
53-
self._config_sources['flake8'] = Flake8Config(self._root_path)
52+
53+
self._config_sources["flake8"] = Flake8Config(self._root_path)
5454
except ImportError:
5555
pass
5656
try:
5757
from .pycodestyle_conf import PyCodeStyleConfig
58-
self._config_sources['pycodestyle'] = PyCodeStyleConfig(self._root_path)
58+
59+
self._config_sources["pycodestyle"] = PyCodeStyleConfig(self._root_path)
5960
except ImportError:
6061
pass
6162

@@ -123,7 +124,7 @@ def settings(self, document_path=None):
123124
settings.cache_clear() when the config is updated
124125
"""
125126
settings = {}
126-
sources = self._settings.get('configurationSources', DEFAULT_CONFIG_SOURCES)
127+
sources = self._settings.get("configurationSources", DEFAULT_CONFIG_SOURCES)
127128

128129
# Plugin configuration
129130
settings = _utils.merge_dicts(settings, self._plugin_settings)
@@ -158,7 +159,7 @@ def find_parents(self, path, names):
158159
return _utils.find_parents(root_path, path, names)
159160

160161
def plugin_settings(self, plugin, document_path=None):
161-
return self.settings(document_path=document_path).get('plugins', {}).get(plugin, {})
162+
return self.settings(document_path=document_path).get("plugins", {}).get(plugin, {})
162163

163164
def update(self, settings):
164165
"""Recursively merge the given settings into the current settings."""
@@ -170,7 +171,8 @@ def update(self, settings):
170171
def _update_disabled_plugins(self):
171172
# All plugins default to enabled
172173
self._disabled_plugins = [
173-
plugin for name, plugin in self.plugin_manager.list_name_plugin()
174-
if not self.settings().get('plugins', {}).get(name, {}).get('enabled', True)
174+
plugin
175+
for name, plugin in self.plugin_manager.list_name_plugin()
176+
if not self.settings().get("plugins", {}).get(name, {}).get("enabled", True)
175177
]
176178
log.info("Disabled plugins: %s", self._disabled_plugins)

0 commit comments

Comments
 (0)