8000 Fix pydocstyle argv (#247) · mrclary/python-lsp-server@344b787 · GitHub
[go: up one dir, main page]

Skip to content

Commit 344b787

Browse files
authored
Fix pydocstyle argv (python-lsp#247)
1 parent 4216689 commit 344b787

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

pyls/plugins/pydocstyle_lint.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Copyright 2017 Palantir Technologies, Inc.
2+
import contextlib
23
import logging
4+
import sys
5+
36
import pydocstyle
47
from pyls import hookimpl, lsp
58

@@ -19,8 +22,10 @@ def pyls_settings():
1922
@hookimpl
2023
def pyls_lint(document):
2124
conf = pydocstyle.config.ConfigurationParser()
22-
conf.parse()
23-
conf._arguments = [document.path]
25+
26+
with _patch_sys_argv([document.path]):
27+
# TODO(gatesn): We can add more pydocstyle args here from our pyls config
28+
conf.parse()
2429

2530
# Will only yield a single filename, the document path
2631
diags = []
@@ -65,3 +70,16 @@ def _parse_diagnostic(document, error):
6570
}
6671
}
6772
}
73+
74+
75+
@contextlib.contextmanager
76+
def _patch_sys_argv(arguments):
77+
old_args = sys.argv
78+
79+
# Preserve argv[0] since it's the executable
80+
sys.argv = old_args[0:1] + arguments
81+
82+
try:
83+
yield
84+
finally:
85+
sys.argv = old_args

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
'json-rpc',
3939
'mccabe',
4040 'pycodestyle',
41-
'pydocstyle',
41+
'pydocstyle>=2.0.0',
4242
'pyflakes',
4343
'rope>=0.10.5',
4444
'yapf',

0 commit comments

Comments
 (0)
0