Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Carlos Cordoba <ccordoba12@gmail.com>
  • Loading branch information
znapy and ccordoba12 committed Oct 25, 2024
1 parent f995ad7 commit a460e70
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
15 changes: 10 additions & 5 deletions spyder/plugins/pylint/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,11 @@ def _start(self):

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

@staticmethod
def get_environment(pythonpath_manager_values: list
) -> QProcessEnvironment:
def get_environment(
pythonpath_manager_values: list
) -> QProcessEnvironment:
"""Get evironment variables for pylint command."""
process_environment = QProcessEnvironment()
process_environment.insert("PYTHONIOENCODING", "utf8")
Expand All @@ -956,7 +959,9 @@ def get_environment(pythonpath_manager_values: list
# Needed for Windows installations using standalone Python and pip.
# See spyder-ide/spyder#19385
if not is_conda_env(sys.prefix):
process_environment.insert("APPDATA", os.environ.get("APPDATA"))
process_environment.insert(
"APPDATA", os.environ.get("APPDATA")
)

return process_environment

Expand Down
30 changes: 19 additions & 11 deletions spyder/plugins/pylint/tests/test_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,21 +339,29 @@ def test_custom_interpreter(pylint_plugin, tmp_path, qtbot,
def test_get_environment(mocker):
"""Test that the environment variables depend on the OS."""
if os.name == 'nt':
mocker.patch("spyder.plugins.pylint.main_widget.is_conda_based_app",
return_value=False)
mocker.patch("spyder.plugins.pylint.main_widget.is_anaconda",
return_value=False)
mocker.patch("spyder.plugins.pylint.main_widget.get_home_dir",
return_value='')

etalon = {
mocker.patch(
"spyder.plugins.pylint.main_widget.is_conda_based_app",
return_value=False
)
mocker.patch(
"spyder.plugins.pylint.main_widget.is_anaconda",
return_value=False
)
mocker.patch(
"spyder.plugins.pylint.main_widget.get_home_dir",
return_value=''
)

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

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

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


if __name__ == "__main__":
Expand Down

0 comments on commit a460e70

Please sign in to comment.