Skip to content

Commit

Permalink
pylint: add the pythonpath environment from pythonpath-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
znapy committed Oct 25, 2024
1 parent ce836b5 commit f995ad7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 11 additions & 2 deletions spyder/plugins/pylint/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@ def _start(self):
lambda ec, es=QProcess.ExitStatus: self._finished(ec, es))

command_args = self.get_command(self.get_filename())
process.setProcessEnvironment(self.get_environment())
pythonpath_manager_values = self.get_conf(
'spyder_pythonpath', default=[], section='pythonpath_manager')
process.setProcessEnvironment(
self.get_environment(pythonpath_manager_values))
process.start(sys.executable, command_args)
running = process.waitForStarted()
if not running:
Expand Down Expand Up @@ -933,11 +936,17 @@ def get_command(self, filename):
return command_args

@staticmethod
def get_environment() -> QProcessEnvironment:
def get_environment(pythonpath_manager_values: list
) -> QProcessEnvironment:
"""Get evironment variables for pylint command."""
process_environment = QProcessEnvironment()
process_environment.insert("PYTHONIOENCODING", "utf8")

if pythonpath_manager_values:
pypath = os.pathsep.join(pythonpath_manager_values)
# See PR spyder-ide/spyder#21891
process_environment.insert("PYTHONPATH", pypath)

if os.name == 'nt':
# Needed due to changes in Pylint 2.14.0
# See spyder-ide/spyder#18175
Expand Down
7 changes: 4 additions & 3 deletions spyder/plugins/pylint/tests/test_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,11 @@ def test_get_environment(mocker):
return_value='')

etalon = {
"nt": ["APPDATA", "PYTHONIOENCODING", "USERPROFILE"],
"posix": ["PYTHONIOENCODING"]}
"nt": ["APPDATA", "PYTHONIOENCODING", "PYTHONPATH", "USERPROFILE"],
"posix": ["PYTHONIOENCODING", "PYTHONPATH"]}

process_environment = Pylint.WIDGET_CLASS.get_environment()
process_environment = Pylint.WIDGET_CLASS.get_environment(
pythonpath_manager_values=["project_dir"])

assert process_environment.keys() == etalon[os.name]

Expand Down

0 comments on commit f995ad7

Please sign in to comment.